diff --git a/index.html b/index.html index bd7c924..5b8ec63 100644 --- a/index.html +++ b/index.html @@ -124,6 +124,7 @@ input:focus,select:focus,textarea:focus,button:focus-visible{outline:2px solid v
+ ', ''), { + url: `http://localhost/?lang=${lang}`, runScripts: 'dangerously', virtualConsole: console, + beforeParse(w) { + w.GymPlan = plan; + w.scrollTo = () => {}; + w.localStorage.setItem('tpt.v1', saved); + } + }); + assert.deepEqual(errors, []); + const document = dom.window.document; + return { dom, document, errors, + click(text, root = document) { + const button = [...root.querySelectorAll('button')].find(b => b.textContent.trim() === text); + assert.ok(button, `No button: ${text}`); + button.click(); + assert.deepEqual(errors, []); + }, + saved() { return dom.window.localStorage.getItem('tpt.v1'); } + }; +} +for (const lang of ['ru', 'kk', 'en']) { + test(`Просмотр четырёх дней и отмена черновика (${lang})`, t => { + const app = open(undefined, lang); t.after(() => app.dom.window.close()); + const text = plan.text(lang); + app.click(text.title); + const cards = app.document.querySelectorAll('#view section'); + assert.equal(cards.length, 4); + assert.equal(app.document.querySelectorAll('#view li').length, 20); + app.click(text.record, cards[0]); + assert.equal(app.document.querySelectorAll('#overlay input[aria-label="Повторы"]').length, 15); + assert.ok([...app.document.querySelectorAll('#overlay input[aria-label="Вес, кг"]')].every(i => i.value === '')); + app.dom.window.document.dispatchEvent(new app.dom.window.KeyboardEvent('keydown', { key: 'Escape' })); + assert.equal(JSON.parse(app.saved()).workouts.length, 0); + app.click(text.back); + assert.ok(app.document.querySelector('#view').textContent.includes(text.title)); + }); +} +test('Сохранение занятия, обычный журнал, редактирование и повторное открытие', t => { + const app = open(); t.after(() => app.dom.window.close()); + app.click('План тренировок'); app.click('Записать тренировку'); + const date = app.document.querySelector('#overlay input[type="date"]'); + date.value = '2026-11-17'; + app.click('Сохранить'); + const data = JSON.parse(app.saved()); + assert.equal(data.workouts.length, 1); + const workout = data.workouts[0]; + assert.equal(workout.date, '2026-11-17'); + assert.equal(workout.type, 'strength'); + assert.equal(workout.duration, 120); + assert.equal(workout.exercises.length, 5); + assert.equal(workout.exercises[0].sets.length, 3); + assert.equal(workout.exercises[0].sets[0].reps, 10); + assert.ok(app.document.querySelector('#view').textContent.includes('120 мин')); + app.document.querySelector('#view .item .main').click(); + assert.ok(app.document.querySelector('#overlay').textContent.includes('Упражнения')); + const next = open(app.saved()); t.after(() => next.dom.window.close()); + next.click('План тренировок'); + assert.equal(next.document.querySelectorAll('#view section').length, 4); + assert.equal(JSON.parse(next.saved()).workouts.length, 1); +}); +test('Неверная длительность: запись не создаётся', t => { + const app = open(); t.after(() => app.dom.window.close()); + app.click('План тренировок'); app.click('Записать тренировку'); + const duration = [...app.document.querySelectorAll('#overlay label')].find(l => l.textContent.includes('Длительность')); + assert.ok(duration); + duration.querySelector('input').value = '0'; + app.click('Сохранить'); + assert.equal(JSON.parse(app.saved()).workouts.length, 0); + assert.ok(duration.querySelector('.err').textContent); +});