peppa/packages/testkit/test/language-menu.test.ts
Асель b9232c9e64 PEP-136: language switcher in the menu on every page
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 09:20:54 +05:00

38 lines
2.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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"), /<Sidebar /);
const sidebar = read("apps/web/components/Sidebar.tsx");
// Desktop: three buttons in the panel; phone: the compact list in the top bar.
assert.match(sidebar, /<LanguageSwitcher className="[^"]*max-md:hidden[^"]*" \/>/);
assert.match(sidebar, /<LanguageSwitcher compact className="[^"]*md:hidden[^"]*" \/>/);
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, /<select\s+aria-label=\{t\("Язык интерфейса"\)\}/);
assert.match(body, /role="group" aria-label=\{t\("Язык интерфейса"\)\}/);
assert.equal(t("en", "Язык интерфейса"), "Interface language");
assert.equal(t("kk", "Язык интерфейса"), "Интерфейс тілі");
assert.equal(t("kk", "Проекты"), "Жобалар");
});
test("Неизвестный язык из переключателя: значение «de» даёт русский", () => {
assert.equal(normalizeLocale("de"), "ru");
assert.equal(normalizeLocale("kk"), "kk");
assert.match(read("apps/web/app/locale-actions.ts"), /const locale = normalizeLocale\(value\)/);
});
});