what-to-cook/test/recipe.test.js
Peppa beb641e743
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 12s
WTC-34: заметная кнопка «Назад» в карточке рецепта
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 06:38:31 +05:00

53 lines
3.0 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.

import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { findRecipe, recipes } from "../src/recipes.js";
import { messages } from "../src/i18n.js";
const read = (f) => readFileSync(new URL(`../src/${f}`, import.meta.url), "utf8");
test("Сценарий: у каждого блюда базы есть ингредиенты с количеством и шаги", () => {
assert.ok(Object.keys(recipes).length >= 5);
for (const [n, r] of Object.entries(recipes)) {
assert.ok(r.ingredients.length >= 2 && r.steps.length >= 2, n);
for (const i of r.ingredients) assert.match(i, /\d|по вкусу|щепотка|пучок/, n);
for (const x of [...r.ingredients, ...r.steps]) assert.match(x, /[а-яё]/i);
}
});
test("Сценарий: рецепт из списка и выдачи — поиск без учёта регистра", () => {
assert.equal(findRecipe(" плов ").name, "Плов");
assert.equal(findRecipe("БОРЩ").name, "Борщ");
});
test("Сценарий: своё блюдо — рецепта нет", () => {
assert.equal(findRecipe("Мамин пирог"), null);
assert.equal(findRecipe(""), null);
assert.match(read("app.js"), /t\.noRecipe/);
});
test("Сценарий: возврат и тексты на трёх языках", () => {
const html = read("index.html");
for (const id of ["recipeToday", "recipe", "back", "steps", "ingredients"]) assert.ok(html.includes(`id="${id}"`));
assert.match(read("app.js"), /\$\("home"\)\.hidden = false/);
for (const l of ["ru", "kk", "en"]) for (const k of ["recipe", "noRecipe", "recipeLabel", "back", "ingredients", "steps"]) assert.ok(messages[l][k], `${l}.${k}`);
});
test("Сценарий: читается на телефоне", () => {
assert.match(read("style.css"), /\.recipe \{[^}]*font-size: 1\.1rem[^}]*overflow-wrap/);
});
test("Сценарий: у каждого блюда общей базы есть рецепт", async () => {
const { catalog } = await import("../src/catalog.js");
for (const d of catalog) assert.ok(findRecipe(d), d);
});
test("Сценарий: Назад сохраняет список и выдачу (карточка только прячет секции)", () => {
const app = read("app.js");
const back = app.slice(app.indexOf('$("back").addEventListener'), app.indexOf('$("recipeToday").addEventListener'));
assert.match(back, /\$\("recipe"\)\.hidden = true/);
assert.doesNotMatch(back, /state\./);
});
test("Сценарий: кнопка «Назад» в карточке заметная — вверху, на всю ширину, контрастная", async () => {
const { readFileSync } = await import("node:fs");
const css = readFileSync(new URL("../src/style.css", import.meta.url), "utf8");
const html = readFileSync(new URL("../src/index.html", import.meta.url), "utf8");
assert.match(css, /#back \{[^}]*width: 100%[^}]*background: #b4500c[^}]*color: #fff/);
assert.ok(html.indexOf('id="back"') < html.indexOf('id="recipeTitle"'));
});