TPTIP-17: подсказка на пустом главном экране #13
@ -673,6 +673,7 @@ function viewToday() {
|
||||
h('div', { class: 'row', style: 'justify-content:center;margin-top:10px' },
|
||||
t.water > 0 ? h('button', { class: 'chip minus', 'aria-label': 'Убрать 250 мл воды', onclick: removeLastWater }, '−250') : null,
|
||||
h('button', { class: 'chip on', onclick: () => addWater(250) }, '+250 мл воды')),
|
||||
t.meals === 0 && t.water === 0 ? h('p', { class: 'small muted', 'data-empty-hint': '', style: 'text-align:center;margin:8px 0 0' }, 'Пока ничего не добавлено, поэтому кольца пустые. Нажмите «+ Еда», «+250 мл воды» или выберите блюдо ниже — кольца заполнятся сами.') : null,
|
||||
h('p', { class: 'left ' + (left >= 0 ? 'ok' : 'bad') }, leftText)),
|
||||
h('div', { class: 'quick two' },
|
||||
h('button', { onclick: () => openMealForm({ date: ui.date }) }, '+ Еда'),
|
||||
@ -907,6 +908,7 @@ function recipesCard() {
|
||||
function suggestionBlock() {
|
||||
const r = suggestedRecipe(ui.date);
|
||||
return h('div', null, h('div', { class: 'muted small', style: 'margin:6px 0' }, 'Идея на этот день'),
|
||||
h('div', { class: 'small muted', 'data-choose-hint': '', style: 'margin-bottom:6px' }, 'Кнопка «Выбрать» добавит блюдо в приём пищи и в кольца за этот день.'),
|
||||
recipeView(r, h('button', { class: 'primary', onclick: () => chooseRecipe(r) }, 'Выбрать')));
|
||||
}
|
||||
/** Выбор рецепта на выбранный день или создание нового. */
|
||||
|
||||
@ -0,0 +1 @@
|
||||
Подсказка — обычный абзац в viewToday, виден при t.meals === 0 и t.water === 0. Тексты на русском, как весь интерфейс приложения.
|
||||
@ -0,0 +1,6 @@
|
||||
## Why
|
||||
У нового пользователя за мастером кольца показывают нули без пояснений.
|
||||
|
||||
## What Changes
|
||||
- Под кольцами на пустом дне — подсказка, что ничего не добавлено и как добавить.
|
||||
- У идеи блюда — пояснение, что «Выбрать» добавляет блюдо в приём пищи и в кольца.
|
||||
@ -0,0 +1,14 @@
|
||||
## ADDED Requirements
|
||||
### Requirement: Подсказка на пустом дне
|
||||
Главный экран SHALL показывать подсказку рядом с кольцами, пока за день нет еды и воды.
|
||||
|
||||
#### Scenario: Новый пользователь
|
||||
- **GIVEN** день без приёмов пищи и воды
|
||||
- **WHEN** пользователь открывает главный экран
|
||||
- **THEN** под кольцами написано, что пока ничего не добавлено и как добавить
|
||||
- **AND** у блюда сказано, что «Выбрать» добавляет его в приём пищи и в кольца
|
||||
|
||||
#### Scenario: После выбора блюда
|
||||
- **GIVEN** пустой день с подсказкой
|
||||
- **WHEN** пользователь нажимает «Выбрать»
|
||||
- **THEN** подсказка пропадает
|
||||
@ -0,0 +1,3 @@
|
||||
- [x] Подсказка под кольцами на пустом дне
|
||||
- [x] Пояснение про «Выбрать» у идеи блюда
|
||||
- [x] Тест сценария
|
||||
20
openspec/specs/home-empty-state/spec.md
Normal file
20
openspec/specs/home-empty-state/spec.md
Normal file
@ -0,0 +1,20 @@
|
||||
# home-empty-state Specification
|
||||
|
||||
## Purpose
|
||||
TBD - created by archiving change tptip-17-empty-home-hint. Update Purpose after archive.
|
||||
|
||||
## Requirements
|
||||
|
||||
### Requirement: Подсказка на пустом дне
|
||||
Главный экран SHALL показывать подсказку рядом с кольцами, пока за день нет еды и воды.
|
||||
|
||||
#### Scenario: Новый пользователь
|
||||
- **GIVEN** день без приёмов пищи и воды
|
||||
- **WHEN** пользователь открывает главный экран
|
||||
- **THEN** под кольцами написано, что пока ничего не добавлено и как добавить
|
||||
- **AND** у блюда сказано, что «Выбрать» добавляет его в приём пищи и в кольца
|
||||
|
||||
#### Scenario: После выбора блюда
|
||||
- **GIVEN** пустой день с подсказкой
|
||||
- **WHEN** пользователь нажимает «Выбрать»
|
||||
- **THEN** подсказка пропадает
|
||||
@ -82,3 +82,13 @@ test('Сценарий: рецепт читается на телефоне —
|
||||
assert.match(css, /overflow-wrap:anywhere/);
|
||||
assert.doesNotMatch(source, /text-overflow:\s*ellipsis/);
|
||||
});
|
||||
|
||||
test('Сценарий: на пустом дне рядом с кольцами есть подсказка, после «Выбрать» она исчезает', t => {
|
||||
const { dom, document } = open(); t.after(() => dom.window.close());
|
||||
const hint = document.querySelector('[data-empty-hint]');
|
||||
assert.ok(hint, 'нет подсказки');
|
||||
assert.match(hint.textContent, /Пока ничего не добавлено/);
|
||||
assert.match(document.querySelector('[data-choose-hint]').textContent, /«Выбрать» добавит блюдо в приём пищи и в кольца/);
|
||||
[...document.querySelectorAll('button')].find(b => b.textContent === 'Выбрать').click();
|
||||
assert.equal(document.querySelector('[data-empty-hint]'), null);
|
||||
});
|
||||
|
||||
95
tests/dish-card.test.js-e
Normal file
95
tests/dish-card.test.js-e
Normal file
@ -0,0 +1,95 @@
|
||||
// Сценарии TPTIP-10: карточка блюда с граммовкой, КБЖУ и рецептом; «Выбрать» пишет приём пищи.
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const fs = require('node:fs');
|
||||
const vm = require('node:vm');
|
||||
const { JSDOM, VirtualConsole } = require('jsdom');
|
||||
const plan = require('../gym-plan.i18n.js');
|
||||
const source = fs.readFileSync('index.html', 'utf8');
|
||||
const initial = vm.runInNewContext(source.split('/* LOGIC:START */')[1].split('/* LOGIC:END */')[0] + '; defaultData()');
|
||||
initial.settings.onboarded = true;
|
||||
|
||||
function open() {
|
||||
const errors = [];
|
||||
const vc = new VirtualConsole();
|
||||
vc.on('jsdomError', e => errors.push(e));
|
||||
const dom = new JSDOM(source.replace('<script src="gym-plan.i18n.js"></script>', ''), {
|
||||
url: 'http://localhost/', runScripts: 'dangerously', virtualConsole: vc,
|
||||
beforeParse(w) { w.GymPlan = plan; w.scrollTo = () => {}; w.localStorage.setItem('tpt.v1', JSON.stringify(initial)); }
|
||||
});
|
||||
assert.deepEqual(errors, []);
|
||||
return { dom, errors, document: dom.window.document };
|
||||
}
|
||||
|
||||
test('Сценарий: карточка блюда показывает фото, граммы, КБЖУ и шаги', t => {
|
||||
const { dom, document } = open(); t.after(() => dom.window.close());
|
||||
const card = [...document.querySelectorAll('.item')].find(i => i.querySelector('[data-nutrition]'));
|
||||
assert.ok(card, 'нет карточки с КБЖУ');
|
||||
assert.ok(card.querySelector('img'));
|
||||
assert.match(card.querySelector('[data-nutrition]').textContent, /Порция \d+ г · \d+ ккал · Б .* · Ж .* · У /);
|
||||
assert.ok(card.querySelectorAll('[data-steps] li').length >= 3);
|
||||
});
|
||||
|
||||
test('Сценарий: «Выбрать» добавляет блюдо в приём пищи с теми же значениями', t => {
|
||||
const { dom, document, errors } = open(); t.after(() => dom.window.close());
|
||||
const card = [...document.querySelectorAll('.item')].find(i => i.querySelector('[data-nutrition]'));
|
||||
const title = card.querySelector('b').textContent;
|
||||
const kcal = card.querySelector('[data-nutrition]').textContent.match(/(\d+) ккал/)[1];
|
||||
[...card.querySelectorAll('button')].find(b => b.textContent === 'Выбрать').click();
|
||||
assert.deepEqual(errors, []);
|
||||
const saved = JSON.parse(dom.window.localStorage.getItem('tpt.v1'));
|
||||
const m = saved.meals.find(x => x.name === title);
|
||||
assert.ok(m);
|
||||
assert.equal(String(m.kcal), kcal);
|
||||
assert.equal(m.qty, 1);
|
||||
assert.match(document.querySelector('#view').textContent, new RegExp(kcal));
|
||||
});
|
||||
|
||||
test('Сценарий: у каждого готового блюда есть фото, вес, КБЖУ и не менее трёх шагов на русском', t => {
|
||||
const { dom } = open(); t.after(() => dom.window.close());
|
||||
const dishes = dom.window.eval('BUILTIN_RECIPES');
|
||||
assert.ok(dishes.length >= 7);
|
||||
for (const d of dishes) {
|
||||
assert.ok(d.photo, 'нет фото: ' + d.title);
|
||||
assert.ok(d.grams > 0 && d.kcal > 0 && d.protein >= 0 && d.fat >= 0 && d.carbs >= 0, 'нет цифр: ' + d.title);
|
||||
const steps = d.steps.split('\n').filter(Boolean);
|
||||
assert.ok(steps.length >= 3, 'мало шагов: ' + d.title);
|
||||
assert.ok(steps.every(x => /[а-яё]/i.test(x)), 'шаг не на русском: ' + d.title);
|
||||
}
|
||||
});
|
||||
|
||||
test('Сценарий: после «Выбрать» видны вес и КБЖУ блюда, кольца и подтверждение обновились', t => {
|
||||
const { dom, document, errors } = open(); t.after(() => dom.window.close());
|
||||
const card = [...document.querySelectorAll('.item')].find(i => i.querySelector('[data-nutrition]'));
|
||||
const title = card.querySelector('b').textContent;
|
||||
const n = card.querySelector('[data-nutrition]').textContent.match(/Порция (\d+) г · (\d+) ккал · Б (\S+) · Ж (\S+) · У (\S+)/);
|
||||
const ringsBefore = document.querySelector('.rings').textContent;
|
||||
[...card.querySelectorAll('button')].find(b => b.textContent === 'Выбрать').click();
|
||||
assert.deepEqual(errors, []);
|
||||
assert.notEqual(document.querySelector('.rings').textContent, ringsBefore);
|
||||
assert.match(document.querySelector('.rings').textContent, new RegExp(n[2]));
|
||||
assert.match(document.getElementById('toast').textContent, /добавлено в приём пищи/);
|
||||
[...document.querySelectorAll('#tabsIn button')].find(x => /Питание/.test(x.textContent)).click();
|
||||
const row = [...document.querySelectorAll('#view .item')].find(i => i.querySelector('b').textContent === title && /порц\./.test(i.textContent));
|
||||
assert.ok(row, 'нет записи в приёме пищи');
|
||||
assert.match(row.textContent, new RegExp('\\(' + n[1] + ' г\\)'));
|
||||
assert.match(row.textContent, new RegExp(n[2] + ' ккал · Б ' + n[3] + ' · Ж ' + n[4] + ' · У ' + n[5]));
|
||||
});
|
||||
|
||||
<<<<<<< HEAD
|
||||
test('Сценарий: рецепт читается на телефоне — текст переносится, а не обрезается', () => {
|
||||
const css = source.match(/\.item \.main\{[^}]*\}/)[0];
|
||||
assert.match(css, /min-width:0/);
|
||||
assert.match(css, /overflow-wrap:anywhere/);
|
||||
assert.doesNotMatch(source, /text-overflow:\s*ellipsis/);
|
||||
=======
|
||||
test('Сценарий: на пустом дне рядом с кольцами есть подсказка, после «Выбрать» она исчезает', t => {
|
||||
const { dom, document } = open(); t.after(() => dom.window.close());
|
||||
const hint = document.querySelector('[data-empty-hint]');
|
||||
assert.ok(hint, 'нет подсказки');
|
||||
assert.match(hint.textContent, /Пока ничего не добавлено/);
|
||||
assert.match(document.querySelector('[data-choose-hint]').textContent, /«Выбрать» добавит блюдо в приём пищи и в кольца/);
|
||||
[...document.querySelectorAll('button')].find(b => b.textContent === 'Выбрать').click();
|
||||
assert.equal(document.querySelector('[data-empty-hint]'), null);
|
||||
>>>>>>> d4dee26 (TPTIP-17: подсказка на пустом главном экране)
|
||||
});
|
||||
Loading…
Reference in New Issue
Block a user