1
0
forked from baron/baron-sso
Files
baron-sso/adminfront/src/lib/i18n.test.ts
2026-05-20 13:41:15 +09:00

36 lines
1.0 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from "vitest";
import { t } from "./i18n";
describe("i18n utility", () => {
beforeEach(() => {
window.localStorage.clear();
vi.clearAllMocks();
});
it("returns fallback if key not found", () => {
expect(t("this.key.truly.does.not.exist", "Fallback")).toBe("Fallback");
});
it("returns key if fallback not provided and key not found", () => {
expect(t("this.key.truly.does.not.exist")).toBe(
"this.key.truly.does.not.exist",
);
});
it("replaces variables in template", () => {
expect(t("this.test.key", "Hello {{ name }}", { name: "World" })).toBe(
"Hello World",
);
});
it("respects locale in localStorage", () => {
window.localStorage.setItem("locale", "en");
expect(t("ui.common.save", "Save")).toBe("Save");
});
it("defaults to ko if no locale set and browser language is ko", () => {
vi.spyOn(window.navigator, "language", "get").mockReturnValue("ko-KR");
expect(t("ui.common.save", "저장")).toBe("저장");
});
});