Files
Epicnabbo-Catalogus-Updated…/src/features/housekeeping/foundation/localization-contract.test.ts
T

196 lines
7.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import en from "@/messages/en.json";
import itMessages from "@/messages/it.json";
import { HOUSEKEEPING_MANIFESTS } from "../manifests";
const requiredKeys = [
"pages.housekeeping.preview.badge",
"pages.housekeeping.preview.commandDisabled",
"pages.housekeeping.preview.backToSite",
"pages.housekeeping.navigation.skipToContent",
"pages.housekeeping.navigation.primary",
"pages.housekeeping.navigation.contextual",
"pages.housekeeping.states.loading.title",
"pages.housekeeping.states.loading.description",
"pages.housekeeping.states.empty.title",
"pages.housekeeping.states.empty.description",
"pages.housekeeping.states.partial.label",
"pages.housekeeping.states.partial.title",
"pages.housekeeping.states.partial.description",
"pages.housekeeping.states.error.title",
"pages.housekeeping.states.error.description",
];
const systemRouteMessageKeys = [
"pages.housekeeping.routes.system.access.permissions",
"pages.housekeeping.routes.system.access.permission-detail",
"pages.housekeeping.routes.system.configuration.settings",
"pages.housekeeping.routes.system.configuration.emulator",
"pages.housekeeping.routes.system.observability.analytics",
"pages.housekeeping.routes.system.observability.analytics-activity",
"pages.housekeeping.routes.system.observability.analytics-economy",
"pages.housekeeping.routes.system.observability.devops",
"pages.housekeeping.routes.system.observability.devops-errors",
"pages.housekeeping.routes.system.observability.logs-staff",
"pages.housekeeping.routes.system.observability.logs-audit",
"pages.housekeeping.routes.system.observability.logs-chat",
"pages.housekeeping.routes.system.observability.logs-commands",
"pages.housekeeping.routes.system.observability.logs-trades",
"pages.housekeeping.routes.system.operations.alerts",
"pages.housekeeping.routes.system.operations.command-center",
"pages.housekeeping.routes.system.operations.maintenance",
] as const;
const economyRouteMessageKeys = [
"pages.housekeeping.routes.economy.catalog.overview",
"pages.housekeeping.routes.economy.catalog.detail",
"pages.housekeeping.routes.economy.catalog.builder-club-detail",
"pages.housekeeping.routes.economy.catalog.maintenance",
"pages.housekeeping.routes.economy.items.overview",
"pages.housekeeping.routes.economy.items.detail",
"pages.housekeeping.routes.economy.commerce.shop",
"pages.housekeeping.routes.economy.commerce.shop-create",
"pages.housekeeping.routes.economy.commerce.shop-detail",
"pages.housekeeping.routes.economy.commerce.marketplace",
"pages.housekeeping.routes.economy.commerce.vouchers",
"pages.housekeeping.routes.economy.commerce.subscriptions",
"pages.housekeeping.routes.economy.history.transactions",
"pages.housekeeping.routes.economy.value.rare-values",
"pages.housekeeping.routes.economy.rewards.badges",
"pages.housekeeping.routes.economy.rewards.achievements",
"pages.housekeeping.routes.economy.rewards.sounds",
"pages.housekeeping.routes.economy.rewards.calendar",
"pages.housekeeping.routes.economy.rewards.calendar-detail",
] as const;
const hotelRouteMessageKeys = [
"pages.housekeeping.routes.hotel.rooms",
"pages.housekeeping.routes.hotel.room-detail",
"pages.housekeeping.routes.hotel.room-furni",
"pages.housekeeping.routes.hotel.navigation",
"pages.housekeeping.routes.hotel.radio.overview",
"pages.housekeeping.routes.hotel.radio.settings",
"pages.housekeeping.routes.hotel.radio.monitoring",
"pages.housekeeping.routes.hotel.radio.moderation",
"pages.housekeeping.routes.hotel.radio.autodj",
"pages.housekeeping.routes.hotel.radio.history",
"pages.housekeeping.routes.hotel.radio.points",
"pages.housekeeping.routes.hotel.radio.ranks",
"pages.housekeeping.routes.hotel.radio.api-keys",
"pages.housekeeping.routes.hotel.radio.banners",
"pages.housekeeping.routes.hotel.radio.embed",
] as const;
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 {
return key.split(".").reduce<unknown>((value, segment) => {
if (value === null || typeof value !== "object") return undefined;
return (value as Record<string, unknown>)[segment];
}, messages);
}
describe("housekeeping localization contract", () => {
it.each([
["English", en],
["Italian", itMessages],
])("provides the planned housekeeping subtree in %s", (_locale, messages) => {
const housekeeping = resolveMessage(messages, "pages.housekeeping");
expect(housekeeping).toEqual(expect.any(Object));
expect(Object.keys(housekeeping as object)).toEqual([
"preview",
"navigation",
"domains",
"routes",
"states",
]);
for (const key of requiredKeys) {
expect(resolveMessage(messages, key), key).toEqual(expect.any(String));
}
for (const key of systemRouteMessageKeys) {
const message = resolveMessage(messages, key);
expect(message, key).toEqual(expect.any(String));
expect((message as string).trim(), key).not.toBe("");
}
for (const key of economyRouteMessageKeys) {
const message = resolveMessage(messages, key);
expect(message, key).toEqual(expect.any(String));
expect((message as string).trim(), key).not.toBe("");
}
for (const key of hotelRouteMessageKeys) {
const message = resolveMessage(messages, key);
expect(message, key).toEqual(expect.any(String));
expect((message as string).trim(), key).not.toBe("");
}
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");
expect(
resolveMessage(
itMessages,
"pages.housekeeping.states.loading.description",
),
).toBe("Stiamo preparando gli strumenti di housekeeping disponibili.");
});
});