feat: muscle map Fatigue + Strength (detraining) views
Per-muscle fatigue (72h window, 36h half-life, .25/.5 bands) and retained strength (14d plateau, 28d half-life, .5 floor) views on the Stats page behind a Balance | Fatigue | Strength segmented control. Pure recovery.js module with fatiguedMuscles/detrainedMuscles hooks, owner-approved backward-compatible absolute-level BodyMap extension, 8 i18n keys across English fallback + 11 locale packs, mounted interaction tests.
This commit is contained in:
1 parent
551b072c54
commit
eeee4b461c
21 files changed
+1307
-35
No files matched your search
+135
-28
@@ -1,4 +1,4 @@
|
||||
import { useState } from 'react'
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { EXIDX } from '../lib/exercises.js'
|
||||
@@ -10,7 +10,9 @@ import LineChart from '../components/LineChart.jsx'
|
||||
import Heatmap from '../components/Heatmap.jsx'
|
||||
import Icon from '../components/Icon.jsx'
|
||||
import BodyMap, { BodyMapLegend } from '../components/BodyMap.jsx'
|
||||
import { loadOfWorkouts, rankOf, MUSCLE_NAME } from '../lib/muscles.js'
|
||||
import { loadOfWorkouts, rankOf, MUSCLE_NAME, musclesOf } from '../lib/muscles.js'
|
||||
import { fatigueOf, strengthOf, STRENGTH_FLOOR } from '../lib/recovery.js'
|
||||
import { fatigueStateOf } from '../lib/recovery-view.js'
|
||||
import { e1rmSeries, best1RM } from '../lib/onerm.js'
|
||||
import {
|
||||
hasEffort, displayScale, scaleName, toScale, avgRir, effortSummary, effortWeeks,
|
||||
@@ -20,11 +22,93 @@ import { Button, Segmented, SelectRow } from '../components/ui.jsx'
|
||||
|
||||
// Which muscles the training in a window actually hit — and, the point of the card,
|
||||
// which ones it keeps missing. Shading is relative within the window (lib/muscles.js).
|
||||
function latestMuscleTraining(workouts) {
|
||||
const latest = {}
|
||||
for (const workout of workouts || []) {
|
||||
const timestamp = Number(workout?.start || new Date(workout?.d).getTime())
|
||||
if (!Number.isFinite(timestamp)) continue
|
||||
for (const entry of workout.entries || []) {
|
||||
if (!(entry.sets || []).some(set => set?.done === true)) continue
|
||||
for (const slug of Object.keys(musclesOf(EXIDX[entry.id]))) {
|
||||
if (latest[slug] == null || timestamp > latest[slug]) latest[slug] = timestamp
|
||||
}
|
||||
}
|
||||
}
|
||||
return latest
|
||||
}
|
||||
|
||||
const FATIGUE_LEVELS = [
|
||||
{ at: 0, level: 4 },
|
||||
{ at: 0.25, level: 2 },
|
||||
{ at: 0.5, level: 0, exclusive: true },
|
||||
]
|
||||
|
||||
const STRENGTH_LEVELS = [
|
||||
{ at: STRENGTH_FLOOR, level: 0 },
|
||||
{ at: 0.625, level: 1 },
|
||||
{ at: 0.75, level: 2 },
|
||||
{ at: 0.875, level: 3 },
|
||||
{ at: 1, level: 4 },
|
||||
]
|
||||
|
||||
function useNow() {
|
||||
const [, setTick] = useState(0)
|
||||
useEffect(() => {
|
||||
const iv = setInterval(() => setTick(tick => tick + 1), 60000)
|
||||
return () => clearInterval(iv)
|
||||
}, [])
|
||||
return Date.now()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the whole weeks since a completed muscle-training timestamp.
|
||||
*
|
||||
* @param {number} now Current render-time timestamp in milliseconds.
|
||||
* @param {number} lastTrained Timestamp of the latest completed training event.
|
||||
* @returns {number} Non-negative whole weeks, including zero for ages under seven days.
|
||||
*/
|
||||
export function weeksSinceTraining(now, lastTrained) {
|
||||
return Math.max(0, Math.floor((now - lastTrained) / 86400000 / 7))
|
||||
}
|
||||
|
||||
function FatigueLegend() {
|
||||
return <div className="hm-legend" aria-label={t('Fatigue')}>
|
||||
<span>{t('Fatigued')}</span><div className="hm-c l0" />
|
||||
<span>{t('Recovering')}</span><div className="hm-c l2" />
|
||||
<span>{t('Ready')}</span><div className="hm-c l4" />
|
||||
</div>
|
||||
}
|
||||
|
||||
function StrengthLegend() {
|
||||
return <div className="hm-legend" aria-label={t('Strength')}>
|
||||
<span>1</span><div className="hm-c l4" /><div className="hm-c l3" /><div className="hm-c l2" />
|
||||
<div className="hm-c l1" /><div className="hm-c l0" /><span>{fmtNum(STRENGTH_FLOOR)}</span>
|
||||
</div>
|
||||
}
|
||||
|
||||
function fatigueLabel(value) {
|
||||
const state = fatigueStateOf(value)
|
||||
return t(state === 'ready' ? 'Ready' : state === 'recovering' ? 'Recovering' : 'Fatigued')
|
||||
}
|
||||
|
||||
function MuscleBalance({ S }) {
|
||||
const [view, setView] = useState('balance')
|
||||
const [win, setWin] = useState(7)
|
||||
const [hard, setHard] = useState(false)
|
||||
const [sel, setSel] = useState(null)
|
||||
const now = Date.now()
|
||||
const now = useNow()
|
||||
const workouts = S.workouts
|
||||
const fatigue = useMemo(() => fatigueOf(workouts, now), [workouts, now])
|
||||
const strength = useMemo(() => strengthOf(workouts, now), [workouts, now])
|
||||
const lastTrained = useMemo(() => latestMuscleTraining(workouts), [workouts])
|
||||
const { worked: strengthOrder } = rankOf(strength)
|
||||
const detrained = strengthOrder.filter(slug => strength[slug] < 1)
|
||||
const strengthHint = slug => {
|
||||
if (lastTrained[slug] == null) return t('not trained')
|
||||
const weeks = weeksSinceTraining(now, lastTrained[slug])
|
||||
return t('Weeks since training: {0}', weeks)
|
||||
}
|
||||
const toggleSel = m => setSel(s => (s === m ? null : m))
|
||||
const inWin = S.workouts.filter(w =>
|
||||
win === 0 ? true
|
||||
: win === 7 ? weekKey(w.d) === weekKey(todayISO())
|
||||
@@ -42,35 +126,58 @@ function MuscleBalance({ S }) {
|
||||
const sets = m => Math.round((load[m] || 0) * 10) / 10
|
||||
|
||||
return <div className="card">
|
||||
<div className="row between" style={{ marginBottom: 8 }}>
|
||||
<h2 style={{ margin: 0 }}>{t('Muscle balance')} <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· {on ? t('by hard sets') : t('by sets worked')}</span></h2>
|
||||
{rated && <Button size="sm" icon="flame" style={on ? { color: 'var(--yellow)' } : undefined}
|
||||
onClick={() => { setHard(h => !h); setSel(null) }}>{on ? t('Hard') : t('All')}</Button>}
|
||||
</div>
|
||||
<Segmented className="seg-range" value={win} onChange={v => { setWin(v); setSel(null) }}
|
||||
options={[{ value: 7, label: t('Week') }, { value: 30, label: '30d' }, { value: 90, label: '90d' }, { value: 0, label: t('All') }]} />
|
||||
{inWin.length ? <>
|
||||
<BodyMap className="tappable" load={load} body={S.body} selected={sel}
|
||||
onMuscle={m => setSel(s => (s === m ? null : m))} />
|
||||
<BodyMapLegend />
|
||||
<Segmented className="seg-range" value={view} onChange={setView}
|
||||
options={[{ value: 'balance', label: t('Muscle balance') }, { value: 'fatigue', label: t('Fatigue') }, { value: 'strength', label: t('Strength') }]} />
|
||||
{view === 'balance' ? <>
|
||||
<div className="row between" style={{ marginBottom: 8 }}>
|
||||
<h2 style={{ margin: 0 }}>{t('Muscle balance')} <span className="dim" style={{ textTransform: 'none', letterSpacing: 0 }}>· {on ? t('by hard sets') : t('by sets worked')}</span></h2>
|
||||
{rated && <Button size="sm" icon="flame" style={on ? { color: 'var(--yellow)' } : undefined}
|
||||
onClick={() => { setHard(h => !h); setSel(null) }}>{on ? t('Hard') : t('All')}</Button>}
|
||||
</div>
|
||||
<Segmented className="seg-range" value={win} onChange={v => { setWin(v); setSel(null) }}
|
||||
options={[{ value: 7, label: t('Week') }, { value: 30, label: '30d' }, { value: 90, label: '90d' }, { value: 0, label: t('All') }]} />
|
||||
{inWin.length ? <>
|
||||
<BodyMap className="tappable" load={load} body={S.body} selected={sel}
|
||||
onMuscle={m => setSel(s => (s === m ? null : m))} />
|
||||
<BodyMapLegend />
|
||||
{sel && <div className="mrow" style={{ borderTop: 'var(--hair) solid var(--sep)', marginTop: 4, paddingTop: 10 }}>
|
||||
<span className="nm"><b>{t(MUSCLE_NAME[sel])}</b></span>
|
||||
<span className="v">{sets(sel) ? t('{0} sets', sets(sel)) : on ? t('no hard sets') : t('not trained')}</span>
|
||||
</div>}
|
||||
{!sel && top.map(m => <div key={m} className="mrow">
|
||||
<span className="nm">{t(MUSCLE_NAME[m])}</span>
|
||||
<span className="bar"><i style={{ width: Math.round(load[m] / max * 100) + '%', background: on ? 'var(--yellow)' : undefined }} /></span>
|
||||
<span className="v">{t('{0} sets', sets(m))}</span>
|
||||
</div>)}
|
||||
{missed.length > 0 && <>
|
||||
<h4 className="sec" style={{ marginTop: 12 }}>{on ? t('No hard sets in this period') : t('Not trained in this period')}</h4>
|
||||
<div className="mchips">{missed.map(m => <span key={m} className="mchip miss">{t(MUSCLE_NAME[m])}</span>)}</div>
|
||||
</>}
|
||||
{!missed.length && worked.length > 0 &&
|
||||
<div className="muted small" style={{ marginTop: 10 }}>{on
|
||||
? t('Every muscle group got at least one hard set in this period.')
|
||||
: t('Every muscle group got some work in this period.')}</div>}
|
||||
</> : <div className="muted small">{t('No workouts in this period yet.')}</div>}
|
||||
</> : view === 'fatigue' ? <>
|
||||
<h2>{t('Fatigue')}</h2>
|
||||
<BodyMap className="tappable" load={fatigue} thresholds={FATIGUE_LEVELS} body={S.body} selected={sel} onMuscle={toggleSel} />
|
||||
<FatigueLegend />
|
||||
<div className="muted small" style={{ marginTop: 10 }}>{t('Fatigue shows how recently each muscle was trained. High means rest.')}</div>
|
||||
{sel && <div className="mrow" style={{ borderTop: 'var(--hair) solid var(--sep)', marginTop: 4, paddingTop: 10 }}>
|
||||
<span className="nm"><b>{t(MUSCLE_NAME[sel])}</b></span>
|
||||
<span className="v">{sets(sel) ? t('{0} sets', sets(sel)) : on ? t('no hard sets') : t('not trained')}</span>
|
||||
<span className="v">{fatigueLabel(fatigue[sel])}</span>
|
||||
</div>}
|
||||
{!sel && top.map(m => <div key={m} className="mrow">
|
||||
<span className="nm">{t(MUSCLE_NAME[m])}</span>
|
||||
<span className="bar"><i style={{ width: Math.round(load[m] / max * 100) + '%', background: on ? 'var(--yellow)' : undefined }} /></span>
|
||||
<span className="v">{t('{0} sets', sets(m))}</span>
|
||||
</> : <>
|
||||
<h2>{t('Strength')}</h2>
|
||||
<BodyMap className="tappable" load={strength} thresholds={STRENGTH_LEVELS} body={S.body} selected={sel} onMuscle={toggleSel} />
|
||||
<StrengthLegend />
|
||||
<div className="muted small" style={{ marginTop: 10 }}>{t('Strength shows retained muscle strength. Train again to reset it.')}</div>
|
||||
{detrained.map(slug => <div key={slug} className="mrow">
|
||||
<span className="nm">{t(MUSCLE_NAME[slug])}</span>
|
||||
<span className="bar"><i style={{ width: Math.round(strength[slug] * 100) + '%' }} /></span>
|
||||
<span className="v">{strengthHint(slug)}</span>
|
||||
</div>)}
|
||||
{missed.length > 0 && <>
|
||||
<h4 className="sec" style={{ marginTop: 12 }}>{on ? t('No hard sets in this period') : t('Not trained in this period')}</h4>
|
||||
<div className="mchips">{missed.map(m => <span key={m} className="mchip miss">{t(MUSCLE_NAME[m])}</span>)}</div>
|
||||
</>}
|
||||
{!missed.length && worked.length > 0 &&
|
||||
<div className="muted small" style={{ marginTop: 10 }}>{on
|
||||
? t('Every muscle group got at least one hard set in this period.')
|
||||
: t('Every muscle group got some work in this period.')}</div>}
|
||||
</> : <div className="muted small">{t('No workouts in this period yet.')}</div>}
|
||||
</>}
|
||||
</div>
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,300 @@
|
||||
import React, { act } from 'react'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { parseHTML } from 'linkedom'
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { MUSCLES, MUSCLE_NAME, levelsOf, rankOf } from '../lib/muscles.js'
|
||||
import { FATIGUE_STATES, STRENGTH_FLOOR } from '../lib/recovery.js'
|
||||
import { fatigueStateOf } from '../lib/recovery-view.js'
|
||||
import Stats, { weeksSinceTraining } from './Stats.jsx'
|
||||
|
||||
const DAY = 86400000
|
||||
const HOUR = 3600000
|
||||
const BASE_NOW = Date.UTC(2026, 0, 22, 12)
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
maps: [],
|
||||
mapMounts: 0,
|
||||
S: {
|
||||
unit: 'kg', body: 'male', effort: 'rir', targetW: null,
|
||||
bodyweight: [], routines: [], workouts: [],
|
||||
},
|
||||
}))
|
||||
|
||||
vi.mock('../store/useStore.js', () => ({
|
||||
useStore: selector => selector({ S: mocks.S }),
|
||||
}))
|
||||
vi.mock('react-router-dom', () => ({ useNavigate: () => () => {} }))
|
||||
vi.mock('../sheets.jsx', () => ({
|
||||
bwSheet: () => {}, goalSheet: () => {}, calendarSheet: () => {}, workoutDetailSheet: () => {},
|
||||
WorkoutRow: () => React.createElement('div'), bwDeltaColor: () => 'inherit',
|
||||
}))
|
||||
vi.mock('../components/LineChart.jsx', () => ({ default: () => React.createElement('div') }))
|
||||
vi.mock('../components/Heatmap.jsx', () => ({ default: () => React.createElement('div') }))
|
||||
vi.mock('../components/Icon.jsx', () => ({ default: props => React.createElement('span', props) }))
|
||||
vi.mock('../components/BodyMap.jsx', () => ({
|
||||
default: props => {
|
||||
mocks.maps.push(props)
|
||||
React.useEffect(() => {
|
||||
mocks.mapMounts++
|
||||
return () => {}
|
||||
}, [])
|
||||
return React.createElement(
|
||||
'div',
|
||||
{ 'data-body-map': true, 'data-selected-muscle': props.selected || '' },
|
||||
React.createElement('button', {
|
||||
'data-muscle': 'chest',
|
||||
onClick: () => props.onMuscle?.('chest'),
|
||||
}, 'Chest'),
|
||||
)
|
||||
},
|
||||
BodyMapLegend: () => React.createElement('div', { 'data-balance-legend': true }),
|
||||
}))
|
||||
|
||||
let dom
|
||||
let root
|
||||
let container
|
||||
|
||||
function iso(timestamp) {
|
||||
return new Date(timestamp).toISOString().slice(0, 10)
|
||||
}
|
||||
|
||||
function set(done, extra = {}) {
|
||||
return { done, w: 10, r: 8, ...extra }
|
||||
}
|
||||
|
||||
function workout(id, start, entries) {
|
||||
return { id, d: iso(start), start, entries }
|
||||
}
|
||||
|
||||
function entry(id, sets) {
|
||||
return { id, sets }
|
||||
}
|
||||
|
||||
function lifecycleWorkouts(now = BASE_NOW) {
|
||||
// The 36-hour fatigue edge crosses .5 after one 60-second interval tick.
|
||||
const fatigueEdge = now - (36 * HOUR - 30000)
|
||||
// This completed set is in the initial 30-day Balance window, then ages out after one tick.
|
||||
const balanceEdge = now - (30 * DAY - 30000)
|
||||
// The 14-day strength edge becomes sub-full after one tick.
|
||||
const strengthEdge = now - (14 * DAY - 30000)
|
||||
// This completed event must remain the latest training event for abs: the newer set is undone.
|
||||
const absCompleted = now - 20 * DAY
|
||||
const absUndone = now - DAY
|
||||
return [
|
||||
workout('fatigue-edge', fatigueEdge, [entry('1254', [set(true, { rir: 0 })])]),
|
||||
workout('balance-edge', balanceEdge, [entry('1254', [set(true, { rir: 2 })])]),
|
||||
workout('strength-edge', strengthEdge, [entry('1001', [set(true, { rir: 2 })])]),
|
||||
workout('abs-completed', absCompleted, [entry('1002', [set(true, { rir: 2 })])]),
|
||||
workout('abs-undone', absUndone, [entry('1002', [set(false, { rir: 0 })])]),
|
||||
]
|
||||
}
|
||||
|
||||
function allFatiguedWorkout(now = BASE_NOW) {
|
||||
// Primary muscles have one completed set. The three secondary-only map slugs have two
|
||||
// completed sets so their .4 weights are also above the production .5 fatigue boundary.
|
||||
const ids = [
|
||||
['1018', 1], // trapezius
|
||||
['1012', 1], // deltoids
|
||||
['1167', 1], // chest
|
||||
['1013', 1], // upper-back
|
||||
['3011', 1], // serratus
|
||||
['1413', 1], // biceps
|
||||
['1399', 1], // triceps
|
||||
['1016', 1], // forearm
|
||||
['1005', 2], // abs + obliques
|
||||
['1010', 1], // lower-back
|
||||
['1003', 1], // gluteal
|
||||
['1001', 1], // quadriceps
|
||||
['1511', 1], // hamstring
|
||||
['1494', 1], // adductors
|
||||
['1002', 2], // abs + hip-flexors
|
||||
['1000', 1], // calves
|
||||
['1396', 2], // calves + tibialis
|
||||
]
|
||||
return workout('all-fatigued', now, ids.map(([id, count]) => entry(id, Array.from({ length: count }, () => set(true)))))
|
||||
}
|
||||
|
||||
function allSubfullWorkout(now = BASE_NOW) {
|
||||
return workout('all-subfull', now - 15 * DAY, [entry('1254', [set(true)])])
|
||||
}
|
||||
|
||||
function resetFixture(workouts = lifecycleWorkouts()) {
|
||||
mocks.S.workouts = workouts
|
||||
mocks.maps.length = 0
|
||||
mocks.mapMounts = 0
|
||||
}
|
||||
|
||||
function installDom() {
|
||||
const parsed = parseHTML('<!doctype html><html><body><div id="root"></div></body></html>')
|
||||
dom = parsed.window
|
||||
globalThis.window = dom
|
||||
globalThis.document = dom.document
|
||||
Object.defineProperty(globalThis, 'navigator', { configurable: true, value: dom.navigator })
|
||||
for (const key of ['HTMLElement', 'Node', 'Element', 'Event']) globalThis[key] = dom[key]
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
container = document.getElementById('root')
|
||||
root = createRoot(container)
|
||||
}
|
||||
|
||||
async function mountStats() {
|
||||
installDom()
|
||||
await act(async () => { root.render(React.createElement(Stats)) })
|
||||
}
|
||||
|
||||
async function unmountStats() {
|
||||
if (!root) return
|
||||
await act(async () => { root.unmount() })
|
||||
root = null
|
||||
container = null
|
||||
dom = null
|
||||
}
|
||||
|
||||
function muscleCard() {
|
||||
return [...container.querySelectorAll('.card')].find(card =>
|
||||
[...card.querySelectorAll('.seg button')].some(button =>
|
||||
['Muscle balance', 'Fatigue', 'Strength'].includes(button.textContent.trim())))
|
||||
}
|
||||
|
||||
function buttonWithText(scope, text) {
|
||||
return [...scope.querySelectorAll('button')].find(button => button.textContent.trim() === text)
|
||||
}
|
||||
|
||||
function viewButton(text) {
|
||||
return buttonWithText(muscleCard(), text)
|
||||
}
|
||||
|
||||
function balanceRangeButton(text) {
|
||||
const segments = muscleCard().querySelectorAll('.seg')
|
||||
return buttonWithText(segments[1], text)
|
||||
}
|
||||
|
||||
async function click(button) {
|
||||
expect(button, `expected a button named ${button?.textContent || 'unknown'}`).toBeTruthy()
|
||||
await act(async () => { button.dispatchEvent(new dom.Event('click', { bubbles: true })) })
|
||||
}
|
||||
|
||||
async function tick(milliseconds) {
|
||||
await act(async () => { await vi.advanceTimersByTimeAsync(milliseconds) })
|
||||
}
|
||||
|
||||
function lastMap() {
|
||||
return mocks.maps.at(-1)
|
||||
}
|
||||
|
||||
function expectPressed(button) {
|
||||
expect(button?.getAttribute('aria-pressed')).toBe('true')
|
||||
}
|
||||
|
||||
function strengthRows() {
|
||||
return [...muscleCard().querySelectorAll('.mrow .nm')].map(node => node.textContent.trim())
|
||||
}
|
||||
|
||||
afterEach(async () => {
|
||||
await unmountStats()
|
||||
vi.useRealTimers()
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
vi.setSystemTime(BASE_NOW)
|
||||
resetFixture()
|
||||
})
|
||||
|
||||
describe('Stats muscle recovery view runtime', () => {
|
||||
it('starts in Balance and preserves range, hard filter, and selected muscle through every real view transition', async () => {
|
||||
await mountStats()
|
||||
const card = muscleCard()
|
||||
|
||||
expectPressed(buttonWithText(card, 'Muscle balance'))
|
||||
expectPressed(buttonWithText(card, 'Week'))
|
||||
|
||||
await click(balanceRangeButton('30d'))
|
||||
await click(buttonWithText(card, 'All'))
|
||||
await click(card.querySelector('[data-muscle="chest"]'))
|
||||
expectPressed(balanceRangeButton('30d'))
|
||||
expect(buttonWithText(muscleCard(), 'Hard')).toBeTruthy()
|
||||
expect(container.querySelector('[data-selected-muscle="chest"]')).toBeTruthy()
|
||||
|
||||
await click(viewButton('Fatigue'))
|
||||
expect(container.textContent).toContain('Fatigue shows how recently each muscle was trained. High means rest.')
|
||||
await click(viewButton('Strength'))
|
||||
expect(container.textContent).toContain('Strength shows retained muscle strength. Train again to reset it.')
|
||||
await click(viewButton('Muscle balance'))
|
||||
|
||||
expectPressed(balanceRangeButton('30d'))
|
||||
expect(buttonWithText(muscleCard(), 'Hard')).toBeTruthy()
|
||||
expect(container.querySelector('[data-selected-muscle="chest"]')).toBeTruthy()
|
||||
expect(lastMap().selected).toBe('chest')
|
||||
expect(lastMap().load.chest).toBe(2)
|
||||
})
|
||||
|
||||
it('refreshes fatigue presentation, Balance 30-day filtering, and the mounted tree on the 60-second tick', async () => {
|
||||
await mountStats()
|
||||
await click(balanceRangeButton('30d'))
|
||||
await click(viewButton('Fatigue'))
|
||||
await click(muscleCard().querySelector('[data-muscle="chest"]'))
|
||||
|
||||
const beforeTickMounts = mocks.mapMounts
|
||||
const beforeTick = lastMap().load.chest
|
||||
expect(fatigueStateOf(beforeTick)).toBe(FATIGUE_STATES.FATIGUED)
|
||||
expect(container.textContent).toContain('Fatigued')
|
||||
|
||||
await tick(60000)
|
||||
|
||||
const afterTick = lastMap().load.chest
|
||||
expect(mocks.mapMounts).toBe(beforeTickMounts)
|
||||
expect(afterTick).toBeLessThan(0.5)
|
||||
expect(fatigueStateOf(afterTick)).toBe(FATIGUE_STATES.RECOVERING)
|
||||
expect(container.textContent).toContain('Recovering')
|
||||
|
||||
await click(viewButton('Strength'))
|
||||
expect(lastMap().load.quadriceps).toBeLessThan(1)
|
||||
expect(strengthRows()).toContain('Quads')
|
||||
|
||||
await click(viewButton('Muscle balance'))
|
||||
expect(lastMap().load.chest).toBe(1)
|
||||
expectPressed(balanceRangeButton('30d'))
|
||||
})
|
||||
|
||||
it('ignores an undone latest set, floors rendered training age, and follows production rankOf ordering', async () => {
|
||||
await mountStats()
|
||||
await click(viewButton('Strength'))
|
||||
|
||||
const load = lastMap().load
|
||||
const expectedRows = rankOf(load).worked
|
||||
.filter(slug => load[slug] < 1)
|
||||
.map(slug => MUSCLE_NAME[slug])
|
||||
expect(strengthRows()).toEqual(expectedRows)
|
||||
|
||||
// The newer abs row is undone, so the rendered hint uses the completed event from 20 days ago.
|
||||
expect(container.textContent).toContain('Weeks since training: 2')
|
||||
|
||||
// The production helper used by Stats' rendered strength hint floors six elapsed days to zero.
|
||||
expect(weeksSinceTraining(BASE_NOW, BASE_NOW - 6 * DAY)).toBe(0)
|
||||
})
|
||||
|
||||
it('uses production boundaries and fixed absolute bands for all-fatigued and all-subfull maps', async () => {
|
||||
expect(fatigueStateOf(0.2499)).toBe(FATIGUE_STATES.READY)
|
||||
expect(fatigueStateOf(0.25)).toBe(FATIGUE_STATES.RECOVERING)
|
||||
expect(fatigueStateOf(0.5)).toBe(FATIGUE_STATES.RECOVERING)
|
||||
expect(fatigueStateOf(0.5001)).toBe(FATIGUE_STATES.FATIGUED)
|
||||
|
||||
resetFixture([allFatiguedWorkout()])
|
||||
await mountStats()
|
||||
await click(viewButton('Fatigue'))
|
||||
const fatigueMap = lastMap()
|
||||
expect(Object.keys(fatigueMap.load)).toEqual(MUSCLES)
|
||||
expect(Object.values(fatigueMap.load).every(value => value > 0.5)).toBe(true)
|
||||
expect(Object.values(levelsOf(fatigueMap.load, fatigueMap.thresholds)).every(level => level === 0)).toBe(true)
|
||||
|
||||
await unmountStats()
|
||||
resetFixture([allSubfullWorkout()])
|
||||
await mountStats()
|
||||
await click(viewButton('Strength'))
|
||||
const strengthMap = lastMap()
|
||||
expect(Object.values(strengthMap.load).every(value => value < 1)).toBe(true)
|
||||
expect(Math.min(...Object.values(strengthMap.load))).toBe(STRENGTH_FLOOR)
|
||||
expect(strengthMap.thresholds.at(-1)).toEqual({ at: 1, level: 4 })
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user