98 lines
3.3 KiB
TypeScript
98 lines
3.3 KiB
TypeScript
import { expect, test } from "@playwright/test";
|
|
|
|
const expectedReferencePaths = [
|
|
"admin.pos.reference",
|
|
"bookings.reference",
|
|
"bookings_table.reference",
|
|
"department_dashboard.wash_log.reference",
|
|
"global.payment.reference",
|
|
"objects.columns.reference",
|
|
"pos.bookings.reference",
|
|
"pos.order.reference",
|
|
"tables.bookings.reference",
|
|
"time_booking_flow.reference",
|
|
"user_dashboard.bookings.book.reference",
|
|
];
|
|
|
|
const expectedFuldfValues = {
|
|
"bookings.statuses.completed": "Fuldført",
|
|
"pos.complete": "Fuldfør",
|
|
"pos.completed": "Fuldført",
|
|
"pos.finish_and_register": "Fuldfør og registrer",
|
|
"pos.finish_and_register_new": "Fuldfør og registrer ny",
|
|
"tables.bookings.booking_id_required": "Du skal indtaste booking-id for at fuldføre vask uden vaskecertifikat",
|
|
"tables.bookings.complete_wash_without_certificate": "Fuldfør vask uden vaskecertifikat",
|
|
"tables.bookings.complete_wash_without_certificate_prompt":
|
|
"Indtast booking-id for at fuldføre vask uden vaskecertifikat",
|
|
"tables.bookings.completed": "Fuldført",
|
|
"tables.bookings.wash_completed": "Vasken er fuldført",
|
|
"superuser_invoice_distribution.errors.compare_failed": "Kunne ikke fuldføre sammenligningen",
|
|
} as const;
|
|
|
|
function getValueAtPath(value: unknown, path: string): unknown {
|
|
return path.split(".").reduce<unknown>((current, segment) => {
|
|
if (current && typeof current === "object") {
|
|
return (current as Record<string, unknown>)[segment];
|
|
}
|
|
|
|
return undefined;
|
|
}, value);
|
|
}
|
|
|
|
function collectExactStringPaths(value: unknown, exact: string, prefix = ""): string[] {
|
|
if (value === exact) {
|
|
return [prefix];
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
|
return value.flatMap((entry, index) => collectExactStringPaths(entry, exact, `${prefix}[${index}]`));
|
|
}
|
|
|
|
if (value && typeof value === "object") {
|
|
return Object.entries(value as Record<string, unknown>).flatMap(([key, entry]) =>
|
|
collectExactStringPaths(entry, exact, prefix ? `${prefix}.${key}` : key)
|
|
);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
function collectSubstringPaths(value: unknown, substring: string, prefix = ""): string[] {
|
|
if (typeof value === "string") {
|
|
return value.includes(substring) ? [prefix] : [];
|
|
}
|
|
|
|
if (Array.isArray(value)) {
|
|
return value.flatMap((entry, index) => collectSubstringPaths(entry, substring, `${prefix}[${index}]`));
|
|
}
|
|
|
|
if (value && typeof value === "object") {
|
|
return Object.entries(value as Record<string, unknown>).flatMap(([key, entry]) =>
|
|
collectSubstringPaths(entry, substring, prefix ? `${prefix}.${key}` : key)
|
|
);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
test.describe("Danish locale smoke", () => {
|
|
test("@smoke @pr normalizes targeted Danish locale copy in da locale", async ({ request }) => {
|
|
const response = await request.get("/src/i18n/locales/da.json");
|
|
expect(response.ok()).toBe(true);
|
|
|
|
const locale = (await response.json()) as Record<string, unknown>;
|
|
|
|
for (const path of expectedReferencePaths) {
|
|
expect(getValueAtPath(locale, path), path).toBe("Reference");
|
|
}
|
|
|
|
for (const [path, expectedValue] of Object.entries(expectedFuldfValues)) {
|
|
expect(getValueAtPath(locale, path), path).toBe(expectedValue);
|
|
}
|
|
|
|
expect(collectExactStringPaths(locale, "Referanse")).toEqual([]);
|
|
expect(collectSubstringPaths(locale, "Fullf")).toEqual([]);
|
|
expect(collectSubstringPaths(locale, "fullf")).toEqual([]);
|
|
});
|
|
});
|