Files
HiveGrid-Wireframes/hivegrid-cloud/apps/web/app/routes/api.embed.forms.$formKey.submit.i18n.test.ts
T

30 lines
1.1 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { readRepoFile } from "~/utils/testing/repoPaths";
function getValueAtPath(source: Record<string, unknown>, path: string): unknown {
return path.split(".").reduce<unknown>((current, segment) => {
if (!current || typeof current !== "object") {
return undefined;
}
return (current as Record<string, unknown>)[segment];
}, source);
}
describe("embed form submit i18n", () => {
it("keeps every public submit error key translated in supported locales", () => {
const routeSource = readRepoFile("apps/web/app/routes/api.embed.forms.$formKey.submit.tsx");
const errorKeys = Array.from(routeSource.matchAll(/"embed\.forms\.submit\.errors\.[^"]+"/gu)).map(([match]) =>
match.replaceAll('"', "")
);
expect(errorKeys).toHaveLength(14);
for (const locale of ["en", "de"]) {
const translations = JSON.parse(readRepoFile(`apps/web/public/locales/${locale}/translations.json`)) as Record<string, unknown>;
for (const key of errorKeys) {
expect(getValueAtPath(translations, key), `${locale}:${key}`).toEqual(expect.any(String));
}
}
});
});