import { describe, it, expect } from "vitest"; import { CATALOG_TABLES, catalogTableSpec } from "./catalogTables"; // Column registry lock (spec "admin-portal-catalog-ui", task 4.1): the /catalog-setup grid // renders EXACTLY the columns the picked list's registry declares. Unlike REFERENCE_TABLES // (always keyed by "code"), the three catalog lists are NOT uniform: brand keys off code, // category keys off its own name, priceType keys off its own label. Status is never an // editable dialog field (badge: true, editable: false) — it changes only via the inline toggle. // Collection was removed (openspec/changes/bundle-by-sku-drop-collection) — Category is // sufficient; it had no product relationship and 0 rows. function fieldNames(key: string): string[] { const spec = catalogTableSpec(key); if (!spec) throw new Error(`no registry entry for ${key}`); return spec.columns.map((c) => c.field); } describe("CATALOG_TABLES column registry", () => { it("covers exactly the four allow-listed lists", () => { expect(CATALOG_TABLES.map((t) => t.key)).toEqual(["brand", "category", "priceType", "supplier"]); for (const t of CATALOG_TABLES) { expect(t.label.length).toBeGreaterThan(0); } }); it("brand: code (key) + name + status, keyed by code", () => { const spec = catalogTableSpec("brand")!; expect(spec.keyField).toBe("code"); expect(fieldNames("brand")).toEqual(["code", "name", "status"]); expect(spec.columns.find((c) => c.field === "code")!.required).toBe(true); expect(spec.columns.find((c) => c.field === "code")!.editable).toBe(true); expect(spec.columns.find((c) => c.field === "name")!.required).toBe(true); expect(spec.columns.find((c) => c.field === "name")!.editable).toBe(true); }); it("category: the wire key IS `code` (mobile-api's CatalogRow carries every list's key in `code`, not `name`)", () => { const spec = catalogTableSpec("category")!; expect(spec.keyField).toBe("code"); expect(fieldNames("category")).toEqual(["code", "status"]); expect(spec.columns.find((c) => c.field === "code")!.label).toBe("CatName"); expect(spec.columns.find((c) => c.field === "code")!.required).toBe(true); expect(spec.columns.find((c) => c.field === "code")!.editable).toBe(true); }); it("priceType: the wire key IS `code` too (mobile-api's CatalogRow has no `priceType` field)", () => { const spec = catalogTableSpec("priceType")!; expect(spec.keyField).toBe("code"); expect(fieldNames("priceType")).toEqual(["code", "status"]); expect(spec.columns.find((c) => c.field === "code")!.label).toBe("PricingPriceType"); expect(spec.columns.find((c) => c.field === "code")!.required).toBe(true); expect(spec.columns.find((c) => c.field === "code")!.editable).toBe(true); }); it("status is never an editable dialog field on any list — badge, read-only in grid", () => { for (const t of CATALOG_TABLES) { const status = t.columns.find((c) => c.field === "status")!; expect(status.editable).toBe(false); expect(status.badge).toBe(true); } }); it("every list's keyField matches one of its own declared columns", () => { for (const t of CATALOG_TABLES) { expect(t.columns.some((c) => c.field === t.keyField)).toBe(true); } }); });