treker-po-trenirovkam-i-pit.../tests/wizard.test.js
Peppa 8057ab6174
All checks were successful
peppa/lint lint: success за 0с
peppa/test test: success за 1с
ci / checks (pull_request) Successful in 5s
deploy / deploy (pull_request) Successful in 9s
TPTIP-15: тест — кольца показывают посчитанные нормы после мастера
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-17 11:39:34 +05:00

65 lines
3.4 KiB
JavaScript
Raw 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.

// Сценарии TPTIP-11: мастер первого запуска без чужих чисел, с понятным вторым шагом.
const test = require('node:test');
const assert = require('node:assert/strict');
const fs = require('node:fs');
const { JSDOM, VirtualConsole } = require('jsdom');
const plan = require('../gym-plan.i18n.js');
const source = fs.readFileSync('index.html', 'utf8');
function open(saved) {
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 = () => {}; if (saved) w.localStorage.setItem('tpt.v1', saved); }
});
assert.deepEqual(errors, []);
return { dom, document: dom.window.document };
}
const btn = (d, t) => [...d.querySelectorAll('button')].find(b => b.textContent === t);
const inputs = d => [...d.querySelectorAll('.sheet input')];
test('Сценарий: на первом шаге поля пустые, числа только в подсказках', t => {
const { dom, document } = open(); t.after(() => dom.window.close());
const [age, height, weight] = inputs(document);
for (const i of [age, height, weight]) assert.equal(i.value, '');
assert.match(age.placeholder, /30/);
btn(document, 'Далее').click();
assert.match(document.querySelector('.sheet').textContent, /Шаг 1 из 2/);
assert.equal(inputs(document).length, 3, 'пустые поля не пускают дальше');
});
test('Сценарий: на втором шаге нормы посчитаны и правятся вручную; окно больше не появляется', t => {
const { dom, document } = open(); t.after(() => dom.window.close());
const [age, height, weight] = inputs(document);
age.value = '40'; height.value = '170'; weight.value = '65';
btn(document, 'Далее').click();
const sheet = document.querySelector('.sheet');
assert.match(sheet.textContent, /Шаг 2 из 2\. Мы посчитали/);
assert.ok(sheet.querySelector('[data-norms-hint]'));
const kcal = inputs(document)[0];
assert.ok(Number(kcal.value) > 1000);
kcal.value = '1800';
btn(document, 'Готово').click();
const saved = dom.window.localStorage.getItem('tpt.v1');
assert.equal(JSON.parse(saved).settings.kcal, 1800);
assert.equal(JSON.parse(saved).settings.onboarded, true);
assert.equal(document.querySelector('.sheet'), null);
const again = open(saved); t.after(() => again.dom.window.close());
assert.equal(again.document.querySelector('.sheet'), null);
});
test('Сценарий: после «Готово» кольца показывают посчитанные нормы, а не 2000/120/65/230', t => {
const { dom, document } = open(); t.after(() => dom.window.close());
const [age, height, weight] = inputs(document);
age.value = '40'; height.value = '170'; weight.value = '65';
btn(document, 'Далее').click();
btn(document, 'Готово').click();
const s = JSON.parse(dom.window.localStorage.getItem('tpt.v1')).settings;
assert.notEqual(s.kcal, 2000);
const rings = document.querySelector('.rings');
assert.ok(rings, 'кольца на главном экране');
assert.ok(rings.textContent.includes(String(s.kcal)), 'норма калорий ' + s.kcal + ' видна: ' + rings.textContent);
});