import { describe, expect, test } from "vitest"; import i18next from "i18next"; import { ensureServerGlobalI18n, syncServerGlobalI18nLanguage } from "./i18next.global.server"; describe("server global i18next bootstrap", () => { test("initialises the global instance with preloaded resources", async () => { await ensureServerGlobalI18n(); expect(i18next.isInitialized).toBe(true); // The sidebar toggle label is the canonical string that previously rendered // empty during SSR (causing button-name a11y failures + hydration #418). expect(i18next.t("components.sidebar.toggle")).not.toBe(""); expect(i18next.t("components.sidebar.toggle")).not.toBe("components.sidebar.toggle"); }); test("aligns the global language with the requested locale", async () => { await syncServerGlobalI18nLanguage("en"); expect(i18next.language).toBe("en"); const en = i18next.t("components.sidebar.toggle"); await syncServerGlobalI18nLanguage("de"); expect(i18next.language).toBe("de"); const de = i18next.t("components.sidebar.toggle"); expect(en).not.toBe(""); expect(de).not.toBe(""); expect(de).not.toBe(en); }); });