55 lines
2.2 KiB
TypeScript
55 lines
2.2 KiB
TypeScript
import { describe, expect, test } from "vitest";
|
|
import { anredeVariants, defaultAnrede, effectiveLng, formalLngs, isAnrede, supportedLocales } from "./index.js";
|
|
|
|
// Coverage gap: the formality (Anrede) axis — `isAnrede` and `effectiveLng`
|
|
// (index.ts) had no direct test. This is the du/sie switch that maps a tenant's
|
|
// formality choice onto an i18next "<locale>-formal" language variant.
|
|
|
|
describe("anrede axis constants", () => {
|
|
test("exposes du/sie as the variant set with du as the additive default", () => {
|
|
expect(anredeVariants).toEqual(["du", "sie"]);
|
|
// "du" must stay the default so existing (informal) keys render byte-identical
|
|
// without any tenant config — see the additive-design note in index.ts.
|
|
expect(defaultAnrede).toBe("du");
|
|
});
|
|
|
|
test("derives a formal language variant for every supported locale", () => {
|
|
expect(formalLngs).toEqual(supportedLocales.map((locale) => `${locale}-formal`));
|
|
expect(formalLngs).toEqual(["de-formal", "en-formal"]);
|
|
});
|
|
});
|
|
|
|
describe("isAnrede", () => {
|
|
test("accepts the known formality values", () => {
|
|
expect(isAnrede("du")).toBe(true);
|
|
expect(isAnrede("sie")).toBe(true);
|
|
});
|
|
|
|
test("rejects unknown, empty and undefined values", () => {
|
|
expect(isAnrede("Sie")).toBe(false); // case-sensitive, not normalized
|
|
expect(isAnrede("formal")).toBe(false);
|
|
expect(isAnrede("")).toBe(false);
|
|
expect(isAnrede(undefined)).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("effectiveLng", () => {
|
|
test("returns the plain locale for the informal default (du)", () => {
|
|
// No second arg → defaultAnrede ("du") → effective language is the bare locale.
|
|
expect(effectiveLng("de")).toBe("de");
|
|
expect(effectiveLng("en", "du")).toBe("en");
|
|
});
|
|
|
|
test("maps the formal axis (sie) onto the <locale>-formal variant", () => {
|
|
expect(effectiveLng("de", "sie")).toBe("de-formal");
|
|
expect(effectiveLng("en", "sie")).toBe("en-formal");
|
|
});
|
|
|
|
test("does not validate the locale string — it only suffixes it", () => {
|
|
// effectiveLng is a pure string mapping; an unknown locale still gets the
|
|
// "-formal" suffix under "sie" (validation is the caller's job).
|
|
expect(effectiveLng("xx", "sie")).toBe("xx-formal");
|
|
expect(effectiveLng("xx")).toBe("xx");
|
|
});
|
|
});
|