返回 CodeWhale
config.test.ts
根目录 / web / lib / i18n / config.test.ts
1 import { describe, expect, it } from "vitest";
2 import {
3 ALL_LOCALES,
4 defaultLocale,
5 isPartialLocale,
6 isTrackedLocale,
7 isValidLocale,
8 locales,
9 partialLocales,
10 } from "./config";
11
12 describe("locale registry (single canonical taxonomy)", () => {
13 it("routes exactly the shipped and partial locales", () => {
14 const routed = ALL_LOCALES.filter(
15 (l) => l.status === "shipped" || l.status === "partial",
16 ).map((l) => l.code);
17 expect([...locales]).toEqual(routed);
18 });
19
20 it("keeps planned and deferred locales out of route generation", () => {
21 const notRouted = ALL_LOCALES.filter(
22 (l) => l.status === "planned" || l.status === "deferred",
23 ).map((l) => l.code);
24 expect(notRouted.length).toBeGreaterThan(0);
25 for (const code of notRouted) {
26 expect(locales).not.toContain(code);
27 expect(isValidLocale(code)).toBe(false);
28 expect(isTrackedLocale(code)).toBe(true);
29 }
30 });
31
32 it("ships the v0.9.2 website wave as partial with visible status", () => {
33 for (const code of ["ja", "vi", "ko", "ru", "uk", "es", "pt-BR", "id"]) {
34 expect(isValidLocale(code)).toBe(true);
35 expect(isPartialLocale(code)).toBe(true);
36 }
37 expect(partialLocales).not.toContain("en");
38 expect(partialLocales).not.toContain("zh");
39 expect(isPartialLocale("fr")).toBe(false);
40 expect(isValidLocale("fr")).toBe(false);
41 });
42
43 it("has unique codes and native-script labels", () => {
44 const codes = ALL_LOCALES.map((l) => l.code);
45 expect(new Set(codes).size).toBe(codes.length);
46 const labels = Object.fromEntries(ALL_LOCALES.map((l) => [l.code, l.label]));
47 expect(labels["ru"]).toBe("Русский");
48 expect(labels["uk"]).toBe("Українська");
49 expect(labels["ja"]).toBe("日本語");
50 expect(labels["ko"]).toBe("한국어");
51 expect(labels["vi"]).toBe("Tiếng Việt");
52 expect(labels["pt-BR"]).toBe("Português (BR)");
53 expect(labels["hi"]).toBe("हिन्दी");
54 });
55
56 it("keeps the default locale routed", () => {
57 expect(locales).toContain(defaultLocale);
58 expect(defaultLocale).toBe("en");
59 });
60 });
61
61 lines TYPESCRIPT