test: harden housekeeping registry contracts
This commit is contained in:
1 parent
2d5f03048a
commit
14cfad4029
4 files changed
+239
-11
No files matched your search
@@ -21,6 +21,39 @@ const requiredKeys = [
|
|||||||
"pages.housekeeping.states.error.description",
|
"pages.housekeeping.states.error.description",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
const expectedDomainMessages = [
|
||||||
|
{
|
||||||
|
id: "operations",
|
||||||
|
labelKey: "pages.housekeeping.domains.operations.title",
|
||||||
|
descriptionKey: "pages.housekeeping.domains.operations.description",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "people",
|
||||||
|
labelKey: "pages.housekeeping.domains.people.title",
|
||||||
|
descriptionKey: "pages.housekeeping.domains.people.description",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "content",
|
||||||
|
labelKey: "pages.housekeeping.domains.content.title",
|
||||||
|
descriptionKey: "pages.housekeeping.domains.content.description",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "economy",
|
||||||
|
labelKey: "pages.housekeeping.domains.economy.title",
|
||||||
|
descriptionKey: "pages.housekeeping.domains.economy.description",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "hotel",
|
||||||
|
labelKey: "pages.housekeeping.domains.hotel.title",
|
||||||
|
descriptionKey: "pages.housekeeping.domains.hotel.description",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: "system",
|
||||||
|
labelKey: "pages.housekeeping.domains.system.title",
|
||||||
|
descriptionKey: "pages.housekeeping.domains.system.description",
|
||||||
|
},
|
||||||
|
] as const;
|
||||||
|
|
||||||
function resolveMessage(messages: unknown, key: string): unknown {
|
function resolveMessage(messages: unknown, key: string): unknown {
|
||||||
return key.split(".").reduce<unknown>((value, segment) => {
|
return key.split(".").reduce<unknown>((value, segment) => {
|
||||||
if (value === null || typeof value !== "object") return undefined;
|
if (value === null || typeof value !== "object") return undefined;
|
||||||
@@ -44,14 +77,34 @@ describe("housekeeping localization contract", () => {
|
|||||||
"states",
|
"states",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
for (const key of [
|
for (const key of requiredKeys) {
|
||||||
...HOUSEKEEPING_MANIFESTS.flatMap((manifest) => [
|
|
||||||
manifest.labelKey,
|
|
||||||
manifest.descriptionKey,
|
|
||||||
]),
|
|
||||||
...requiredKeys,
|
|
||||||
]) {
|
|
||||||
expect(resolveMessage(messages, key), key).toEqual(expect.any(String));
|
expect(resolveMessage(messages, key), key).toEqual(expect.any(String));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const [index, expected] of expectedDomainMessages.entries()) {
|
||||||
|
const manifest = HOUSEKEEPING_MANIFESTS[index];
|
||||||
|
|
||||||
|
expect(manifest).toMatchObject(expected);
|
||||||
|
expect(
|
||||||
|
resolveMessage(messages, expected.labelKey),
|
||||||
|
expected.labelKey,
|
||||||
|
).toEqual(expect.any(String));
|
||||||
|
expect(
|
||||||
|
resolveMessage(messages, expected.descriptionKey),
|
||||||
|
expected.descriptionKey,
|
||||||
|
).toEqual(expect.any(String));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
it("uses idiomatic Italian copy for the housekeeping shell", () => {
|
||||||
|
expect(resolveMessage(itMessages, "pages.housekeeping.preview.badge")).toBe(
|
||||||
|
"Anteprima della struttura",
|
||||||
|
);
|
||||||
|
expect(
|
||||||
|
resolveMessage(itMessages, "pages.housekeeping.navigation.primary"),
|
||||||
|
).toBe("Aree housekeeping");
|
||||||
|
expect(
|
||||||
|
resolveMessage(itMessages, "pages.housekeeping.states.loading.title"),
|
||||||
|
).toBe("Caricamento in corso");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { describe, expect, it, vi } from "vitest";
|
import { describe, expect, it, vi } from "vitest";
|
||||||
import { PERMS } from "@/lib/permission-slugs";
|
import { PERMS } from "@/lib/permission-slugs";
|
||||||
|
import { HOUSEKEEPING_MANIFESTS } from "../manifests";
|
||||||
import { anyCapability, type HousekeepingCapabilityContext } from "./contracts";
|
import { anyCapability, type HousekeepingCapabilityContext } from "./contracts";
|
||||||
import { buildHousekeepingNavigation } from "./navigation";
|
import { buildHousekeepingNavigation } from "./navigation";
|
||||||
import { createHousekeepingRegistry } from "./registry";
|
import { createHousekeepingRegistry } from "./registry";
|
||||||
@@ -117,4 +118,34 @@ describe("housekeeping navigation", () => {
|
|||||||
expect(translate).not.toHaveBeenCalledWith("system.title");
|
expect(translate).not.toHaveBeenCalledWith("system.title");
|
||||||
expect(translate).not.toHaveBeenCalledWith("system.description");
|
expect(translate).not.toHaveBeenCalledWith("system.description");
|
||||||
});
|
});
|
||||||
|
it("shows the real People manifest only for its view capabilities", () => {
|
||||||
|
const registry = createHousekeepingRegistry(HOUSEKEEPING_MANIFESTS);
|
||||||
|
const translate = (key: string) => key;
|
||||||
|
|
||||||
|
expect(
|
||||||
|
buildHousekeepingNavigation(
|
||||||
|
registry,
|
||||||
|
context([PERMS.MOD_CFH_VIEW]),
|
||||||
|
translate,
|
||||||
|
).map((domain) => domain.id),
|
||||||
|
).toContain("people");
|
||||||
|
expect(
|
||||||
|
buildHousekeepingNavigation(
|
||||||
|
registry,
|
||||||
|
context([PERMS.MOD_CFH_VIEW]),
|
||||||
|
translate,
|
||||||
|
).map((domain) => domain.id),
|
||||||
|
).not.toContain("economy");
|
||||||
|
|
||||||
|
for (const slug of [PERMS.MOD_ACTIONS, PERMS.MOD_CFH_EDIT]) {
|
||||||
|
const visibleDomainIds = buildHousekeepingNavigation(
|
||||||
|
registry,
|
||||||
|
context([slug]),
|
||||||
|
translate,
|
||||||
|
).map((domain) => domain.id);
|
||||||
|
|
||||||
|
expect(visibleDomainIds).not.toContain("people");
|
||||||
|
expect(visibleDomainIds).not.toContain("economy");
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
File diff suppressed because it is too large.
Load diff
@@ -3263,13 +3263,13 @@
|
|||||||
},
|
},
|
||||||
"housekeeping": {
|
"housekeeping": {
|
||||||
"preview": {
|
"preview": {
|
||||||
"badge": "Anteprima della base",
|
"badge": "Anteprima della struttura",
|
||||||
"commandDisabled": "Ricerca e comandi saranno abilitati in un sottoprogetto successivo.",
|
"commandDisabled": "Ricerca e comandi saranno abilitati in un sottoprogetto successivo.",
|
||||||
"backToSite": "Torna al sito"
|
"backToSite": "Torna al sito"
|
||||||
},
|
},
|
||||||
"navigation": {
|
"navigation": {
|
||||||
"skipToContent": "Vai al contenuto",
|
"skipToContent": "Vai al contenuto",
|
||||||
"primary": "Domini housekeeping",
|
"primary": "Aree housekeeping",
|
||||||
"contextual": "Navigazione del dominio"
|
"contextual": "Navigazione del dominio"
|
||||||
},
|
},
|
||||||
"domains": {
|
"domains": {
|
||||||
@@ -3300,8 +3300,8 @@
|
|||||||
},
|
},
|
||||||
"states": {
|
"states": {
|
||||||
"loading": {
|
"loading": {
|
||||||
"title": "Caricamento housekeeping",
|
"title": "Caricamento in corso",
|
||||||
"description": "Preparazione degli strumenti housekeeping disponibili."
|
"description": "Stiamo preparando gli strumenti housekeeping disponibili."
|
||||||
},
|
},
|
||||||
"empty": {
|
"empty": {
|
||||||
"title": "Nessun contenuto disponibile",
|
"title": "Nessun contenuto disponibile",
|
||||||
|
|||||||
Reference in new issue
Block a user