138 lines
7.8 KiB
JavaScript
138 lines
7.8 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, /note = "noneNearby"; everywhere = true;/);
|
||
assert.match(app, /t\.resultsNoPlace|resultsNoPlace/);
|
||
assert.doesNotMatch(app, /district|coverage/i);
|
||
});
|
||
|
||
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.doesNotMatch(html, /district|coverage/);
|
||
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", "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 ["ru", "kk", "en"]) {
|
||
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
|
||
assert.deepEqual(Object.keys(d).filter((k) => /district|coverage/i.test(k)), [], l);
|
||
assert.doesNotMatch(JSON.stringify(d), /[Рр]айон|Аудан|аудан|[Dd]istrict|Есиль|Есіл|Esil/, l);
|
||
if (l !== "ru") assert.ok(Object.keys(d.promoTexts).length >= 3, l);
|
||
}
|
||
});
|
||
|
||
test("Сценарий: пока заведений нет — вместо пустого экрана сообщение «список готовится»", () => {
|
||
assert.match(app, /"listPreparing"/);
|
||
for (const l of ["ru", "kk", "en"]) assert.ok(JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8")).listPreparing, l);
|
||
});
|
||
|
||
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", "manualHint", "resultsNoPlace"]) {
|
||
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\.resultsOffers/);
|
||
for (const l of ["ru", "kk", "en"]) {
|
||
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
|
||
for (const k of ["resultsAll", "resultsOffers", "resultsNoPlace", "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, /load\(\); \/\/ список и сообщение/);
|
||
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-26)", () => {
|
||
const base = fs.readFileSync("public/base-view.js", "utf8"); // строки «Все заведения» (DIK-49)
|
||
for (const k of ["notConfirmed", "lunchLater", "promoNone", "promoEnded"]) assert.match(app, new RegExp(`t\\.${k}\\b`), k);
|
||
for (const k of ["basePromoEnded", "baseNotChecked", "baseNoSource"]) assert.match(base, new RegExp(`t\\.${k}\\b`), k);
|
||
// подстановка не выводит undefined/null
|
||
for (const src of [app, base]) assert.match(src, /o\[k\] \?\? ""/);
|
||
for (const l of ["ru", "kk", "en"]) {
|
||
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
|
||
for (const k of ["notConfirmed", "lunchLater", "promoNone", "promoEnded", "basePromoEnded", "baseNotChecked", "baseNoSource"]) {
|
||
assert.ok(d[k], `${l}.${k}`);
|
||
assert.doesNotMatch(d[k], /null|undefined/i, `${l}.${k}`);
|
||
}
|
||
}
|
||
});
|
||
|
||
test("Сценарий: главная без районов, подсказка про адрес, пустой список подсказывает шаг (DIK-62)", () => {
|
||
const html = fs.readFileSync("public/index.html", "utf8");
|
||
assert.match(html, /data-i="manualHint"/);
|
||
assert.match(html, /<input type="text" id="addr"/);
|
||
for (const l of ["ru", "kk", "en"]) {
|
||
const d = JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
|
||
assert.doesNotMatch(d.manualHint, /[Рр]айон|Аудан|аудан|[Dd]istrict|Есиль|Есіл|Алматы/, l);
|
||
assert.ok(d.listPreparing.length > 30, `${l}.listPreparing`);
|
||
}
|
||
assert.match(app, /msg\("listPreparing"\)/);
|
||
});
|