126 lines
6.9 KiB
JavaScript
126 lines
6.9 KiB
JavaScript
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}`);
|
||
}
|
||
});
|
||
|
||
test("Сценарий: кнопка ☰ подписана словом «Меню», у меню есть заголовок (DIK-33)", async () => {
|
||
const { renderPage } = await import("../src/page.js");
|
||
const ru = JSON.parse(fs.readFileSync("public/i18n/ru.json", "utf8"));
|
||
const html = renderPage(fs.readFileSync("public/index.html", "utf8"), ru);
|
||
assert.match(html, /<button id="burger"[^>]*>.*<span data-i="menuLabel">Меню<\/span><\/button>/);
|
||
assert.match(html, /<nav id="menu"[^>]*>\s*<h2 data-i="menuLabel">Меню<\/h2>/);
|
||
});
|
||
|
||
test("Сценарий: подсказки у расстояния и переключателя не отсылают к району (DIK-57)", () => {
|
||
const bad = { ru: /район/i, kk: /аудан/i, en: /district/i };
|
||
for (const l of ["ru", "kk", "en"]) {
|
||
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
|
||
for (const k of ["distNeedPlace", "filterNeedPlace"]) assert.doesNotMatch(d[k], bad[l], `${l}.${k}`);
|
||
}
|
||
});
|