import { test, expect } from "../fixtures/item-management"; import { useActor } from "../fixtures/user"; import { ItemCreateFormPage } from "../pages/item-create-form"; import { ItemDetailPage } from "../pages/item-detail"; import { ItemListPage } from "../pages/item-list"; useActor(test, "admin"); // The item-management `## Flow Diagram` main path as one journey: // create-item -> view-item-list -> view-item-detail. test("admin creates an item, finds it active in the list, and reviews its detail", async ({ page, }) => { const suffix = `X-${Date.now()}`; const sku = `ITEM-${suffix}`; const name = `Item ${suffix}`; // Create Item — the resolver creates in DRAFT and immediately activates it, // so a successful submit lands the row directly in ACTIVE. The Unit selector // is pre-filled with Each (each) and disabled. const createForm = new ItemCreateFormPage(page); await createForm.goto(); await expect(createForm.skuInput).toBeVisible(); await expect(createForm.unitSelect).toBeDisabled(); await createForm.fill({ sku, name }); await createForm.submit(); // View Item List — the Admin finds the new catalog row by SKU and name. const listPage = new ItemListPage(page); await expect(listPage.heading).toBeVisible(); const row = listPage.getRow(sku); await expect(row).toBeVisible(); await expect(row).toContainText(name); await expect(row).toContainText(/active/i); // View Item Detail — clicking the row navigates to the item detail page. await listPage.getRow(sku).click(); await page.waitForURL(/\/master-data\/item\/[^/]+$/); const detailPage = new ItemDetailPage(page); await expect(detailPage.heading).toBeVisible(); await expect(detailPage.skuValue).toContainText(sku); await expect(detailPage.nameValue).toContainText(name); await expect(detailPage.statusBadge).toContainText(/active/i); // The right-rail Actions panel exposes Back to Items and Edit Item. await expect(detailPage.backButton).toBeVisible(); await expect(detailPage.editButton).toBeVisible(); // Back to Items returns to the list, where the item is still visible. await detailPage.backButton.click(); await page.waitForURL(/\/master-data\/item$/); await expect(listPage.heading).toBeVisible(); await expect(listPage.getRow(sku)).toBeVisible(); }); // Duplicate-SKU rejection: the second create with the same SKU is refused, so // item identity stays stable (ITEM_MANAGEMENT_DUPLICATE_SKU). test("admin cannot create a second item with a duplicate SKU", async ({ page }) => { const suffix = `DUP-${Date.now()}`; const sku = `ITEM-${suffix}`; const createForm = new ItemCreateFormPage(page); // First create succeeds and reaches the list. await createForm.goto(); await createForm.fill({ sku, name: `Item ${suffix}` }); await createForm.submit(); const listPage = new ItemListPage(page); await expect(listPage.heading).toBeVisible(); await expect(listPage.getRow(sku)).toBeVisible(); // Second create with the same SKU is rejected: the form does not navigate to // the list and surfaces an error instead. await createForm.goto(); await createForm.fill({ sku, name: `Item ${suffix} Again` }); await createForm.submit(); await expect(page.getByText(/already exists|duplicate/i)).toBeVisible(); await expect(page).toHaveURL(/\/master-data\/item\/create$/); });