58 lines
1.8 KiB
TypeScript
58 lines
1.8 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",
|
|
];
|
|
|
|
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",
|
|
"states",
|
|
]);
|
|
|
|
for (const key of [
|
|
...HOUSEKEEPING_MANIFESTS.flatMap((manifest) => [
|
|
manifest.labelKey,
|
|
manifest.descriptionKey,
|
|
]),
|
|
...requiredKeys,
|
|
]) {
|
|
expect(resolveMessage(messages, key), key).toEqual(expect.any(String));
|
|
}
|
|
});
|
|
});
|