import { describe, expect, it } from "vitest"; import { composeInstalledMessageCatalogs, INSTALLED_MESSAGE_CATALOGS, } from "../../src/features/installed-feature-messages.ts"; import { INSTALLED_PRODUCT_FEATURE_MODULES } from "../../src/features/installed-product-manifest.ts"; import { TECH_LOG_MESSAGE_CATALOGS } from "../../src/features/tech-log/contracts/tech-log-message-catalog.ts"; // Template sync (af3d8e6). TechLog's catalogs are composed directly beside the // installed modules' (src/features/tech-log/NOT_INSTALLED). const SOURCES = [ ...INSTALLED_PRODUCT_FEATURE_MODULES, { messages: TECH_LOG_MESSAGE_CATALOGS }, ]; describe("installed feature message catalogs (Q-6.9-12)", () => { it("keeps every message each installed feature declares", () => { // Read from the installed modules, not a named sample: the catalog is // empty once the sample is removed (FE-GATE-020), and that is still valid. const locales = new Set( SOURCES.flatMap((module) => Object.keys(module.messages)), ); expect(Object.keys(INSTALLED_MESSAGE_CATALOGS).sort()).toEqual([...locales].sort()); for (const module of SOURCES) { for (const [locale, catalog] of Object.entries(module.messages)) { expect(INSTALLED_MESSAGE_CATALOGS[locale as keyof typeof INSTALLED_MESSAGE_CATALOGS]) .toMatchObject(catalog); } } }); it("composes every locale a feature declares, not a fixed list", () => { const catalogs = composeInstalledMessageCatalogs([ { messages: { "ko-KR": { a: "가" }, "ja-JP": { a: "あ" } } }, { messages: { "ko-KR": { b: "나" } } }, ]); expect(catalogs).toEqual({ "ko-KR": { a: "가", b: "나" }, "ja-JP": { a: "あ" }, }); expect(Object.isFrozen(catalogs["ko-KR"])).toBe(true); }); it("rejects a key two features define for the same locale", () => { expect(() => composeInstalledMessageCatalogs([ { messages: { "en-US": { a: "A" } } }, { messages: { "en-US": { a: "B" } } }, ]), ).toThrow("Duplicate en-US message key: a"); }); });