import { test, expect } from "../fixtures/inventory-cost-tracking"; import { InventoryListPage } from "../pages/inventory-list"; import { ItemValuationDetailPage } from "../pages/item-valuation-detail"; import { ItemValuationListPage } from "../pages/item-valuation-list"; // inventory-cost-tracking is API-driven and read-only in the UI: the // `costData` fixture assigns the seeded valuation policy to a fresh item // (setItemValuationPolicy), publishes two standard cost generations // (publishStandardCost), and settles a PO-backed receipt in between. The // signed-in user (`page`, authenticated by the shared fixture) then only // *views* the resulting valuation data — the item-valuation screens and the // stock-level cost drawer. test.describe("inventory-cost-tracking", () => { // Story: purchaser--assign-valuation-policy test("purchaser views the item's valuation policy assignment and drills into its detail", async ({ page, costData, }) => { const listPage = new ItemValuationListPage(page); await listPage.goto(); await expect(listPage.heading).toBeVisible(); // The assignment created by setItemValuationPolicy is listed with its // company and policy. await expect(listPage.getColumnHeader("Company")).toBeVisible(); await expect(listPage.getColumnHeader("Inventory Valuation Policy")).toBeVisible(); const valuationRow = listPage.getRow(costData.itemName); await expect(valuationRow).toBeVisible(); await expect(valuationRow.getByText(costData.valuationPolicyName)).toBeVisible(); await listPage.getViewLink(costData.itemName).click(); await page.waitForURL(/\/inventory\/item-valuation\/[^/]+$/); const detailPage = new ItemValuationDetailPage(page); await expect(detailPage.heading).toBeVisible(); await expect(detailPage.itemField).toBeVisible(); await expect(detailPage.companyField).toBeVisible(); await expect(detailPage.valuationPolicyField).toBeVisible(); await expect(page.getByText(costData.valuationPolicyName).first()).toBeVisible(); }); // Story: purchaser--publish-standard-cost test("purchaser sees the published standard as the effective one in the stock-level cost drawer", async ({ page, costData, }) => { const listPage = new InventoryListPage(page); await listPage.goto(); await expect(listPage.heading).toBeVisible(); // Narrow to the fixture's item, then open its cost drawer. await listPage.search(costData.itemSku); await expect(listPage.getRow(costData.itemName).first()).toBeVisible(); await listPage.getShowCostButton(costData.itemName).first().click(); // The drawer shows the policy assignment and the standard cost table with // the most recently published generation (the effective standard) on top. await expect(page.getByText("Valuation Policy").first()).toBeVisible(); await expect(page.getByText(costData.valuationPolicyName).first()).toBeVisible(); await expect(page.getByText(/standard costs/i).first()).toBeVisible(); const drawerRows = page.getByRole("row").filter({ hasText: String(costData.secondStandardCost), }); await expect(drawerRows.first()).toBeVisible(); }); // Story: purchaser--view-standard-costs test("purchaser reviews the item's standard cost generation history", async ({ page, costData, }) => { // The fixture published two generations; both survive (append-only). expect(costData.standardCostGenerationCount).toBeGreaterThanOrEqual(2); const listPage = new InventoryListPage(page); await listPage.goto(); await listPage.search(costData.itemSku); await expect(listPage.getRow(costData.itemName).first()).toBeVisible(); await listPage.getShowCostButton(costData.itemName).first().click(); // Both generations are listed: the superseded first standard and the // effective second one. await expect( page .getByRole("row") .filter({ hasText: String(costData.secondStandardCost) }) .first(), ).toBeVisible(); await expect( page .getByRole("row") .filter({ hasText: String(costData.firstStandardCost) }) .first(), ).toBeVisible(); }); });