fix(i18n): preserve inherited-name labels as untranslated data

This commit is contained in:
cesnimda
2026-11-02 22:23:26 +01:00
parent 8909e53467
commit 7b132ec4b4
7 changed files with 36 additions and 2 deletions
@@ -78,6 +78,12 @@ const match = {
beforeEach(() => jest.clearAllMocks());
test.each(["constructor", "toString", "__proto__"])("timeline preserves unknown category %s as a label", async category => {
mockedApi.get.mockResolvedValue({ data: { ...timeline, categories: ["stage", category] } } as any);
render(<ApplicationTimeline jobId={7} />);
expect(await screen.findByRole("button", { name: category })).toBeInTheDocument();
});
// ---------- Timeline ----------
test("timeline renders grouped days, milestones and readable summaries", async () => {
@@ -0,0 +1,13 @@
import { localizeCompletenessLabel } from "./views/career/careerCompletenessLabels";
test.each(["constructor", "toString", "__proto__", "Custom section"])("preserves unknown completeness label %s as data", label => {
const translate = jest.fn(() => "translated");
expect(localizeCompletenessLabel(label, translate)).toBe(label);
expect(translate).not.toHaveBeenCalled();
});
test("translates a known completeness label using its catalogue key", () => {
const translate = jest.fn(() => "Personopplysninger");
expect(localizeCompletenessLabel("Personal details", translate)).toBe("Personopplysninger");
expect(translate).toHaveBeenCalledWith("profileCvCompletenessPersonal");
});
@@ -364,7 +364,7 @@ function timelineCategoryLabel(t: (key: any) => string, category: string): strin
communication: "intelligenceCategoryCommunication",
ai: "intelligenceCategoryAi",
};
return keys[category] ? t(keys[category]) : category;
return Object.hasOwn(keys, category) ? t(keys[category]) : category;
}
function matchBandLabel(t: (key: any) => string, band?: string): string {
@@ -11,6 +11,6 @@ const completenessLabelKeys: Record<string, TranslationKey> = {
};
export function localizeCompletenessLabel(label: string, t: (key: TranslationKey) => string) {
const key = completenessLabelKeys[label];
const key = Object.hasOwn(completenessLabelKeys, label) ? completenessLabelKeys[label] : undefined;
return key ? t(key) : label;
}