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); });