Files

69 lines
3.0 KiB
JavaScript

// @vitest-environment node
import { describe, expect, it } from "vitest";
import { findTransliterations, isExemptValue, renderReport, scanGermanDiacritics } from "./verify-i18n-german-diacritics.mjs";
describe("findTransliterations", () => {
it("catches the spellings the admin audit found in production text", () => {
expect(findTransliterations("Betriebsansicht fuer Worker-Queues")).toContain("fuer");
expect(findTransliterations("Pruefen")).toContain("Pruefen");
expect(findTransliterations("Verzoegert")).toContain("Verzoegert");
expect(findTransliterations("MEILI_URL und MEILI_API_KEY muessen gesetzt sein.")).toContain("muessen");
expect(findTransliterations("Dieser Admin-Prozess laeuft.")).toContain("laeuft");
expect(findTransliterations("Fuer Enterprise- oder Custom-Plaene")).toEqual(expect.arrayContaining(["Fuer", "Plaene"]));
});
it("accepts correctly spelled German text", () => {
expect(findTransliterations("Betriebsansicht für Worker-Queues")).toEqual([]);
expect(findTransliterations("Prüfen")).toEqual([]);
expect(findTransliterations("MEILI_URL und MEILI_API_KEY müssen gesetzt sein.")).toEqual([]);
});
it("leaves legitimate German words alone that merely contain the digraphs", () => {
for (const text of ["Dauer", "Neue Quelle", "Sequenz", "Aktueller Stand", "manuell", "Vertrauenswürdige Geräte", "Lebensdauer", "Zuerst"]) {
expect(findTransliterations(text), text).toEqual([]);
}
});
it("leaves English technical vocabulary alone", () => {
for (const text of ["Queue", "Request", "unique value", "true", "Blueprint", "Preview"]) {
expect(findTransliterations(text), text).toEqual([]);
}
});
});
describe("isExemptValue", () => {
it("keeps sample email addresses and URLs in ASCII", () => {
// `empfaenger@firma.de` is a deliberate ASCII placeholder.
expect(isExemptValue("empfaenger@firma.de, zweiter@firma.de")).toBe(true);
expect(isExemptValue("https://staging-mcp.hivegrid.de")).toBe(true);
expect(isExemptValue("Zahlung überfällig")).toBe(false);
});
});
describe("scanGermanDiacritics", () => {
it("reports the shipped German locale files as clean", async () => {
const result = await scanGermanDiacritics();
expect(result.scannedFiles).toBeGreaterThan(0);
expect(result.findings).toEqual([]);
expect(renderReport(result)).toContain("PASS i18n-diacritics");
});
});
describe("renderReport", () => {
it("names the offending key and word so the fix is obvious", () => {
const report = renderReport({
scannedFiles: 9,
findings: [{ namespace: "translations", key: "admin.jobs.description", words: ["fuer"], value: "Betriebsansicht fuer Worker-Queues" }],
});
expect(report).toContain("FAIL i18n-diacritics");
expect(report).toContain("translations:admin.jobs.description [fuer]");
});
it("fails when no locale file was found at all", () => {
expect(renderReport({ scannedFiles: 0, findings: [] })).toContain("FAIL i18n-diacritics");
});
});