219 lines
8.5 KiB
TypeScript
219 lines
8.5 KiB
TypeScript
import fs from "node:fs";
|
|
import path from "node:path";
|
|
import { describe, expect, it } from "vitest";
|
|
import { ApplicationEvents, getApplicationEventNameKey } from "~/modules/events/types/ApplicationEvent";
|
|
|
|
const repoRoot = process.cwd();
|
|
const textCache = new Map<string, string>();
|
|
const jsonCache = new Map<string, unknown>();
|
|
|
|
type LocaleTranslations = {
|
|
admin: {
|
|
events: {
|
|
filters: {
|
|
eventOption: string;
|
|
};
|
|
};
|
|
};
|
|
events: {
|
|
descriptions: {
|
|
subscription: Record<string, string>;
|
|
};
|
|
names: Record<string, string>;
|
|
};
|
|
models: {
|
|
log: {
|
|
actions: Record<string, string>;
|
|
};
|
|
};
|
|
};
|
|
|
|
function resolveRepoPath(file: string) {
|
|
return path.resolve(repoRoot, file);
|
|
}
|
|
|
|
function readRepoFile(file: string) {
|
|
const resolved = resolveRepoPath(file);
|
|
const cached = textCache.get(resolved);
|
|
if (cached !== undefined) {
|
|
return cached;
|
|
}
|
|
|
|
const source = fs.readFileSync(resolved, "utf8");
|
|
textCache.set(resolved, source);
|
|
return source;
|
|
}
|
|
|
|
function readJsonFile<T>(file: string) {
|
|
const resolved = resolveRepoPath(file);
|
|
if (!jsonCache.has(resolved)) {
|
|
jsonCache.set(resolved, JSON.parse(readRepoFile(file)) as unknown);
|
|
}
|
|
|
|
return jsonCache.get(resolved) as T;
|
|
}
|
|
|
|
function readTranslations(locale: "en" | "de") {
|
|
return readJsonFile<LocaleTranslations>(`apps/web/public/locales/${locale}/translations.json`);
|
|
}
|
|
|
|
function getNestedValue(source: unknown, key: string) {
|
|
return key.split(".").reduce<unknown>((value, segment) => {
|
|
if (!value || typeof value !== "object") {
|
|
return undefined;
|
|
}
|
|
return (value as Record<string, unknown>)[segment];
|
|
}, source);
|
|
}
|
|
|
|
describe("events i18n", () => {
|
|
it("keeps event detail chrome behind semantic keys", () => {
|
|
const sources = [
|
|
"apps/web/app/modules/events/components/EventDetails.tsx",
|
|
"apps/web/app/modules/events/components/EventsTable.tsx",
|
|
"apps/web/app/modules/events/components/StatusBadge.tsx",
|
|
"apps/web/app/components/app/events/LogsTable.tsx",
|
|
"apps/web/app/routes/admin/events.tsx",
|
|
"apps/web/app/routes/app.$tenant/settings/logs/events.$id.tsx",
|
|
"apps/web/app/routes/app.$tenant/settings/logs/events.tsx",
|
|
]
|
|
.map((file) => readRepoFile(file))
|
|
.join("\n");
|
|
|
|
expect(sources).toContain("shared.createdAt");
|
|
expect(sources).toContain("models.tenant.object");
|
|
expect(sources).toContain("models.user.object");
|
|
expect(sources).toContain("models.log.action");
|
|
expect(sources).toContain("EventUtils.parseName");
|
|
expect(sources).toContain("admin.events.filters.eventOption");
|
|
expect(sources).toContain("settings.logs.events.filters.eventOption");
|
|
expect(sources).toContain("getLogActionI18nKey");
|
|
expect(sources).toContain("events.webhookAttempts.status.notCaught");
|
|
expect(sources).toContain("useLocaleFormatters");
|
|
expect(sources).toContain("createLocaleFormatters");
|
|
expect(sources).toContain("useTranslation");
|
|
expect(sources).toContain('t("shared.notSet")');
|
|
expect(sources).not.toContain("t as i18nT");
|
|
expect(sources).not.toContain("DateUtils.");
|
|
expect(sources).not.toContain('from "~/utils/shared/DateUtils"');
|
|
expect(sources).not.toContain("ui.autogenerated");
|
|
expect(sources).not.toContain("Webhook Attempt #");
|
|
expect(sources).not.toContain("Webhook not catched");
|
|
expect(sources).not.toContain("title={item.name}");
|
|
expect(sources).not.toContain("title: data.item.name");
|
|
expect(sources).not.toContain("${item.value} - ${t(");
|
|
expect(sources).not.toContain("{i.name}</Badge>");
|
|
expect(sources).not.toContain('italic">?</span>');
|
|
});
|
|
|
|
it("localizes event preference values before interpolation", () => {
|
|
const source = readRepoFile("apps/web/app/modules/events/utils/EventUtils.ts");
|
|
|
|
expect(source).toContain("translateEventValue");
|
|
expect(source).toContain("shared.locales.${oldLocale}");
|
|
expect(source).toContain("shared.locales.${newLocale}");
|
|
expect(source).toContain("shared.${oldTheme}");
|
|
expect(source).toContain("shared.${newTheme}");
|
|
expect(source).not.toContain("oldLocale,\n newLocale,");
|
|
expect(source).not.toContain("oldTheme,\n newTheme,");
|
|
});
|
|
|
|
it("keeps server-side event diagnostics behind semantic keys", () => {
|
|
const source = readRepoFile("apps/web/app/modules/events/services/.server/EventsService.ts");
|
|
|
|
expect(source).toContain("events.webhooks.errors.callEndpointFailed");
|
|
expect(source).toContain("events.actions.viewAccount");
|
|
expect(source).not.toContain("ui.autogenerated");
|
|
});
|
|
|
|
it("keeps localized audit log actions available in English and German", () => {
|
|
const en = readTranslations("en");
|
|
const de = readTranslations("de");
|
|
const actionKeys = [
|
|
"apiKeyCreated",
|
|
"apiKeyUpdated",
|
|
"apiKeyRotated",
|
|
"apiKeyDeleted",
|
|
"updateTenantDetails",
|
|
"updatedAiOverageConfiguration",
|
|
"workspaceRoleCreated",
|
|
"workspaceRoleUpdated",
|
|
"workspaceRoleDeleted",
|
|
];
|
|
|
|
for (const key of actionKeys) {
|
|
expect(en.models.log.actions[key]).toEqual(expect.any(String));
|
|
expect(de.models.log.actions[key]).toEqual(expect.any(String));
|
|
}
|
|
});
|
|
|
|
it("keeps admin event filter option locale keys in parity", () => {
|
|
const en = readTranslations("en");
|
|
const de = readTranslations("de");
|
|
|
|
expect(en.admin.events.filters.eventOption).toBe("{{eventValue}} - {{eventLabel}}");
|
|
expect(de.admin.events.filters.eventOption).toBe("{{eventValue}} - {{eventLabel}}");
|
|
});
|
|
|
|
it("keeps German subscription event names aligned with plan and subscription terminology", () => {
|
|
const de = readTranslations("de");
|
|
|
|
expect(de.events.descriptions.subscription.subscribed).toBe("{{tenant}} hat den Tarif {{product}} abonniert");
|
|
expect(de.events.descriptions.subscription.subscribedByUser).toBe("{{email}} hat für {{tenant}} den Tarif {{product}} abonniert");
|
|
expect(de.events.descriptions.subscription.upgraded).toBe("Tarif-Upgrade: {{tenant}} ({{product}})");
|
|
expect(de.events.descriptions.subscription.downgraded).toBe("Tarif-Downgrade: {{tenant}} ({{product}})");
|
|
expect(de.events.descriptions.subscription.cancelled).toBe("Abonnement gekündigt: {{tenant}} ({{product}})");
|
|
expect(de.events.names.subscription_subscribed).toBe("Tarif abonniert");
|
|
expect(de.events.names.subscription_upgraded).toBe("Tarif-Upgrade");
|
|
expect(de.events.names.subscription_downgraded).toBe("Tarif-Downgrade");
|
|
});
|
|
|
|
it("keeps German row event names aligned with Datensatz terminology", () => {
|
|
const de = readTranslations("de");
|
|
const rowEventNames = Object.entries(de.events.names).filter(([key]) => key.startsWith("row_"));
|
|
|
|
expect(rowEventNames.length).toBeGreaterThan(0);
|
|
for (const [, value] of rowEventNames) {
|
|
expect(value).toEqual(expect.any(String));
|
|
expect(value).not.toMatch(/Zeile|Zeilen/u);
|
|
}
|
|
expect(de.events.names.row_updated).toBe("Datensatz aktualisiert");
|
|
expect(de.events.names.row_comments_reacted).toBe("Reaktion auf Datensatzkommentar");
|
|
});
|
|
|
|
it("keeps every application event name backed by explicit en/de locale keys", () => {
|
|
const locales = ["en", "de"] as const;
|
|
|
|
for (const event of ApplicationEvents) {
|
|
expect(event, event.value).not.toHaveProperty("name");
|
|
|
|
for (const locale of locales) {
|
|
const translations = readTranslations(locale);
|
|
const key = getApplicationEventNameKey(event.value).replace("events.names.", "");
|
|
|
|
expect(translations.events.names, `${locale} ${getApplicationEventNameKey(event.value)}`).toHaveProperty(key);
|
|
expect(translations.events.names[key], `${locale} ${getApplicationEventNameKey(event.value)}`).toEqual(expect.any(String));
|
|
expect(translations.events.names[key].trim(), `${locale} ${getApplicationEventNameKey(event.value)}`).not.toBe("");
|
|
}
|
|
}
|
|
});
|
|
|
|
it("keeps every EventUtils description key backed by explicit en/de locale text", () => {
|
|
const source = readRepoFile("apps/web/app/modules/events/utils/EventUtils.ts");
|
|
const descriptionKeys = Array.from(source.matchAll(/translateEventDescription\(\s*t,\s*"([^"]+)"/g), ([, key]) => key)
|
|
.filter((key) => key.startsWith("events."))
|
|
.sort();
|
|
|
|
expect(descriptionKeys.length).toBeGreaterThan(0);
|
|
|
|
for (const locale of ["en", "de"] as const) {
|
|
const translations = readTranslations(locale);
|
|
|
|
for (const key of descriptionKeys) {
|
|
expect(getNestedValue(translations, key), `${locale} ${key}`).toEqual(expect.any(String));
|
|
expect((getNestedValue(translations, key) as string).trim(), `${locale} ${key}`).not.toBe("");
|
|
}
|
|
}
|
|
});
|
|
});
|