what-to-cook/test/back-button.test.js
Peppa 13e81adb0a
All checks were successful
peppa/lint lint: success за 1с
peppa/test test: success за 0с
peppa/build build: success за 0с
ci / checks (pull_request) Successful in 4s
deploy / deploy (pull_request) Successful in 13s
WTC-38: тест — «Назад» только в карточке рецепта, возврат к месту открытия
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 06:43:15 +05:00

21 lines
1.0 KiB
JavaScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
const html = readFileSync(new URL("../src/index.html", import.meta.url), "utf8");
const app = readFileSync(new URL("../src/app.js", import.meta.url), "utf8");
test("Сценарий: на главном экране «Назад» не появляется, пока рецепт не открыт", () => {
const recipe = html.slice(html.indexOf('<article id="recipe"'));
assert.match(html, /<article id="recipe"[^>]*hidden/);
assert.ok(recipe.includes('id="back"'));
assert.ok(!html.slice(0, html.indexOf('<article id="recipe"')).includes('id="back"'));
assert.ok(html.includes('>Назад<'));
});
test("Сценарий: «Назад» возвращает к кнопке, откуда открыт рецепт (список или выдача)", () => {
assert.match(app, /openRecipe\(d, r\)/);
assert.match(app, /openRecipe\(state\.last, \$\("recipeToday"\)\)/);
assert.match(app, /opener\.focus\(\)/);
});