dika/test/client.test.js
Peppa 46a63725da
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 0с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 6s
deploy / deploy (pull_request) Successful in 12s
DIK-43: фильтры по расстоянию и цене ланча
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 15:26:11 +05:00

110 lines
5.9 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.

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
const app = fs.readFileSync("public/app.js", "utf8");
test("Сценарий: местоположение не отвечает — ожидание ограничено 10 секундами", () => {
assert.match(app, /timeout:\s*10000/);
});
test("Сценарий: рядом нет заведений — открывается выбор района и адреса", () => {
assert.match(app, /if \(far\) showManual\(\)/);
});
test("Тексты ожидания есть на трёх языках", () => {
for (const l of ["ru", "kk", "en"]) assert.ok(JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8")).searching);
});
test("Сценарий: у каждого поля и кнопки без текста есть подпись на трёх языках", () => {
const html = fs.readFileSync("public/index.html", "utf8");
assert.doesNotMatch(html, /aria-label="Menu"/);
assert.match(html, /<label for="district"/);
assert.match(html, /<label for="addr"/);
assert.match(html, /id="burger" data-al="menuOpen"/);
for (const l of ["ru", "kk", "en"]) {
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
for (const k of ["menuOpen", "menuLabel", "districtLabel", "districtPlaceholder", "addressLabel"]) assert.ok(d[k], `${l}.${k}`);
}
});
test("Сценарий: выбранный язык запоминается и применяется при следующем открытии", () => {
assert.match(app, /localStorage\.setItem\("lang", l\)/);
assert.match(app, /LANGS\.includes\(saved\(\)\)/);
});
test("Сценарий: названия районов и акции переведены, смеси языков нет", () => {
for (const l of ["kk", "en"]) {
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
assert.ok(d.district_esil && d.district_almaty && Object.keys(d.promoTexts).length >= 3, l);
}
});
test("Сценарий: пока заведений нет — вместо пустого экрана сообщение «список готовится»", () => {
assert.match(app, /listPreparing/);
assert.match(app, /if \(none\)/);
for (const l of ["ru", "kk", "en"]) assert.ok(JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8")).listPreparing, l);
});
test("Сценарий: тексты про районы берутся из базы, а не зашиты в перевод", () => {
for (const l of ["ru", "kk", "en"]) {
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
for (const k of ["subtitle", "aboutText", "noneNearby", "coverage"]) assert.doesNotMatch(d[k], /Есиль|Есіл|Esil|Алматы|Almaty|два района|екі ауданы|Two districts/, `${l}.${k}`);
assert.match(d.coverage, /\{districts\}/);
}
});
test("Сценарий: сообщения запасного пути понятны и без технических ошибок (DIK-13)", () => {
assert.match(app, /e\.code === 1 \? "geoDenied"/);
assert.match(app, /"geoSlow"/);
assert.match(app, /"geoFailed"/);
assert.match(app, /try \{ await show\(\); \} catch \{ msg\("error"\); \}/);
for (const l of ["ru", "kk", "en"]) {
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
for (const k of ["geoDenied", "geoFailed", "geoSlow", "noneNearby", "searching", "error"]) {
assert.ok(d[k], `${l}.${k}`);
assert.doesNotMatch(d[k], /undefined|Error|exception|\b[45]\d\d\b/i, `${l}.${k}`);
}
}
});
test("Сценарий: при первом открытии сайт на русском, а переключатель виден в шапке", () => {
const html = fs.readFileSync("public/index.html", "utf8");
const base = fs.readFileSync("public/base.js", "utf8");
for (const src of [app, base]) {
assert.doesNotMatch(src, /navigator\.language/);
assert.match(src, /LANGS\.includes\(saved\(\)\) \? saved\(\) : "ru"/);
}
const header = html.slice(html.indexOf("<header>"), html.indexOf("</header>"));
for (const l of ["ru", "kk", "en"]) assert.match(header, new RegExp(`data-l="${l}"`));
});
test("Сценарий: после кнопки местоположения всегда есть подсказка, итог и текст про отказ", () => {
assert.match(app, /t\.startHint/);
assert.match(app, /t\.resultsOffers/);
assert.match(app, /msg\("filterNeedPlace"\)/);
for (const l of ["ru", "kk", "en"]) {
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
for (const k of ["startHint", "resultsAll", "resultsOffers", "filterNeedPlace", "geoDenied"]) assert.ok(d[k], `${l}.${k}`);
assert.match(d.resultsAll, /\{n\}/);
}
});
test("Сценарий: сообщение переводится при смене языка, выбранный язык отмечен (DIK-18)", () => {
assert.match(app, /function msg\(key\) \{ lastMsg = key;/);
assert.match(app, /else if \(lastMsg && covered\(\)\.length\) msg\(lastMsg\)/);
assert.match(app, /setAttribute\("aria-pressed", String\(b\.dataset\.l === l\)\)/);
assert.match(app, /setAttribute\("aria-expanded", String\(open\)\)/);
});
test("Сценарий: фильтры расстояния и цены, сброс, тексты на трёх языках (DIK-43)", () => {
const html = fs.readFileSync("public/index.html", "utf8");
assert.match(html, /id="maxKm"/); assert.match(html, /id="maxPrice"/);
assert.match(app, /maxKm=/); assert.match(app, /resetFilters/);
assert.match(app, /\$\("maxKm"\)\.disabled = !pos/);
for (const l of ["ru", "kk", "en"]) {
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
for (const k of ["filterDistance", "distNeedPlace", "filterPrice", "noMatch", "resetFilters", "dist1", "dist2", "dist5", "price2000", "price3000", "price4000"]) assert.ok(d[k], `${l}.${k}`);
}
});