what-to-cook/test/dish-list.test.js
Peppa 8febcd2955
All checks were successful
peppa/lint lint: success за 0с
peppa/test test: success за 0с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 4s
deploy / deploy (pull_request) Successful in 13s
WTC-19: фраза про кнопку «Рецепт» видна только рядом с кнопкой
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
2026-11-16 06:18:58 +05:00

57 lines
3.2 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 { readFileSync } from "node:fs";
import { messages } from "../src/i18n.js";
import { removeDish, parseState, hasRecipe } from "../src/logic.js";
import { findRecipe } from "../src/recipes.js";
const read = (f) => readFileSync(new URL(`../src/${f}`, import.meta.url), "utf8");
test("Сценарий: список и кнопки удаления — кнопка не ниже 48 px", () => {
assert.match(read("style.css"), /li button \{[^}]*min-height: 48px/);
assert.match(read("app.js"), /aria-label/);
});
test("Сценарий: удаление последнего блюда — подсказка пустого списка на всех языках", () => {
for (const l of ["ru", "kk", "en"]) assert.ok(messages[l].listEmpty.length > 10);
assert.match(messages.ru.listEmpty, /Добавьте первое блюдо/);
assert.match(read("index.html"), /id="empty"/);
assert.deepEqual(removeDish(["Борщ"], "Борщ"), []);
});
test("Сценарий: список после перезагрузки", () => {
const saved = JSON.stringify({ dishes: removeDish(["Борщ", "Плов"], "Борщ"), last: null });
assert.deepEqual(parseState(saved).dishes, ["Плов"]);
});
test("Сценарий: список пуст — подсказка под заголовком, не дублирует подсказку под кнопкой", () => {
const html = read("index.html");
assert.ok(html.indexOf('id="listTitle"') < html.indexOf('id="empty"'));
for (const l of ["ru", "kk", "en"]) assert.notEqual(messages[l].listEmpty, messages[l].emptyHint);
});
test("Сценарий: добавлено первое блюдо — подсказка скрывается", () => {
assert.match(read("app.js"), /\$\("empty"\)\.hidden = n !== 0/);
});
// WTC-19: фраза про кнопку «Рецепт» видна только рядом с кнопкой
test("Сценарий: Пустой список — фразы нет", () => {
assert.equal(hasRecipe([], findRecipe), false);
const app = read("app.js");
assert.match(app, /\$\("recipesHint"\)\.hidden = !hasRecipe\(state\.dishes, findRecipe\)/);
assert.doesNotMatch(app, /emptyRecipes/);
assert.doesNotMatch(messages.ru.listEmpty, /[Рр]ецепт/);
assert.doesNotMatch(messages.ru.emptyHint, /[Рр]ецепт/);
});
test("Сценарий: В списке блюдо из базы", () => {
assert.equal(hasRecipe(["Мамин пирог", "Бешбармак"], findRecipe), true);
for (const l of ["ru", "kk", "en"]) assert.ok(messages[l].listRecipes.length > 20);
assert.match(messages.ru.listRecipes, /кнопкой «Рецепт»/);
});
test("Сценарий: Кнопка открывает рецепт", () => {
const r = findRecipe("Бешбармак");
assert.equal(r.name, "Бешбармак");
assert.ok(r.ingredients.length >= 2 && r.steps.length >= 2);
assert.match(read("app.js"), /r\.addEventListener\("click", \(\) => openRecipe\(d, r\)\)/);
});
test("Сценарий: В списке только своё блюдо", () => {
assert.equal(hasRecipe(["Мамин пирог"], findRecipe), false);
});