feat: add Stats exercise progress picker search
This commit is contained in:
1 parent
5314b342ff
commit
283d897762
3 files changed
+90
-19
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { EXIDX } from '../lib/exercises.js'
|
||||
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, weekKey } from '../lib/format.js'
|
||||
import { t, exerciseNameFor, getLang } from '../lib/i18n.js'
|
||||
@@ -428,7 +428,13 @@ export default function Stats() {
|
||||
{exHist.length ? <>
|
||||
<div className="sect-b" style={{ marginBottom: 10 }}>
|
||||
<SelectRow title={t('Exercise')} sheetTitle={t('Exercise progress')} value={curEx} onChange={setExId} stackedValue
|
||||
options={exHist.map(id => ({ value: id, label: nameOf(id) + (exCurrent[id].mx ? ' ' + '—' + ' ' + fmtNum(exCurrent[id].mx) + ' ' + exCurrent[id].unit : '') }))} />
|
||||
options={exHist.map(id => ({ value: id, label: nameOf(id) + (exCurrent[id].mx ? ' ' + '—' + ' ' + fmtNum(exCurrent[id].mx) + ' ' + exCurrent[id].unit : '') }))}
|
||||
search={{
|
||||
placeholder: t('Search…'),
|
||||
label: t('Search…'),
|
||||
emptyLabel: t('No match'),
|
||||
match: (option, query) => matchExercise(EXIDX[option.value] || { n: nameOf(option.value) }, query),
|
||||
}} />
|
||||
</div>
|
||||
{exOpts.length > 1 && <Segmented className="seg-range" value={onEff ? 'effort' : onE1 ? 'e1rm' : 'top'} onChange={setExMetric} options={exOpts} />}
|
||||
<div className="chart">
|
||||
|
||||
@@ -6,6 +6,9 @@ import { MUSCLES, levelsOf } from '../lib/muscles.js'
|
||||
import { FATIGUE_STATES, STRENGTH_FLOOR } from '../lib/recovery.js'
|
||||
import { fatigueStateOf } from '../lib/recovery-view.js'
|
||||
import Stats from './Stats.jsx'
|
||||
import Modals from '../components/Modals.jsx'
|
||||
import { bindUI } from '../components/ui.jsx'
|
||||
import { useUI } from '../store/useUI.js'
|
||||
|
||||
const DAY = 86400000
|
||||
const HOUR = 3600000
|
||||
@@ -50,6 +53,8 @@ vi.mock('../components/BodyMap.jsx', () => ({
|
||||
BodyMapLegend: () => React.createElement('div', { 'data-balance-legend': true }),
|
||||
}))
|
||||
|
||||
bindUI(useUI)
|
||||
|
||||
let dom
|
||||
let root
|
||||
let container
|
||||
@@ -105,19 +110,30 @@ function allSubfullWorkout(now = BASE_NOW) {
|
||||
return workout('all-subfull', now - 15 * DAY, [entry('1254', [set(true)])])
|
||||
}
|
||||
|
||||
function exercisePickerWorkouts(now = BASE_NOW) {
|
||||
return [
|
||||
workout('bench', now, [entry('0025', [set(true, { w: 80 })])]),
|
||||
workout('squat', now - DAY, [entry('0043', [set(true, { w: 60 })])]),
|
||||
]
|
||||
}
|
||||
|
||||
function resetFixture(workouts = lifecycleWorkouts()) {
|
||||
mocks.S.unit = 'kg'
|
||||
mocks.S.bodyweight = []
|
||||
mocks.S.workouts = workouts
|
||||
mocks.maps.length = 0
|
||||
mocks.mapMounts = 0
|
||||
useUI.setState({ sheets: [] })
|
||||
}
|
||||
|
||||
function installDom() {
|
||||
dom = new Window({ url: 'http://localhost/' })
|
||||
dom.scrollTo = vi.fn()
|
||||
globalThis.window = dom
|
||||
globalThis.document = dom.document
|
||||
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: dom.navigator })
|
||||
Object.defineProperty(globalThis, 'location', { configurable: true, value: dom.location })
|
||||
Object.defineProperty(globalThis, 'history', { configurable: true, value: dom.history })
|
||||
for (const key of ['HTMLElement', 'HTMLIFrameElement', 'Node', 'Element', 'Event', 'MouseEvent']) {
|
||||
globalThis[key] = dom[key]
|
||||
}
|
||||
@@ -129,7 +145,7 @@ function installDom() {
|
||||
|
||||
async function mountStats() {
|
||||
installDom()
|
||||
await act(async () => { root.render(React.createElement(Stats)) })
|
||||
await act(async () => { root.render(React.createElement(React.Fragment, null, React.createElement(Stats), React.createElement(Modals))) })
|
||||
}
|
||||
|
||||
async function unmountStats() {
|
||||
@@ -179,6 +195,7 @@ beforeEach(() => {
|
||||
|
||||
afterEach(async () => {
|
||||
await unmountStats()
|
||||
useUI.setState({ sheets: [] })
|
||||
vi.useRealTimers()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
@@ -272,3 +289,36 @@ describe('Stats muscle recovery view runtime', () => {
|
||||
expect(strengthMap.thresholds.at(-1)).toEqual({ at: 1, level: 4 })
|
||||
})
|
||||
})
|
||||
|
||||
describe('Stats exercise progress picker', () => {
|
||||
it('filters with the shared exercise matcher and still selects from the mounted sheet', async () => {
|
||||
resetFixture(exercisePickerWorkouts())
|
||||
await mountStats()
|
||||
|
||||
const card = [...container.querySelectorAll('.card')].find(el => el.querySelector('h2')?.textContent.trim() === 'Exercise progress')
|
||||
const selector = [...card.querySelectorAll('button')].find(button => button.querySelector('.lrow-t')?.textContent.trim() === 'Exercise')
|
||||
await click(selector)
|
||||
|
||||
const modal = document.querySelector('#modal-root')
|
||||
const input = modal.querySelector('input')
|
||||
expect(input).toBeTruthy()
|
||||
expect(input.getAttribute('aria-label')).toBe('Search…')
|
||||
expect(input.getAttribute('placeholder')).toBe('Search…')
|
||||
|
||||
const setter = Object.getOwnPropertyDescriptor(input.constructor.prototype, 'value').set
|
||||
await act(async () => {
|
||||
setter.call(input, 'squat full bárbell')
|
||||
input.dispatchEvent(new Event('input', { bubbles: true }))
|
||||
input.dispatchEvent(new Event('change', { bubbles: true }))
|
||||
})
|
||||
|
||||
expect(modal.textContent).toContain('barbell full squat')
|
||||
expect(modal.textContent).not.toContain('barbell bench press')
|
||||
|
||||
const matching = [...modal.querySelectorAll('button')].find(button => button.textContent.includes('barbell full squat'))
|
||||
await click(matching)
|
||||
|
||||
expect(useUI.getState().sheets).toHaveLength(0)
|
||||
expect(card.querySelector('.lrow-v').textContent).toContain('barbell full squat')
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user