35 lines
1.8 KiB
JavaScript
35 lines
1.8 KiB
JavaScript
// DIK-23: главная без служебных фраз, всё подписано, тексты на одном языке.
|
||
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"));
|
||
|
||
test("сценарий «Нет служебных фраз»: на главной нет Esil и Almaty", () => {
|
||
for (const l of ["ru", "kk", "en"]) {
|
||
const t = tr(l);
|
||
for (const [k, v] of Object.entries(t)) {
|
||
if (typeof v === "string" && !k.startsWith("adm")) assert.doesNotMatch(v, /\b(esil|almaty)\b/i, `${l}.${k}`);
|
||
}
|
||
}
|
||
assert.doesNotMatch(html, /\b(esil|almaty)\b/i);
|
||
});
|
||
|
||
test("сценарий «Всё подписано»: у кнопок есть текст или подпись, у полей — label", () => {
|
||
for (const m of html.matchAll(/<button\b([^>]*)>([\s\S]*?)<\/button>/g)) {
|
||
assert.match(m[1] + m[2], /data-i=|data-al=|aria-label=|>[^<\s][^<]*</, m[0]);
|
||
}
|
||
for (const id of ["addr", "maxKm", "maxPrice"]) assert.match(html, new RegExp(`<label for="${id}"`));
|
||
});
|
||
|
||
test("сценарий «Один язык»: по умолчанию русский, RU/KK/EN есть, ключи совпадают", () => {
|
||
assert.match(html, /<html lang="ru"/);
|
||
for (const l of ["ru", "kk", "en"]) assert.match(html, new RegExp(`data-l="${l}"`));
|
||
const keys = Object.keys(tr("ru")).sort();
|
||
assert.deepEqual(Object.keys(tr("kk")).sort(), keys);
|
||
assert.deepEqual(Object.keys(tr("en")).sort(), keys);
|
||
const ru = /[А-Яа-я]/;
|
||
for (const k of ["subtitle", "useLocation", "noDescription"]) assert.doesNotMatch(tr("en")[k], ru, k);
|
||
});
|