import { describe, it, expect } from "vitest"; import { REFERENCE_TABLES } from "./referenceTables"; import { DEFAULT_MESSAGES } from "./i18n/defaultMessages"; // Column registry lock (spec "admin-portal-reference-ui", requirement "One Generic Grid // Renders Each Table's Registry Columns"): the /reference grid renders EXACTLY the columns // the picked table's registry declares — preferredLanguage shows no message_tag column, // nationality adds iso_code, marritalStatus adds a spouse_required (Y/N) select. function fieldNames(key: string): string[] { const spec = REFERENCE_TABLES.find((t) => t.key === key); if (!spec) throw new Error(`no registry entry for ${key}`); return spec.columns.map((c) => c.field); } describe("REFERENCE_TABLES column registry", () => { it("covers exactly the five allow-listed tables, each keyed by code", () => { expect(REFERENCE_TABLES.map((t) => t.key)).toEqual([ "nationality", "marritalStatus", "race", "preferredLanguage", "salutation", ]); for (const t of REFERENCE_TABLES) { expect(t.keyField).toBe("code"); expect(t.label.length).toBeGreaterThan(0); } }); it("nationality: code, name, message_tag and iso_code", () => { expect(fieldNames("nationality")).toEqual(["code", "name", "messageTag", "isoCode"]); }); it("marritalStatus: code, name, message_tag and a spouse_required Y/N select", () => { const spec = REFERENCE_TABLES.find((t) => t.key === "marritalStatus")!; expect(fieldNames("marritalStatus")).toEqual(["code", "name", "messageTag", "spouseRequired"]); const spouse = spec.columns.find((c) => c.field === "spouseRequired")!; expect(spouse.options?.map((o) => o.value)).toEqual(["Y", "N"]); expect(spouse.editable).toBe(true); }); it("preferredLanguage has NO message_tag column (the table has no such column)", () => { expect(fieldNames("preferredLanguage")).toEqual(["code", "name"]); }); it("race: code, name and message_tag only", () => { expect(fieldNames("race")).toEqual(["code", "name", "messageTag"]); }); it("salutation: code, name and message_tag only", () => { expect(fieldNames("salutation")).toEqual(["code", "name", "messageTag"]); }); it("code and name are required and editable on every table; message_tag/iso_code are not", () => { for (const t of REFERENCE_TABLES) { const code = t.columns.find((c) => c.field === "code")!; const name = t.columns.find((c) => c.field === "name")!; expect(code.required).toBe(true); expect(code.editable).toBe(true); expect(name.required).toBe(true); expect(name.editable).toBe(true); for (const c of t.columns) { if (c.field === "messageTag" || c.field === "isoCode") { expect(c.required ?? false).toBe(false); } } } }); }); // Copy lock (spec "portal-copy-i18n", A7): table, column and option labels hold message codes, // translated with t() where they render, so admins can edit and translate them in /messages. describe("REFERENCE_TABLES labels are message codes", () => { it("labels every table, column and option with a code that has an English default", () => { for (const t of REFERENCE_TABLES) { const labels = [t.label, ...t.columns.flatMap((c) => [c.label, ...(c.options ?? []).map((o) => o.label)])]; for (const label of labels) expect(Object.hasOwn(DEFAULT_MESSAGES, label), label).toBe(true); } }); it("names a row with CatName, not the person-name code", () => { for (const t of REFERENCE_TABLES) expect(t.columns.find((c) => c.field === "name")?.label).toBe("CatName"); }); it("labels the spouse-required options with the shared yes/no codes", () => { const spouse = REFERENCE_TABLES.find((t) => t.key === "marritalStatus")!.columns.find((c) => c.field === "spouseRequired")!; expect(spouse.options?.map((o) => o.label)).toEqual(["Yes", "No"]); }); });