peppa/packages/testkit/test/product-help.test.ts
Асель 4c0a08bef2 PEP-149: translations, help, agent rules, scenario tests
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 13:06:08 +05:00

48 lines
3.0 KiB
TypeScript

// PEP-122: «Помощь» for the «Продакт» view — three answers in three languages, glossary words only.
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { describe, test } from "node:test";
import { HELP_LANGS, PRODUCT_HELP, type ProductHelpText } from "@peppa/core";
const strings = (t: ProductHelpText) => [t.title, t.lead, t.question, t.product, t.messages.title, ...t.messages.items, t.more, t.moreLink, ...t.sections.flatMap((s) => [s.title, ...s.steps, s.note])];
/** «Нельзя» column of docs/glossary.md. */
function forbidden(): string[] {
const rows = readFileSync(new URL("../../../docs/glossary.md", import.meta.url), "utf8")
.split("\n")
.filter((l) => l.startsWith("|") && !l.startsWith("|---") && !l.startsWith("| Понятие"));
return rows.flatMap((r) => r.split("|")[3]!.split(",").map((w) => w.trim()).filter(Boolean));
}
describe("PEP-122: «Помощь» для вида «Продакт»", () => {
test("Продакт открывает «Помощь»: три ответа — поставить задачу, принять, поправить", () => {
assert.deepEqual(PRODUCT_HELP.ru.sections.map((s) => s.title), ["Как поставить задачу", "Как принять работу", "Если результат не нравится"]);
assert.match(PRODUCT_HELP.ru.sections[1].steps.join(" "), /«Принять»/);
assert.match(PRODUCT_HELP.ru.sections[2].steps.join(" "), /«Ответить»/);
});
test("тексты есть на русском, казахском и английском, одной формы и без пустых строк", () => {
assert.deepEqual([...HELP_LANGS], ["ru", "kk", "en"]);
for (const lang of HELP_LANGS) {
const t = PRODUCT_HELP[lang];
assert.equal(t.sections.length, 3, lang);
t.sections.forEach((s, i) => assert.equal(s.steps.length, PRODUCT_HELP.ru.sections[i]!.steps.length, `${lang}: steps of section ${i + 1}`));
for (const s of strings(t)) assert.ok(s.trim().length > 0, lang);
}
assert.notDeepEqual(strings(PRODUCT_HELP.kk), strings(PRODUCT_HELP.ru));
assert.notDeepEqual(strings(PRODUCT_HELP.en), strings(PRODUCT_HELP.ru));
});
test("Слова из словаря: в русском тексте нет слов из колонки «Нельзя»", () => {
const words = forbidden();
assert.ok(words.includes("стори") && words.includes("PR") && words.includes("ты"), "the glossary is parsed");
// «Peppa FACTORY» is the allowed product name; the bare «Peppa» is not.
const text = strings(PRODUCT_HELP.ru).join("\n").replaceAll("Peppa FACTORY", "");
for (const w of words) {
const esc = w.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const re = /^[\p{L}\p{N} ]+$/u.test(w) ? new RegExp(`(?<![\\p{L}\\p{N}])${esc}(?![\\p{L}\\p{N}])`, "iu") : new RegExp(esc, "u");
assert.doesNotMatch(text, re, `«${w}» is in the «Нельзя» column of docs/glossary.md`);
}
});
});