dika/test/card-offer.test.js
peppa-bot 4df6699534
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 10s
deploy / deploy (pull_request) Successful in 33s
DIK-66: источник описания и фото на карточке, «Фото пока нет» у заглушки
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-27 12:15:59 +00:00

55 lines
3.5 KiB
JavaScript
Raw Permalink 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-73): сценарии openspec/specs/venue-card-offer
import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import { offerLines } from "../public/card-offer.js";
const dict = (l) => JSON.parse(fs.readFileSync(`public/i18n/${l}.json`, "utf8"));
const ru = dict("ru");
const app = fs.readFileSync("public/app.js", "utf8");
const html = fs.readFileSync("public/index.html", "utf8");
const css = html.slice(html.indexOf("<style>"), html.indexOf("</style>"));
const date = (iso) => iso.split("-").reverse().join(".");
test("Сценарий: Карточка с ценой ланча и акцией — обе плашки, сначала цена", () => {
const v = { lunch: { price: 2500, from: "12:00", to: "15:00" }, promo: { text: "Кофе в подарок", until: "2026-12-01" } };
assert.deepEqual(offerLines(v, ru, { date }), [
{ kind: "lunch", on: true, text: "Бизнес-ланч 2500 ₸, 12:00–15:00" },
{ kind: "promo", on: true, text: "Акция: Кофе в подарок (до 01.12.2026)" },
]);
});
test("Сценарий: Цены и акции нет — написано словами, пустых мест нет", () => {
const cases = [
[{ lunch: null, promo: null, promoState: "none" }, ["Цена не подтверждена", "Акции сейчас нет"]],
[{ lunch: null, lunchHours: { from: "12:00", to: "15:00" }, promo: null, promoState: "ended" }, ["Бизнес-ланч в другое время: 12:00–15:00", "Акция закончилась"]],
];
for (const [v, want] of cases) {
const lines = offerLines(v, ru, { date });
assert.deepEqual(lines.map((o) => o.text), want);
assert.ok(lines.every((o) => !o.on));
}
});
test("Сценарий: Строки цены и акции на трёх языках — без пустых и undefined", () => {
const vs = [{}, { promoState: "ended" }, { lunchHours: { from: "12:00", to: "15:00" } }, { lunch: { price: 1, from: "a", to: "b" }, promo: { text: "x" } }];
for (const l of ["ru", "kk", "en"]) for (const v of vs) for (const o of offerLines(v, dict(l), { date })) {
assert.ok(o.text && o.text.trim(), `${l}: пустая строка`);
assert.doesNotMatch(o.text, /undefined|null|\{/, `${l}: ${o.text}`);
}
});
test("Сценарий: Карточка на телефоне и компьютере — пять элементов по порядку, без раскрытия", () => {
const i = (s) => { const n = app.indexOf(s); assert.ok(n > 0, s); return n; };
// фото сверху, затем название, описание, блок цены и акции; источники — ниже предложений
assert.ok(i("c.append(photo(v), body)") > 0);
assert.ok(i("h.textContent = v.name") < i("desc.textContent") && i("desc.textContent") < i('offers.className = "offers"'));
assert.ok(i('offers.className = "offers"') < i("srcNode(t.srcDescLabel, v.description"));
// описание — до 2 строк, ничего не прячется за «Подробнее» и не скрывается на узком экране
assert.match(css, /\.desc\{[^}]*-webkit-line-clamp:2/);
assert.doesNotMatch(app, /<details|\.offers[^\n]*hidden/);
const media = css.slice(css.indexOf("@media"));
assert.doesNotMatch(media, /\.(offers|badge|desc|photo|offer-none)[^{]*\{[^}]*display:none/);
assert.match(css, /\.offers\{[^}]*display:flex;flex-direction:column/);
});