feat(workout): safely swap active exercise
This commit is contained in:
1 parent
5314b342ff
commit
cf1e99ac95
19 files changed
+366
-2
No files matched your search
@@ -10,7 +10,7 @@ import { t, exerciseNameFor } from '../lib/i18n.js'
|
||||
import { api } from '../lib/api.js'
|
||||
import { setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck } from '../lib/supersetFlow.js'
|
||||
import Media from '../components/Media.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet } from '../sheets.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, topWeightSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise } from '../sheets.jsx'
|
||||
import Icon from '../components/Icon.jsx'
|
||||
import { Button, Check, NumberField } from '../components/ui.jsx'
|
||||
import { nextPrescription, applyPrescription, defaultIncrement } from '../lib/progression.js'
|
||||
@@ -526,6 +526,11 @@ function ActiveWorkout() {
|
||||
}), null, routine, seed)
|
||||
})} icon="plus">{t('Add exercise')}</Button>
|
||||
{A.entries.length > 0 && <>
|
||||
<div style={{ height: 6 }} />
|
||||
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
||||
<Button size="sm" icon="shuffle" aria-label={t('Swap exercise')} disabled={!!work}
|
||||
onClick={() => swapActiveWorkoutExercise(cur)}>{t('Swap exercise')}</Button>
|
||||
</div>
|
||||
<div style={{ height: 6 }} />
|
||||
<div style={{ display: 'flex', justifyContent: 'center' }}>
|
||||
<Button size="sm" icon="minus" style={{ color: 'var(--red)' }} disabled={!!work} onClick={removeExerciseSheet}>{t('Remove exercise')}</Button>
|
||||
|
||||
@@ -10,6 +10,7 @@ const mocks = vi.hoisted(() => {
|
||||
startRest: vi.fn(),
|
||||
stopRest: vi.fn(),
|
||||
topWeightSheet: vi.fn(),
|
||||
swapActiveWorkoutExercise: vi.fn(),
|
||||
}
|
||||
state.storeSnapshot = () => ({
|
||||
S: state.S,
|
||||
@@ -46,6 +47,7 @@ vi.mock('../sheets.jsx', () => ({
|
||||
finishWorkout: vi.fn(),
|
||||
workoutCompleteSheet: vi.fn(),
|
||||
confirmSheet: vi.fn(),
|
||||
swapActiveWorkoutExercise: mocks.swapActiveWorkoutExercise,
|
||||
// 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(),
|
||||
@@ -187,3 +189,16 @@ describe('superset flow survives an exercise being removed mid-session', () => {
|
||||
expect(mocks.startRest).toHaveBeenCalledWith(90)
|
||||
})
|
||||
})
|
||||
|
||||
describe('active exercise swap control', () => {
|
||||
it('opens the swap flow for the selected duplicate occurrence', async () => {
|
||||
await mount([exercise('bench', [false]), exercise('bench', [false]), exercise('row', [false])], 1)
|
||||
|
||||
const swap = container.querySelector('button[aria-label="Swap exercise"]')
|
||||
expect(swap).toBeTruthy()
|
||||
await act(async () => { swap.dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
|
||||
expect(mocks.swapActiveWorkoutExercise).toHaveBeenCalledOnce()
|
||||
expect(mocks.swapActiveWorkoutExercise).toHaveBeenCalledWith(1)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user