WTC-29: подсказка под полем про блюда из базы

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Peppa 2026-11-16 06:32:11 +05:00
parent 480cd45ae1
commit 064b17a26e
4 changed files with 26 additions and 0 deletions

View File

@ -50,6 +50,7 @@ function render() {
const examples = hasRecipe(state.dishes, findRecipe) ? [] : recipeExamples(state.dishes, catalog, findRecipe);
$("recipeExample").hidden = examples.length === 0;
$("recipeExampleHint").textContent = t.recipeExampleHint;
$("suggestHint").textContent = t.suggestHint;
$("examplesNote").textContent = t.examplesNote;
$("examples").replaceChildren(...examples.map((name) => {
const b = document.createElement("button");

View File

@ -23,6 +23,7 @@ export const messages = {
today: "Сегодня готовим:",
recipe: "Рецепт",
noRecipe: "Рецепта нет",
suggestHint: "Начните вводить — предложим блюда из базы казахской кухни.",
fromCatalog: "Из базы",
recipeLabel: "Рецепт блюда «{name}»",
back: "Назад",
@ -61,6 +62,7 @@ export const messages = {
today: "Бүгін дайындаймыз:",
recipe: "Рецепт",
noRecipe: "Рецепт жоқ",
suggestHint: "Жаза бастаңыз — қазақ тағамдары қорынан тағамдар ұсынамыз.",
fromCatalog: "Қордан",
recipeLabel: "«{name}» тағамының рецепті",
back: "Артқа",
@ -99,6 +101,7 @@ export const messages = {
today: "Today you cook:",
recipe: "Recipe",
noRecipe: "No recipe",
suggestHint: "Start typing — we will suggest dishes from the Kazakh cuisine base.",
fromCatalog: "From the base",
recipeLabel: "Recipe for “{name}”",
back: "Back",

View File

@ -17,6 +17,7 @@
<input id="name" type="text" maxlength="80" autocomplete="off" aria-describedby="nameError">
<button id="add" type="submit"></button>
</div>
<p id="suggestHint" class="hint"></p>
<ul id="suggest" class="suggest" aria-labelledby="nameLabel" hidden></ul>
<p id="nameError" class="error" role="alert" hidden></p>
</form>

21
test/suggest-hint.test.js Normal file
View File

@ -0,0 +1,21 @@
import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { messages } from "../src/i18n.js";
import { suggest, inCatalog } from "../src/logic.js";
import { catalog } from "../src/catalog.js";
test("Сценарий: подсказка под полем на трёх языках", () => {
for (const l of ["ru", "kk", "en"]) assert.ok(messages[l].suggestHint);
assert.match(messages.ru.suggestHint, /Начните вводить/);
assert.match(readFileSync("src/index.html", "utf8"), /id="suggestHint"/);
assert.match(readFileSync("src/app.js", "utf8"), /suggestHint/);
});
test("Сценарий: при вводе названия из базы виден список", () => {
const r = suggest("беш", catalog, []);
assert.ok(r.length > 0);
});
test("Сценарий: пометка только у блюда из базы", () => {
assert.equal(inCatalog("бешбармак", catalog), true);
assert.equal(inCatalog("Мамин пирог", catalog), false);
});