what-to-cook/test/show-dish.test.js
Peppa fe87a2d9a1
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 3s
deploy / deploy (pull_request) Successful in 12s
WTC-6: требование и тесты показа выпавшего блюда
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 05:56:04 +05:00

22 lines
1.1 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 { 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, "Борщ"); }
});