From dcfc7f15a791852d5c8cd570cedde1312f20d9b5 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 28 Aug 2026 17:17:02 +0000 Subject: [PATCH 1/2] fix: allow decimal progression steps below one --- frontend/src/sheets.jsx | 2 +- frontend/src/sheets.test.jsx | 69 ++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 frontend/src/sheets.test.jsx diff --git a/frontend/src/sheets.jsx b/frontend/src/sheets.jsx index 00ad49f..0bd5faf 100644 --- a/frontend/src/sheets.jsx +++ b/frontend/src/sheets.jsx @@ -552,7 +552,7 @@ function ProgressionFields({ ex, mode, c, setC, routine, unit }) { if (options.length < 2) return null const inherited = policyFor({ id: ex.id }, routine, mode) const active = policyFor({ ...c, id: ex.id }, routine, mode) - const inc = c.inc > 0 ? c.inc : (mode === 'time' ? 5 : defaultIncrement(ex.id, unit)) + const inc = c.inc >= 0 ? c.inc : (mode === 'time' ? 5 : defaultIncrement(ex.id, unit)) return <>

{t('Progression')}

diff --git a/frontend/src/sheets.test.jsx b/frontend/src/sheets.test.jsx new file mode 100644 index 0000000..df52ca7 --- /dev/null +++ b/frontend/src/sheets.test.jsx @@ -0,0 +1,69 @@ +// @vitest-environment happy-dom +import React, { act } from 'react' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' +import { createRoot } from 'react-dom/client' +import { EXDB } from './lib/exercises.js' +import { useStore } from './store/useStore.js' +import { useUI } from './store/useUI.js' +import { exConfigSheet } from './sheets.jsx' + +const ex = EXDB.find(e => e.id === '0009') +const mounted = [] + +function type(el, value) { + Object.getOwnPropertyDescriptor(el.constructor.prototype, 'value').set.call(el, value) + el.dispatchEvent(new Event('input', { bubbles: true })) +} + +function renderConfig(onSave = vi.fn()) { + exConfigSheet(ex, { sets: 3, reps: 10, weight: 0, mode: 'reps', prog: 'double' }, onSave) + const sheet = useUI.getState().sheets.at(-1) + const host = document.createElement('div') + document.body.appendChild(host) + const root = createRoot(host) + mounted.push(root) + act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id)))) + const stepper = [...host.querySelectorAll('.stp-w')] + .find(el => el.querySelector('.stp-l')?.textContent.startsWith('Step')) + return { host, step: stepper.querySelector('input'), onSave } +} + +describe('exercise configuration progression step', () => { + beforeEach(() => { + globalThis.IS_REACT_ACT_ENVIRONMENT = true + useUI.setState({ sheets: [] }) + useStore.setState(s => ({ S: { ...s.S, unit: 'kg' } })) + document.body.innerHTML = '' + }) + + afterEach(() => { + act(() => { mounted.splice(0).forEach(root => root.unmount()) }) + }) + + it('keeps the draft empty while clearing the default so a sub-one comma decimal can be entered', () => { + const { step } = renderConfig() + expect(step.value).toBe('2.5') + + act(() => { type(step, '') }) + expect(step.value).toBe('') + + act(() => { type(step, '0,5') }) + expect(step.value).toBe('0.5') + }) + + it('persists a positive decimal but omits a cleared progression increment', () => { + const positive = renderConfig() + act(() => { type(positive.step, '0,5') }) + const positiveSave = [...positive.host.querySelectorAll('button')] + .find(b => /^(save|add to routine)$/i.test(b.textContent.trim())) + act(() => { positiveSave.click() }) + expect(positive.onSave).toHaveBeenCalledWith(expect.objectContaining({ inc: 0.5 })) + + const empty = renderConfig() + act(() => { type(empty.step, '') }) + const emptySave = [...empty.host.querySelectorAll('button')] + .find(b => /^(save|add to routine)$/i.test(b.textContent.trim())) + act(() => { emptySave.click() }) + expect(empty.onSave).toHaveBeenCalledWith(expect.not.objectContaining({ inc: expect.anything() })) + }) +}) From 9216aa2f02f3ab9da36782e8d2d7890ac5030958 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 28 Aug 2026 17:20:36 +0000 Subject: [PATCH 2/2] test: assert cleared progression steps are omitted --- frontend/src/sheets.test.jsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/sheets.test.jsx b/frontend/src/sheets.test.jsx index df52ca7..fed2b47 100644 --- a/frontend/src/sheets.test.jsx +++ b/frontend/src/sheets.test.jsx @@ -64,6 +64,6 @@ describe('exercise configuration progression step', () => { const emptySave = [...empty.host.querySelectorAll('button')] .find(b => /^(save|add to routine)$/i.test(b.textContent.trim())) act(() => { emptySave.click() }) - expect(empty.onSave).toHaveBeenCalledWith(expect.not.objectContaining({ inc: expect.anything() })) + expect(empty.onSave.mock.calls[0][0]).not.toHaveProperty('inc') }) })