what-to-cook/test/accessible-names.test.js
Peppa 2aa92f693a
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 4s
deploy / deploy (pull_request) Successful in 12s
WTC-46: названия у безымянных кнопок
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-16 06:55:02 +05:00

26 lines
1.3 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";
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("Сценарий: у каждой кнопки в разметке есть название (текст или aria-label)", () => {
for (const [, attrs, text] of html.matchAll(/<button\b([^>]*)>([^<]*)<\/button>/g)) {
assert.ok(text.trim() || /aria-label="[^"]+"/.test(attrs), attrs);
}
});
test("Сценарий: поле ввода связано с подписью «Название блюда»", () => {
assert.match(html, /<label id="nameLabel" for="name">Название блюда<\/label>/);
assert.match(html, /<input id="name"/);
});
test("Сценарий: кнопки примеров получают название «Добавить «…»»", () => {
assert.match(app, /b\.textContent = added \? .*t\.addExample\.replace\("\{name\}", name\)/);
});
test("Сценарий: aria-label «Рецепт» не пустеет, когда блюда нет", () => {
assert.doesNotMatch(app, /\$\("recipeToday"\)\.setAttribute\("aria-label", show \? [^:]+: ""\)/);
});