Merge merge request !59 (stop timed-set countdowns when discarding a workout)
This commit is contained in:
commit
3026d92cc4
2 files changed
+55
-5
No files matched your search
@@ -276,7 +276,7 @@ function ActiveWorkout() {
|
||||
const nav = useNavigate()
|
||||
const S = useStore(s => s.S)
|
||||
const update = useStore(s => s.update)
|
||||
const { startRest, stopRest, work } = useUI()
|
||||
const { startRest, stopRest, stopWork, work } = useUI()
|
||||
const A = S.active
|
||||
const units = supersetUnits(A.entries)
|
||||
const cur = Math.min(A.cur, Math.max(0, A.entries.length - 1))
|
||||
@@ -480,7 +480,7 @@ function ActiveWorkout() {
|
||||
|
||||
return <div className="narrow">
|
||||
<div className="hdr">
|
||||
<button className="iconbtn" aria-label={t('Discard')} onClick={() => confirmSheet({ title: t('Discard workout?'), message: t('The sets you logged in this session will be lost.'), confirmText: t('Discard'), danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); nav('/home') } })}><Icon name="xmark" /></button>
|
||||
<button className="iconbtn" aria-label={t('Discard')} onClick={() => confirmSheet({ title: t('Discard workout?'), message: t('The sets you logged in this session will be lost.'), confirmText: t('Discard'), danger: true, onConfirm: () => { update(s => { s.active = null }); stopRest(); stopWork(); nav('/home') } })}><Icon name="xmark" /></button>
|
||||
<div style={{ textAlign: 'center' }}><div style={{ fontWeight: 600 }}>{A.name}</div><div className="sub"><Elapsed start={A.start} /> · {t('{0} sets', done + '/' + total)}</div></div>
|
||||
<button className="iconbtn" style={{ color: 'var(--acc)' }} aria-label={t('Finish')} onClick={finishWorkout}><Icon name="check" /></button>
|
||||
</div>
|
||||
|
||||
@@ -7,19 +7,27 @@ import Workout from './Workout.jsx'
|
||||
const mocks = vi.hoisted(() => {
|
||||
const state = {
|
||||
S: null,
|
||||
timer: null,
|
||||
work: null,
|
||||
startRest: vi.fn(),
|
||||
stopRest: vi.fn(),
|
||||
stopRest: null,
|
||||
stopWork: null,
|
||||
confirmSheet: vi.fn(),
|
||||
topWeightSheet: vi.fn(),
|
||||
}
|
||||
state.stopRest = vi.fn(() => { state.timer = null })
|
||||
state.stopWork = vi.fn(() => { state.work = null })
|
||||
state.storeSnapshot = () => ({
|
||||
S: state.S,
|
||||
user: null,
|
||||
update: mut => mut(state.S),
|
||||
})
|
||||
state.uiSnapshot = () => ({
|
||||
work: null,
|
||||
timer: state.timer,
|
||||
work: state.work,
|
||||
startRest: state.startRest,
|
||||
stopRest: state.stopRest,
|
||||
stopWork: state.stopWork,
|
||||
startWork: vi.fn(),
|
||||
toast: vi.fn(),
|
||||
})
|
||||
@@ -45,7 +53,7 @@ vi.mock('../sheets.jsx', () => ({
|
||||
topWeightSheet: mocks.topWeightSheet,
|
||||
finishWorkout: vi.fn(),
|
||||
workoutCompleteSheet: vi.fn(),
|
||||
confirmSheet: vi.fn(),
|
||||
confirmSheet: mocks.confirmSheet,
|
||||
// Both note sheets belong here even though the tests never open one: Workout.jsx reads
|
||||
// sessionNoteSheet during render, so a missing export is a render crash, not a no-op.
|
||||
exerciseNoteSheet: vi.fn(),
|
||||
@@ -112,8 +120,16 @@ async function toggleSet(index) {
|
||||
await act(async () => { checkbox.dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
}
|
||||
|
||||
async function requestDiscard() {
|
||||
const button = container.querySelector('button[aria-label="Discard"]')
|
||||
expect(button).toBeTruthy()
|
||||
await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
mocks.timer = null
|
||||
mocks.work = null
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
@@ -155,6 +171,40 @@ describe('Workout set completion flow', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('Workout discard timer lifecycle', () => {
|
||||
it('preserves active timers while discard is awaiting confirmation', async () => {
|
||||
const timer = { left: 30, total: 90, endsAt: Date.now() + 30_000 }
|
||||
const work = { left: 20, total: 45, endsAt: Date.now() + 20_000, label: 'Plank' }
|
||||
mocks.timer = timer
|
||||
mocks.work = work
|
||||
await mount([exercise('timed-plank', [false])])
|
||||
|
||||
await requestDiscard()
|
||||
|
||||
expect(mocks.confirmSheet).toHaveBeenCalledOnce()
|
||||
expect(mocks.timer).toBe(timer)
|
||||
expect(mocks.work).toBe(work)
|
||||
expect(mocks.stopRest).not.toHaveBeenCalled()
|
||||
expect(mocks.stopWork).not.toHaveBeenCalled()
|
||||
expect(mocks.S.active).not.toBeNull()
|
||||
})
|
||||
|
||||
it('clears rest and work timers only after discard is confirmed', async () => {
|
||||
mocks.timer = { left: 30, total: 90, endsAt: Date.now() + 30_000 }
|
||||
mocks.work = { left: 20, total: 45, endsAt: Date.now() + 20_000, label: 'Plank' }
|
||||
await mount([exercise('timed-plank', [false])])
|
||||
await requestDiscard()
|
||||
|
||||
await act(async () => { mocks.confirmSheet.mock.calls[0][0].onConfirm() })
|
||||
|
||||
expect(mocks.S.active).toBeNull()
|
||||
expect(mocks.timer).toBeNull()
|
||||
expect(mocks.work).toBeNull()
|
||||
expect(mocks.stopRest).toHaveBeenCalledOnce()
|
||||
expect(mocks.stopWork).toHaveBeenCalledOnce()
|
||||
})
|
||||
})
|
||||
|
||||
describe('superset flow survives an exercise being removed mid-session', () => {
|
||||
// removeActiveExercise splices A.entries, shifting every index above the removal down.
|
||||
// The high-water marks are index-keyed, so without re-baselining the shifted exercise
|
||||
|
||||
Reference in new issue
Block a user