diff --git a/.peppa/memory.md b/.peppa/memory.md index 8efe7b0..765da48 100644 --- a/.peppa/memory.md +++ b/.peppa/memory.md @@ -16,6 +16,7 @@ - WTC-19: фраза про кнопку «Рецепт» — абзац #recipesHint (i18n listRecipes), видна только когда hasRecipe(dishes, findRecipe) из logic.js, т.е. в списке есть блюдо с кнопкой; на пустом экране её нет (требование WTC-14 снято). - WTC-20: пока в списке нет блюда с кнопкой «Рецепт», виден блок #recipeExample (подсказка + кнопка #addExample «Добавить «…»», пример = recipeExample() в logic.js); иначе — фраза #recipesHint (WTC-19). Подпись #noRecipeHint под списком — при блюде без рецепта (hasNoRecipe). - WTC-24: подсказка под кнопкой «Что приготовить?» — i18n pickHint (в app.js #hint: пусто→emptyHint, одно блюдо после выбора→oneHint, иначе pickHint); остальные критерии были готовы с WTC-5..8. +- WTC-26: #noRecipeHint виден на пустом экране (n===0) или при блюде без рецепта; вместе с #recipeExample объясняет оба случая. sed на macOS с | и & падает — правь через Edit. ## Соглашения - Цвета кнопки: доступная #b4500c, недоступная #e8dccb/#5c4a35 (контраст ≥4.5:1, проверяется тестом); opacity для disabled не используем. diff --git a/src/app.js b/src/app.js index bc9b5e5..d93f5d9 100644 --- a/src/app.js +++ b/src/app.js @@ -53,7 +53,7 @@ function render() { $("addExample").textContent = example === null ? "" : t.addExample.replace("{name}", example); $("addExample").dataset.name = example ?? ""; $("noRecipeHint").textContent = t.noRecipeHint; - $("noRecipeHint").hidden = !hasNoRecipe(state.dishes, findRecipe); + $("noRecipeHint").hidden = n !== 0 && !hasNoRecipe(state.dishes, findRecipe); const ul = $("list"); ul.replaceChildren(...state.dishes.map((d) => { const li = document.createElement("li"); diff --git a/test/empty-recipe-hint.test.js b/test/empty-recipe-hint.test.js new file mode 100644 index 0000000..76d6303 --- /dev/null +++ b/test/empty-recipe-hint.test.js @@ -0,0 +1,13 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { messages } from "../src/i18n.js"; + +// WTC-26: на пустом экране объяснено и про кнопку «Рецепт», и про «Рецепта нет» +test("Сценарий: Пустой экран объясняет оба случая", () => { + const app = readFileSync(new URL("../src/app.js", import.meta.url), "utf8"); + assert.match(app, /\$\("noRecipeHint"\)\.hidden = n !== 0 && !hasNoRecipe\(/); + assert.match(messages.ru.recipeExampleHint, /кнопка «Рецепт»/); + assert.match(messages.ru.noRecipeHint, /«Рецепта нет»/); + for (const l of ["ru", "kk", "en"]) assert.ok(messages[l].noRecipeHint.length > 20, l); +}); diff --git a/test/recipe-example.test.js b/test/recipe-example.test.js index 494f186..c60ec5d 100644 --- a/test/recipe-example.test.js +++ b/test/recipe-example.test.js @@ -53,7 +53,7 @@ test("Сценарий: Своё блюдо в списке", () => { assert.equal(findRecipe("Мамин пирог"), null); assert.match(messages.ru.noRecipeHint, /«Рецепта нет»/); assert.ok(messages.ru.noRecipeHint.includes(messages.ru.noRecipe)); - assert.match(read("app.js"), /\$\("noRecipeHint"\)\.hidden = !hasNoRecipe\(state\.dishes, findRecipe\)/); + assert.match(read("app.js"), /\$\("noRecipeHint"\)\.hidden = n !== 0 && !hasNoRecipe\(state\.dishes, findRecipe\)/); const html = read("index.html"); assert.ok(html.indexOf('id="list"') < html.indexOf('id="noRecipeHint"')); });