what-to-cook/test/show-dish.test.js
2026-11-16 05:56:04 +05:00

22 lines
1.1 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 { pickDish } from "../src/logic.js";
const read = (f) => readFileSync(new URL(`../src/${f}`, import.meta.url), "utf8");
test("Сценарий: блюдо показано — крупно, рядом с кнопкой", () => {
const html = read("index.html");
assert.ok(html.indexOf('id="dish"') < html.indexOf('id="pick"'));
assert.match(read("style.css"), /\.dish \{[^}]*font-size: 2rem/);
assert.match(read("app.js"), /\$\("dish"\)\.textContent = state\.last/);
assert.ok(["Борщ", "Плов", "Манты"].includes(pickDish(["Борщ", "Плов", "Манты"], null)));
});
test("Сценарий: повторное нажатие — другое блюдо", () => {
for (const r of [0, 0.5, 0.99]) assert.equal(pickDish(["Борщ", "Плов"], "Борщ", () => r), "Плов");
});
test("Сценарий: одно блюдо — каждый раз оно же", () => {
let last = null;
for (let i = 0; i < 5; i++) { last = pickDish(["Борщ"], last); assert.equal(last, "Борщ"); }
});