what-to-cook/test/no-unnamed-controls.test.js

38 lines
2.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";
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("Сценарий: Пустой экран — скрытые кнопки убираются со страницы", () => {
assert.match(app, /for \(const id of \["recipeToday", "easier", "harder", "back"\]\)/);
assert.match(app, /conditional\[id\]\.replaceWith\(anchors\[id\]\)/);
assert.match(app, /else if \(!on\) conditional\[id\]\.remove\(\)/);
assert.match(app, /mount\("easier", n !== 0\)/);
assert.match(app, /mount\("harder", n !== 0\)/);
});
test("Сценарий: Поле ввода с подписью — подпись связана двумя способами", () => {
assert.match(html, /<label id="nameLabel" for="name">Название блюда<\/label>/);
assert.match(html, /<input id="name"[^>]*aria-labelledby="nameLabel"/);
});
test("Сценарий: Блюдо выбрано — кнопка «Рецепт» появляется вместе с текстом", () => {
assert.match(app, /\$\("recipeToday"\)\.textContent = !\$\("recipeToday"\)\.hidden \? t\.recipe : ""/);
assert.match(app, /mount\("recipeToday", !\$\("recipeToday"\)\.hidden\)/);
});
test("Сценарий: Открыт рецепт и возврат назад — «Назад» есть только в рецепте", () => {
const open = app.slice(app.indexOf("function openRecipe"), app.indexOf('$("back").addEventListener'));
assert.match(open, /mount\("back", true\)/);
const back = app.slice(app.indexOf('$("back").addEventListener'), app.indexOf('$("recipeToday").addEventListener'));
assert.match(back, /mount\("back", false\)/);
});
test("Сценарий: списки названы по своим заголовкам", () => {
assert.match(html, /<ul id="list" aria-labelledby="listTitle">/);
assert.match(html, /<ul id="ingredients"[^>]*aria-labelledby="ingTitle"/);
assert.match(html, /<ol id="steps" aria-labelledby="stepsTitle">/);
});