| 1 | import { describe, expect, it } from "vitest"; |
| 2 | import { |
| 3 | ALL_LOCALES, |
| 4 | defaultLocale, |
| 5 | isPartialLocale, |
| 6 | isTrackedLocale, |
| 7 | isValidLocale, |
| 8 | localeDirection, |
| 9 | locales, |
| 10 | partialLocales, |
| 11 | } from "./config"; |
| 12 | |
| 13 | describe("locale registry (single canonical taxonomy)", () => { |
| 14 | it("routes exactly the shipped and partial locales", () => { |
| 15 | const routed = ALL_LOCALES.filter( |
| 16 | (l) => l.status === "shipped" || l.status === "partial", |
| 17 | ).map((l) => l.code); |
| 18 | expect([...locales]).toEqual(routed); |
| 19 | }); |
| 20 | |
| 21 | it("keeps planned and deferred locales out of route generation", () => { |
| 22 | const notRouted = ALL_LOCALES.filter( |
| 23 | (l) => l.status === "planned" || l.status === "deferred", |
| 24 | ).map((l) => l.code); |
| 25 | // Every tracked locale is routed as of the wave-2 localization, so the |
| 26 | // registry has no planned/deferred entries today — the invariant below |
| 27 | // still guards any future demotion. |
| 28 | expect(notRouted).toEqual([]); |
| 29 | for (const code of notRouted) { |
| 30 | expect(locales).not.toContain(code); |
| 31 | expect(isValidLocale(code)).toBe(false); |
| 32 | expect(isTrackedLocale(code)).toBe(true); |
| 33 | } |
| 34 | }); |
| 35 | |
| 36 | it("ships the v0.9.2 wave and the wave-2 majors as partial with visible status", () => { |
| 37 | for (const code of [ |
| 38 | "ja", "vi", "ko", "ru", "uk", "es", "pt-BR", "id", |
| 39 | "fr", "de", "ca", "hi", "tr", "it", "pl", "ar", |
| 40 | ]) { |
| 41 | expect(isValidLocale(code), code).toBe(true); |
| 42 | expect(isPartialLocale(code), code).toBe(true); |
| 43 | } |
| 44 | expect(partialLocales).not.toContain("en"); |
| 45 | expect(partialLocales).not.toContain("zh"); |
| 46 | }); |
| 47 | |
| 48 | it("derives the document direction from the registry (RTL plumbing)", () => { |
| 49 | expect(localeDirection("ar")).toBe("rtl"); |
| 50 | for (const l of ALL_LOCALES) { |
| 51 | if (l.code === "ar") continue; |
| 52 | expect(localeDirection(l.code), `${l.code} dir`).toBe("ltr"); |
| 53 | } |
| 54 | expect(localeDirection("en")).toBe("ltr"); |
| 55 | expect(localeDirection("xx")).toBe("ltr"); |
| 56 | }); |
| 57 | |
| 58 | it("has unique codes and native-script labels", () => { |
| 59 | const codes = ALL_LOCALES.map((l) => l.code); |
| 60 | expect(new Set(codes).size).toBe(codes.length); |
| 61 | const labels = Object.fromEntries(ALL_LOCALES.map((l) => [l.code, l.label])); |
| 62 | expect(labels["ru"]).toBe("Русский"); |
| 63 | expect(labels["uk"]).toBe("Українська"); |
| 64 | expect(labels["ja"]).toBe("日本語"); |
| 65 | expect(labels["ko"]).toBe("한국어"); |
| 66 | expect(labels["vi"]).toBe("Tiếng Việt"); |
| 67 | expect(labels["pt-BR"]).toBe("Português (BR)"); |
| 68 | expect(labels["hi"]).toBe("हिन्दी"); |
| 69 | }); |
| 70 | |
| 71 | it("keeps the default locale routed", () => { |
| 72 | expect(locales).toContain(defaultLocale); |
| 73 | expect(defaultLocale).toBe("en"); |
| 74 | }); |
| 75 | }); |
| 76 |