// PEP-136: the language switcher lives in the menu of every page behind the login. import assert from "node:assert/strict"; import { readFileSync } from "node:fs"; import { describe, test } from "node:test"; import { LOCALE_LABELS, LOCALES, normalizeLocale, t } from "@peppa/shared/i18n"; const read = (path: string) => readFileSync(new URL(`../../../${path}`, import.meta.url), "utf8"); describe("PEP-136: выбор языка в меню на каждой странице", () => { test("Переключатель языка в меню на Главной: меню всех страниц за входом — Sidebar с переключателем RU / EN / KZ", () => { // One layout draws the menu of every page behind the login, the home page included. assert.match(read("apps/web/app/(app)/layout.tsx"), //); assert.match(sidebar, //); assert.deepEqual(LOCALES.map((l) => LOCALE_LABELS[l]).sort(), ["EN", "KZ", "RU"]); }); test("Смена языка из меню: оба вида зовут одно действие и подписаны на языке пользователя", () => { const src = read("apps/web/components/I18n.tsx"); const body = src.slice(src.indexOf("export function LanguageSwitcher")); assert.equal(body.match(/await setLanguage\(/g)?.length, 1, "one handler for both looks"); assert.match(body, /router\.refresh\(\)/); // the user stays on the page assert.match(body, / { assert.equal(normalizeLocale("de"), "ru"); assert.equal(normalizeLocale("kk"), "kk"); assert.match(read("apps/web/app/locale-actions.ts"), /const locale = normalizeLocale\(value\)/); }); });