WTC-46: названия у безымянных кнопок и подпись поля #46

Merged
peppa-bot merged 1 commits from task/wtc-46 into main 2026-11-16 06:55:27 +05:00
9 changed files with 75 additions and 5 deletions

View File

@ -54,3 +54,4 @@
- WTC-43: пометка «Рецепта нет» у своего блюда уже была (WTC-33/40); «Борщ» из примера стори есть в базе с рецептом — для своего блюда брать другое имя; добавлен test/own-dish-note.test.js.
- WTC-44: кнопки на пустом экране уже скрыты (WTC-39/42: tune, recipeToday, back); добавлен только тест в test/empty-screen.test.js. Приёмочные стори снова описали готовое.
- WTC-45: результат «Полегче/Посложнее» уже сделан в WTC-39/41 (tuneDone, noEasier, tuneOne, скрытие на пустом экране); добавлен только test/tune-acceptance.test.js.
- WTC-46: безымянные кнопки (Рецепт/Полегче/Посложнее/Назад) названы статическим aria-label в index.html; текст ставит app.js; test/accessible-names.test.js.

View File

@ -0,0 +1,2 @@
## Решение
aria-label в разметке, текст кнопок по-прежнему ставит app.js (WTC-42 не нарушен). Тест test/accessible-names.test.js.

View File

@ -0,0 +1,6 @@
## Why
Четыре кнопки («Рецепт», «Полегче», «Посложнее», «Назад») в тексте страницы без названия; программа чтения экрана их не озвучит.
## What Changes
- Статический aria-label у этих кнопок в index.html; у «Рецепт» название сохраняется и без блюда.
- Поле ввода уже связано с подписью «Название блюда»; кнопки примеров названы «Добавить «…»».

View File

@ -0,0 +1,14 @@
## ADDED Requirements
### Requirement: У кнопок и поля есть название
Каждая кнопка и поле ввода SHALL иметь название для программы чтения экрана.
#### Scenario: Кнопки без текста
- **GIVEN** страница открыта, список блюд пуст
- **WHEN** программа чтения экрана читает кнопки «Рецепт», «Полегче», «Посложнее», «Назад»
- **THEN** у каждой есть название
#### Scenario: Поле ввода
- **GIVEN** страница открыта
- **WHEN** фокус на поле ввода
- **THEN** озвучивается подпись «Название блюда»

View File

@ -0,0 +1,3 @@
## 1. Реализация
- [x] 1.1 aria-label у четырёх кнопок в index.html
- [x] 1.2 Тест test/accessible-names.test.js

View File

@ -0,0 +1,19 @@
# accessibility Specification
## Purpose
TBD - created by archiving change wtc-46-accessible-names. Update Purpose after archive.
## Requirements
### Requirement: У кнопок и поля есть название
Каждая кнопка и поле ввода SHALL иметь название для программы чтения экрана.
#### Scenario: Кнопки без текста
- **GIVEN** страница открыта, список блюд пуст
- **WHEN** программа чтения экрана читает кнопки «Рецепт», «Полегче», «Посложнее», «Назад»
- **THEN** у каждой есть название
#### Scenario: Поле ввода
- **GIVEN** страница открыта
- **WHEN** фокус на поле ввода
- **THEN** озвучивается подпись «Название блюда»

View File

@ -38,7 +38,7 @@ function render() {
$("noRecipeToday").hidden = !(show && !findRecipe(state.last));
$("noRecipeToday").textContent = t.noRecipe;
$("recipeToday").textContent = !$("recipeToday").hidden ? t.recipe : "";
$("recipeToday").setAttribute("aria-label", show ? t.recipeLabel.replace("{name}", state.last) : "");
$("recipeToday").setAttribute("aria-label", show ? t.recipeLabel.replace("{name}", state.last) : t.recipe);
const lvl = state.last ? difficultyOf(state.last) : null;
$("level").hidden = lvl === null;
$("level").textContent = lvl === null ? "" : t.difficulty.replace("{level}", t[LEVEL_KEYS[lvl]]);

View File

@ -25,12 +25,12 @@
<section class="result" aria-live="polite">
<p id="today" class="today" hidden></p>
<p id="dish" class="dish" hidden></p>
<button id="recipeToday" type="button" class="recipe-btn" hidden></button>
<button id="recipeToday" type="button" class="recipe-btn" aria-label="Рецепт" hidden></button>
<p id="noRecipeToday" class="no-recipe" hidden></p>
<p id="level" class="level" hidden></p>
<div id="tune" class="tune">
<button id="easier" type="button"></button>
<button id="harder" type="button"></button>
<button id="easier" type="button" aria-label="Полегче"></button>
<button id="harder" type="button" aria-label="Посложнее"></button>
</div>
<p id="tuneInfo" class="hint"></p>
<p id="tuneResult" class="hint" role="status" hidden></p>
@ -53,7 +53,7 @@
</section>
</div>
<article id="recipe" class="recipe" hidden tabindex="-1">
<button id="back" type="button"></button>
<button id="back" type="button" aria-label="Назад"></button>
<h1 id="recipeTitle"></h1>
<h2 id="ingTitle"></h2>
<ul id="ingredients" class="plain"></ul>

View File

@ -0,0 +1,25 @@
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 \? [^:]+: ""\)/);
});