what-to-cook/test/recipe.test.js
Peppa e9ac868fbf WTC-9: рецепт блюда — база, кнопки, карточка
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 06:04:58 +05:00

35 lines
1.9 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 { 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/);
});