import { test, expect, uniqueSuffix, findOrFail } from './fixtures'; // 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. test.describe('Admin taxonomy', () => { test('creates a category and a nested child that stays visible', async ({ page, admin, adminTaxonomy }) => { const RUN = `a${uniqueSuffix()}`; await admin.open('Categories'); await adminTaxonomy.addCategory(`Furniture ${RUN}`); await expect(page.getByText(`Furniture ${RUN}`)).toBeVisible(); await adminTaxonomy.addChildCategory(`Furniture ${RUN}`, `Tables ${RUN}`); // 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, admin, adminTaxonomy }) => { const RUN = `a${uniqueSuffix()}`; await admin.open('Tags'); await adminTaxonomy.addTag(`vintage-${RUN}`); // Clicking OK only dispatches the request; wait for the confirmation so the // lookup below can't race the create. await expect(adminTaxonomy.tagAddedNotice).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 = findOrFail( tags, (tag: { name: string }) => tag.name === `vintage-${RUN}`, `the tag vintage-${RUN}` ); expect(created.color).toBeTruthy(); }); test('offers category and tag fields on the item form', async ({ admin, adminInventory }) => { await admin.goto(); await adminInventory.openItemForm(); await expect(adminInventory.formDialog.getByText('Category', { exact: true })).toBeVisible(); await expect(adminInventory.formDialog.getByText('Pick existing tags')).toBeVisible(); }); });