dika/test/distance-hint.test.js
peppa-bot c4e3481df7
All checks were successful
peppa/lint lint: success за 0с
peppa/test test: success за 1с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 10s
deploy / deploy (pull_request) Successful in 28s
DIK-63: закрытое расстояние объясняет, что нажать; подсказка видна сразу
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 11:36:47 +00:00

34 lines
2.0 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-63: закрытое поле «Расстояние» объясняет, что нажать, а поле адреса видно с подписью
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import { renderPage } from "../src/page.js";
const src = fs.readFileSync("public/index.html", "utf8");
const app = fs.readFileSync("public/app.js", "utf8");
const lang = (l) => JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
test("Сценарий: поле адреса видно на главной с подписью «Введите адрес»", () => {
const html = renderPage(src, lang("ru"));
assert.match(html, /<label for="addr"[^>]*>Введите адрес<\/label>/);
assert.match(html, /<input type="text" id="addr"[^>]*placeholder="Адрес, например/);
assert.doesNotMatch(html.match(/<div id="manual"[^>]*>/)[0], /hidden/);
});
test("Сценарий: место не известно — расстояние закрыто, рядом написано, что нажать", () => {
const html = renderPage(src, lang("ru"));
assert.match(html, /<select id="maxKm" disabled aria-describedby="distNote">/);
const note = html.match(/<p class="meta" id="distNote"([^>]*)>([^<]*)<\/p>/);
assert.ok(note, "подсказка есть");
assert.doesNotMatch(note[1], /hidden/, "подсказка видна без скрипта");
for (const l of ["ru", "kk", "en"]) {
const d = lang(l);
assert.ok(d.distNeedPlace.includes(`«${d.useLocation}»`), `${l}: называет кнопку места`);
assert.ok(d.distNeedPlace.includes(`«${d.findAddress}»`), `${l}: называет кнопку адреса`);
}
});
test("Сценарий: после определения места расстояние открывается и подсказка прячется", () => {
assert.match(app, /\$\("maxKm"\)\.disabled = !pos; \$\("distNote"\)\.hidden = Boolean\(pos\)/);
});