From a0145be4245ce601fb9c661b3494d3bdb8672c4e Mon Sep 17 00:00:00 2001 From: Peppa Date: Tue, 17 Nov 2026 11:00:47 +0500 Subject: [PATCH] =?UTF-8?q?TPTIP-5:=20=D0=BE=D1=82=D0=BA=D1=80=D1=8B=D1=82?= =?UTF-8?q?=D1=8C=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D1=8B=D0=B9=20=D0=BF?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=20=D0=B8=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD?= =?UTF-8?q?=D0=BE=D1=81=D0=B8=D1=82=D1=8C=20=D0=B7=D0=B0=D0=BD=D1=8F=D1=82?= =?UTF-8?q?=D0=B8=D1=8F=20=D0=B2=20=D0=B6=D1=83=D1=80=D0=BD=D0=B0=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- index.html | 30 +++++-- .../changes/tptip-5-weekly-gym-plan/tasks.md | 2 +- server.js | 1 + sw.js | 4 +- tests/gym-plan-ui.test.js | 84 +++++++++++++++++++ 5 files changed, 112 insertions(+), 9 deletions(-) create mode 100644 tests/gym-plan-ui.test.js 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); +});