dika/test/home-sources.test.js
peppa-bot 1be7d3a00d
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 1с
peppa/build build: success за 1с
ci / checks (pull_request) Successful in 12s
deploy / deploy (pull_request) Successful in 19s
DIK-68: блок «Откуда данные» на главной заполнен, ссылки ведут к нему
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:53:11 +00:00

41 lines
2.2 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-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, /[А-Яа-я]/);
}
});