diff --git a/frontend/src/views/Stats.jsx b/frontend/src/views/Stats.jsx index 636e266..692b854 100644 --- a/frontend/src/views/Stats.jsx +++ b/frontend/src/views/Stats.jsx @@ -5,7 +5,7 @@ import { EXIDX, matchExercise } from '../lib/exercises.js' import { lastBW, streakWeeks, setLabel, modeOf, effortOf, metricModeForEntry, metricRowsForEntry, bestWeightForEntry } from '../lib/history.js' import { fmtNum, fmtDate, fmtVol, todayISO, weekStartOf } from '../lib/format.js' import { t, exerciseNameFor, getLang } from '../lib/i18n.js' -import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx' +import { bwSheet, goalSheet, calendarSheet, workoutDetailSheet, exerciseHistorySheet, WorkoutRow, bwDeltaColor } from '../sheets.jsx' import LineChart from '../components/LineChart.jsx' import Heatmap from '../components/Heatmap.jsx' import Icon from '../components/Icon.jsx' @@ -189,8 +189,10 @@ function MuscleBalance({ S }) {
{t('Strength shows retained muscle strength. Train again to reset it.')}
{sel && <>

{t('Exercises')} · {t(MUSCLE_NAME[sel])}

+ {/* A row quotes the exercise's estimated 1RM, so a tap opens the exercise history + sheet — the curve behind that number plus the last sessions set by set. */} {muscleExercises.length ? muscleExercises.map(row => ( -
onExercise && onExercise(row.id))}> +
exerciseHistorySheet(row.id))}> {row.name} diff --git a/frontend/src/views/Stats.recovery.test.jsx b/frontend/src/views/Stats.recovery.test.jsx index 402981f..93c1052 100644 --- a/frontend/src/views/Stats.recovery.test.jsx +++ b/frontend/src/views/Stats.recovery.test.jsx @@ -20,6 +20,7 @@ const LEGACY_SNAPSHOT_ID = 'legacy-snapshot-only' const mocks = vi.hoisted(() => ({ maps: [], mapMounts: 0, + exerciseHistorySheet: vi.fn(), S: { unit: 'kg', body: 'male', effort: 'rir', targetW: null, bodyweight: [], routines: [], workouts: [], @@ -32,6 +33,7 @@ vi.mock('../store/useStore.js', () => ({ vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} })) vi.mock('../sheets.jsx', () => ({ bwSheet: () => {}, goalSheet: () => {}, calendarSheet: () => {}, workoutDetailSheet: () => {}, + exerciseHistorySheet: mocks.exerciseHistorySheet, WorkoutRow: () => React.createElement('div'), bwDeltaColor: () => 'inherit', })) vi.mock('../components/LineChart.jsx', () => ({ default: () => React.createElement('div') })) @@ -139,6 +141,7 @@ function resetFixture(workouts = lifecycleWorkouts()) { mocks.S.workouts = workouts mocks.maps.length = 0 mocks.mapMounts = 0 + mocks.exerciseHistorySheet.mockClear() useUI.setState({ sheets: [] }) } @@ -306,6 +309,36 @@ describe('Stats muscle recovery view runtime', () => { }) }) +describe('Stats strength exercise rows', () => { + // The rows under "Exercises · " are presented as buttons (role, tabIndex, pointer + // cursor) but for a year called a handler that never existed, so every tap threw + // "onExercise is not defined" and opened nothing (QA C13). A tap now opens the exercise's + // history sheet — the one place that already draws the Est. 1RM curve the row quotes. + it('opens the exercise history sheet when a row is tapped instead of throwing', async () => { + resetFixture(exercisePickerWorkouts()) + await mountStats() + const thrown = [] + dom.addEventListener('error', e => { thrown.push(e.error || e.message); e.preventDefault() }) + + await click(viewButton('Strength')) + await click(muscleCard().querySelector('[data-muscle="chest"]')) + expect(muscleCard().textContent).toContain('Exercises · Chest') + const row = [...muscleCard().querySelectorAll('.mrow[role="button"]')].find(el => el.textContent.includes('Est. 1RM')) + expect(row, 'expected a tappable exercise row for the chest').toBeTruthy() + expect(row.textContent).toContain('barbell bench press') + + await click(row) + expect(thrown).toEqual([]) + expect(mocks.exerciseHistorySheet).toHaveBeenCalledTimes(1) + expect(mocks.exerciseHistorySheet).toHaveBeenCalledWith('0025') + + // The keyboard path of tappable() must land in the same place. + await act(async () => { row.dispatchEvent(new dom.KeyboardEvent('keydown', { key: 'Enter', bubbles: true })) }) + expect(thrown).toEqual([]) + expect(mocks.exerciseHistorySheet).toHaveBeenCalledTimes(2) + }) +}) + describe('Stats exercise progress picker', () => { it('filters with the shared exercise matcher and still selects from the mounted sheet', async () => { resetFixture(exercisePickerWorkouts()) diff --git a/frontend/src/views/Stats.test.js b/frontend/src/views/Stats.test.js index 50f5ec7..179f892 100644 --- a/frontend/src/views/Stats.test.js +++ b/frontend/src/views/Stats.test.js @@ -19,7 +19,10 @@ describe('Stats mixed-entry metric contract', () => { it('renders one clickable muscle exercise list rather than a duplicate non-clickable copy', () => { expect((source.match(/muscleExercises\.length \? muscleExercises\.map\(row =>/g) || []).length).toBe(1) - expect(source).toContain('{...tappable(() => onExercise && onExercise(row.id))}') + // The handler must be one that exists: the previous `onExercise` was never defined and + // every tap threw (QA C13), so the row opens the exercise history sheet instead. + expect(source).toContain('{...tappable(() => exerciseHistorySheet(row.id))}') + expect(source).not.toContain('onExercise') }) it('uses the shared metric mode and row helpers rather than entryMode as a chart gate', () => {