what-to-cook/test/example-added.test.js
2026-11-16 06:41:00 +05:00

39 lines
1.8 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { exampleStates, addDish, removeDish } from "../src/logic.js";
import { catalog } from "../src/catalog.js";
import { findRecipe } from "../src/recipes.js";
import { messages } from "../src/i18n.js";
// WTC-32
test("Сценарий: Добавленный пример помечен, остальные доступны", () => {
const all = exampleStates([], catalog, findRecipe);
assert.equal(all.length, 4);
assert.ok(all.every((x) => !x.added));
const st = exampleStates(addDish([], all[1].name), catalog, findRecipe);
assert.deepEqual(st.map((x) => x.added), [false, true, false, false]);
assert.deepEqual(st.map((x) => x.name), all.map((x) => x.name));
});
test("Сценарий: Добавлены все четыре — короткий текст", () => {
let d = [];
for (const x of exampleStates([], catalog, findRecipe)) d = addDish(d, x.name);
assert.ok(exampleStates(d, catalog, findRecipe).every((x) => x.added));
for (const l of ["ru", "kk", "en"]) {
assert.ok(messages[l].examplesAllAdded.length > 10, l);
assert.match(messages[l].exampleAdded, /\{name\}/, l);
}
const app = readFileSync(new URL("../src/app.js", import.meta.url), "utf8");
assert.match(app, /b\.disabled = added/);
});
// WTC-36
test("Сценарий: Удалённый пример снова доступен для добавления", () => {
const first = exampleStates([], catalog, findRecipe)[0].name;
const d = addDish([], first);
assert.equal(exampleStates(d, catalog, findRecipe)[0].added, true);
const after = exampleStates(removeDish(d, first), catalog, findRecipe);
assert.equal(after[0].added, false);
assert.equal(after.length, 4);
});