dika/test/home-cleanup.test.js
peppa-bot 814ffe26c7
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 0с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 15s
deploy / deploy (pull_request) Successful in 29s
DIK-54: тест и требование — без районов, меню подписано, вся главная переводится
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-25 12:59:52 +00:00

45 lines
2.7 KiB
JavaScript
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.

// DIK-54: на главной нет районов, у меню ☰ понятное назначение, переключатель меняет весь текст.
import { test } from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
const html = readFileSync(new URL("../public/index.html", import.meta.url), "utf8");
const tr = (l) => JSON.parse(readFileSync(new URL(`../public/i18n/${l}.json`, import.meta.url), "utf8"));
const body = html.slice(html.indexOf("<body>"));
test("сценарий «Нет районов»: ни на одном языке главная не говорит о районах", () => {
for (const l of ["ru", "kk", "en"]) {
for (const [k, v] of Object.entries(tr(l))) {
if (typeof v !== "string" || k.startsWith("adm")) continue;
assert.doesNotMatch(v, /район|аудан|district|Есиль|Алматы|Esil|Almaty/i, `${l}.${k}`);
}
}
assert.doesNotMatch(body, /район|Есиль|Алматы/i);
});
test("сценарий «Меню с понятным назначением»: у ☰ видимая подпись и разделы", () => {
const burger = body.match(/<button id="burger"[\s\S]*?<\/button>/)[0];
assert.match(burger, /data-i="menuLabel"/);
const menu = body.match(/<nav id="menu"[\s\S]*?<\/nav>/)[0];
for (const k of ["menuNearby", "menuAbout", "menuBase", "menuSources"]) assert.match(menu, new RegExp(`data-i="${k}"`));
for (const l of ["ru", "kk", "en"]) for (const k of ["menuLabel", "menuNearby", "menuAbout", "menuBase", "menuSources"]) assert.ok(tr(l)[k], `${l}.${k}`);
assert.equal(tr("ru").menuLabel, "Меню");
});
test("сценарий «Переключатель меняет весь текст»: каждый текст главной из словаря", () => {
// Текст прямо в разметке (не из словаря) не переведётся — его быть не должно, кроме кнопок RU/KK/EN и значка ☰.
const stripped = body.replace(/<script[\s\S]*?<\/script>/g, "").replace(/<style[\s\S]*?<\/style>/g, "");
for (const m of stripped.matchAll(/>([^<]+)</g)) {
const s = m[1].trim();
if (!s || ["RU", "KK", "EN", "☰"].includes(s)) continue;
assert.fail(`текст без перевода: «${s}»`);
}
for (const m of body.matchAll(/data-(?:i|ph|al|ti)="(\w+)"/g)) {
for (const l of ["ru", "kk", "en"]) assert.ok(tr(l)[m[1]], `${l}.${m[1]}`);
}
// Атрибуты-подписи без ключа (title/aria-label/placeholder) допустимы только у кнопок языка.
for (const m of body.matchAll(/<(\w+)\b([^>]*\b(?:title|aria-label|placeholder)="[^"]*"[^>]*)>/g)) {
assert.match(m[2], /data-l=/, m[0]);
}
});