41 lines
2.2 KiB
JavaScript
41 lines
2.2 KiB
JavaScript
// DIK-68: блок «Откуда данные» на главной заполнен — сценарии openspec/specs/home-texts
|
||
import test from "node:test";
|
||
import assert from "node:assert/strict";
|
||
import fs from "node:fs";
|
||
import { renderPage } from "../src/page.js";
|
||
|
||
const html = fs.readFileSync("public/index.html", "utf8");
|
||
const app = fs.readFileSync("public/app.js", "utf8");
|
||
const tr = (l) => JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
|
||
const block = (h) => h.slice(h.indexOf('<section id="sources">'), h.indexOf("</section>", h.indexOf('<section id="sources">')));
|
||
const kinds = ["srcGis", "srcSite", "srcSocial", "srcCall", "srcVisit"];
|
||
|
||
test("Сценарий: Пользователь открывает «Откуда данные» из меню — под заголовком текст", () => {
|
||
const page = renderPage(html, tr("ru"));
|
||
const b = block(page);
|
||
assert.match(b, /<h2 data-i="srcTitle">Откуда данные<\/h2>/);
|
||
assert.match(b, /ИИ-агент/);
|
||
assert.match(b, /16\.11\.2026/);
|
||
assert.match(b, /уточнять у заведения/);
|
||
for (const k of [...kinds, "srcIntro"]) assert.ok(b.includes(`>${tr("ru")[k]}<`), k);
|
||
assert.match(b, /никто не звонил/);
|
||
assert.match(b, /никто не ходил/);
|
||
});
|
||
|
||
test("Сценарий: Ссылки из меню и приветствия ведут к блоку на главной", () => {
|
||
assert.match(html, /<nav id="menu"[\s\S]*<a href="#sources" data-i="menuSources">/);
|
||
assert.match(html, /class="note-src">[\s\S]*?<a href="#sources" data-i="srcLink">/);
|
||
assert.doesNotMatch(html, /href="\/base#sources"/);
|
||
assert.match(app, /\["#about", "#sources"\]\.includes\(location\.hash\)/);
|
||
});
|
||
|
||
test("Сценарий Outline: блок на выбранном языке", () => {
|
||
for (const l of ["ru", "kk", "en"]) {
|
||
const t = tr(l);
|
||
for (const k of ["srcTitle", "srcIntro", ...kinds]) assert.ok(t[k] && t[k].trim(), `${l}.${k}`);
|
||
assert.match(t.srcIntro, /16\.11\.2026/, `${l}.srcIntro: дата сбора`);
|
||
if (l !== "ru") assert.notEqual(t.srcIntro, tr("ru").srcIntro, `${l}.srcIntro переведён`);
|
||
if (l === "en") assert.doesNotMatch(t.srcIntro, /[А-Яа-я]/);
|
||
}
|
||
});
|