import { test, expect } from '@playwright/test'; // The e2e database is shared and never reset, so every fixture name carries a // unique suffix and assertions are scoped to the nodes this run created. The // suffix is generated per test rather than per module: a worker can run this // file more than once, and a module-level constant would collide with itself. const suffix = () => `a${Date.now().toString(36)}${Math.random().toString(36).slice(2, 7)}`; test.describe('Admin taxonomy', () => { test('creates a category and a nested child that stays visible', async ({ page }) => { const RUN = suffix(); await page.goto('/admin'); await page.getByRole('tab', { name: 'Categories' }).click(); await page.getByRole('button', { name: 'Add Category' }).click(); await page.getByLabel('Name').fill(`Furniture ${RUN}`); await page.getByRole('button', { name: 'OK' }).click(); await expect(page.getByText(`Furniture ${RUN}`)).toBeVisible(); await page .getByRole('treeitem') .filter({ hasText: `Furniture ${RUN}` }) .getByRole('button', { name: 'Add child' }) .click(); await page.getByLabel('Name').fill(`Tables ${RUN}`); await page.getByRole('button', { name: 'OK' }).click(); // The tree is mounted before this branch exists, so the child is only // visible if expansion follows newly created nodes rather than the state // captured at first render. await expect(page.getByText(`Tables ${RUN}`)).toBeVisible(); }); test('creates a tag with an automatically assigned colour', async ({ page }) => { const RUN = suffix(); await page.goto('/admin'); await page.getByRole('tab', { name: 'Tags' }).click(); await page.getByRole('button', { name: 'Add Tag' }).click(); await page.getByLabel('Name').fill(`vintage-${RUN}`); await page.getByRole('button', { name: 'OK' }).click(); // Clicking OK only dispatches the request; wait for the confirmation so the // lookup below can't race the create. await expect(page.getByText('Tag added')).toBeVisible(); // The table paginates and the shared database holds many tags, so the new // row is confirmed through the API rather than hunted for across pages. const tags = await (await page.request.get('/api/admin/tags')).json(); const created = tags.find((tag: { name: string }) => tag.name === `vintage-${RUN}`); expect(created).toBeTruthy(); expect(created.color).toBeTruthy(); }); test('offers category and tag fields on the item form', async ({ page }) => { await page.goto('/admin'); await page.getByRole('button', { name: 'Add Item' }).click(); const modal = page.getByRole('dialog'); await expect(modal.getByText('Category', { exact: true })).toBeVisible(); await expect(modal.getByText('Pick existing tags')).toBeVisible(); }); });