46 lines
2.0 KiB
TypeScript
46 lines
2.0 KiB
TypeScript
/**
|
|
* Smoke test for the Storybook-local i18next bootstrap (#62 Task F).
|
|
*
|
|
* The point of this test is to lock in the contract that the locale
|
|
* toolbar global drives a real `react-i18next` instance — not just html
|
|
* attributes — so future stories that call `useTranslation` resolve
|
|
* against the bundled `apps/web/public/locales` tree at the picked
|
|
* language. Failures here mean a story would render English even when
|
|
* the toolbar reads "DE", which is precisely the regression we're
|
|
* guarding against now that the locale picker is functional.
|
|
*/
|
|
import { describe, expect, it } from "vitest";
|
|
import { getStorybookI18n, setStorybookLocale } from "./i18n";
|
|
|
|
describe("storybook i18n bootstrap", () => {
|
|
it("seeds the `common` namespace for both shipped locales", () => {
|
|
const i18n = getStorybookI18n();
|
|
// `action.save` lives in `common.json` and is present in both EN + DE.
|
|
expect(i18n.hasResourceBundle("en", "common")).toBe(true);
|
|
expect(i18n.hasResourceBundle("de", "common")).toBe(true);
|
|
expect(i18n.getResource("en", "common", "action.save")).toBe("Save");
|
|
expect(i18n.getResource("de", "common", "action.save")).toBeTruthy();
|
|
});
|
|
|
|
it("switches language when the toolbar global flips", async () => {
|
|
const i18n = getStorybookI18n();
|
|
setStorybookLocale("de");
|
|
// changeLanguage is async; wait one microtask for the i18next promise.
|
|
await Promise.resolve();
|
|
expect(i18n.language).toBe("de");
|
|
setStorybookLocale("en");
|
|
await Promise.resolve();
|
|
expect(i18n.language).toBe("en");
|
|
});
|
|
|
|
it("falls back to the default locale for unknown values", async () => {
|
|
const i18n = getStorybookI18n();
|
|
// `ar` is registered as a toolbar item for RTL preview but we don't
|
|
// ship Arabic resources — the helper must coerce it back to the
|
|
// configured default so stories don't render empty keys.
|
|
setStorybookLocale("ar");
|
|
await Promise.resolve();
|
|
expect(["de", "en"]).toContain(i18n.language);
|
|
});
|
|
});
|