Merge !102: Workout view: Allow multiple routines
This commit is contained in:
commit
b4feea6a2e
36 files changed
+1683
-174
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { useState } from 'react'
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { effectiveRoutine, effectiveRoutineId, nextTrainingDay, streakWeeks, lastBW, setsDoneActive } from '../lib/history.js'
|
||||
import { effectiveRoutines, effectiveRoutineIds, nextTrainingDay, streakWeeks, lastBW, setsDoneActive } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, todayISO, isoOf, weekKey, weekStartOf, weekDayOffset, DAYS, DAYN } from '../lib/format.js'
|
||||
import { t, dateLocale } from '../lib/i18n.js'
|
||||
import { bwSheet, goalSheet, dayOverrideSheet, calendarSheet, startFlow, starterPlanSheet, bwDeltaColor } from '../sheets.jsx'
|
||||
@@ -19,10 +19,14 @@ export default function Home() {
|
||||
const [weekOffset, setWeekOffset] = useState(0)
|
||||
|
||||
const today = new Date()
|
||||
const routine = effectiveRoutine(S, todayISO())
|
||||
// A weekday can hold several routines. `todayRoutines` is the whole day; `routine` is the
|
||||
// first, kept for the one-routine glyph. The derived session name joins them (§9).
|
||||
const todayRoutines = effectiveRoutines(S, todayISO())
|
||||
const routine = todayRoutines[0] || null
|
||||
const todayName = todayRoutines.map(r => r.name).join(' + ')
|
||||
const todayOvr = S.dayPlan[todayISO()] !== undefined
|
||||
// On a rest day, saying when you train next beats leaving the row as a full stop.
|
||||
const next = !S.active && !routine ? nextTrainingDay(S, todayISO()) : null
|
||||
const next = !S.active && !todayRoutines.length ? nextTrainingDay(S, todayISO()) : null
|
||||
const bw = lastBW(S)
|
||||
const prevBW = S.bodyweight.length > 1 ? S.bodyweight[S.bodyweight.length - 2] : null
|
||||
const delta = bw && prevBW ? bw.w - prevBW.w : null
|
||||
@@ -40,7 +44,7 @@ export default function Home() {
|
||||
for (let i = 0; i < 7; i++) {
|
||||
const d = new Date(wkStart); d.setDate(wkStart.getDate() + i)
|
||||
const iso = isoOf(d)
|
||||
const eff = effectiveRoutineId(S, iso), ovr = S.dayPlan[iso] !== undefined, done = doneDays.has(iso)
|
||||
const eff = effectiveRoutineIds(S, iso).length > 0, ovr = S.dayPlan[iso] !== undefined, done = doneDays.has(iso)
|
||||
const dot = done ? ' done' : ovr && eff ? ' ovr' : eff ? ' plan' : ''
|
||||
strip.push(<div key={i} className={'wday' + (iso === todayISO() ? ' today' : '')} {...tappable(() => dayOverrideSheet(iso))}>
|
||||
<div className="lbl">{t(DAYS[d.getDay()])}</div><div className="num">{d.getDate()}</div><div className={'dot' + dot} /></div>)
|
||||
@@ -49,11 +53,12 @@ export default function Home() {
|
||||
const wkLabel = weekOffset === 0 ? t('This week') : `${wkStart.getDate()} ${wkStart.toLocaleDateString(dateLocale(), { month: 'short' })} – ${wkEnd.getDate()} ${wkEnd.toLocaleDateString(dateLocale(), { month: 'short' })}`
|
||||
|
||||
const wThisWeek = S.workouts.filter(w => weekKey(w.d, ws) === weekKey(todayISO(), ws)).length
|
||||
const plannedPerWeek = Object.keys(S.week).filter(k => S.week[k]).length
|
||||
// Days scheduled, not routines — a combined day counts as 1, matching wThisWeek (one w).
|
||||
const plannedPerWeek = Object.values(S.week).filter(ids => ids?.length).length
|
||||
const bwPoints = S.bodyweight.slice(-30).map(b => ({ t: b.t || new Date(b.d).getTime(), y: b.w, d: b.d }))
|
||||
|
||||
// today's session shown right under the week strip
|
||||
const onToday = () => { if (S.active) nav('/workout'); else if (routine) startFlow(routine.id); else dayOverrideSheet(todayISO()) }
|
||||
const onToday = () => { if (S.active) nav('/workout'); else if (todayRoutines.length) startFlow(effectiveRoutineIds(S, todayISO())); else dayOverrideSheet(todayISO()) }
|
||||
|
||||
return <div className="narrow">
|
||||
<div className="hdr">
|
||||
@@ -83,7 +88,7 @@ export default function Home() {
|
||||
<div className="lbl2">{t('Today')}</div>
|
||||
<div className="ttl">{S.active ? t('{0} — in progress', S.active.name)
|
||||
: doneToday ? (doneToday.name ? t('{0} — done', doneToday.name) : t('Workout done'))
|
||||
: routine ? routine.name : t('Rest day')}{todayOvr && routine && !doneToday ? ' · ' + t('rescheduled') : ''}</div>
|
||||
: routine ? todayName : t('Rest day')}{todayOvr && routine && !doneToday ? ' · ' + t('rescheduled') : ''}</div>
|
||||
{next && !doneToday && <div className="ss">{t('Next session: {0}, {1}', t(DAYN[next.weekday]), next.routine.name)}</div>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -2,7 +2,7 @@ import { useNavigate } from 'react-router-dom'
|
||||
import { useStore } from '../store/useStore.js'
|
||||
import { DAYN, weekOrder, weekStartOf, uid, exCount } from '../lib/format.js'
|
||||
import { t } from '../lib/i18n.js'
|
||||
import { dayAssignSheet, starterPlanSheet, planToolsSheet } from '../sheets.jsx'
|
||||
import { dayAssignSheet, dayAddRoutineSheet, starterPlanSheet, planToolsSheet } from '../sheets.jsx'
|
||||
import Icon from '../components/Icon.jsx'
|
||||
import { Button } from '../components/ui.jsx'
|
||||
import { tappable } from '../lib/use-sheet-keyboard.js'
|
||||
@@ -31,6 +31,12 @@ export default function Plan() {
|
||||
nav('/plan/r/' + r.id)
|
||||
}
|
||||
|
||||
// Pull one routine off a weekday; drop the key when the day empties (never store []).
|
||||
const removeFromDay = (d, rid) => update(s => {
|
||||
const next = [].concat(s.week[d] || []).filter(id => id !== rid)
|
||||
if (next.length) s.week[d] = next; else delete s.week[d]
|
||||
})
|
||||
|
||||
return <>
|
||||
<div className="hdr">
|
||||
<div><h1>{t('Plan')}</h1><div className="sub">{t('Your weekly routine')}</div></div>
|
||||
@@ -49,11 +55,27 @@ export default function Plan() {
|
||||
<h4 className="sec">{t('Week schedule')}</h4>
|
||||
<div className="list" style={{ display: 'flex', flexDirection: 'column' }}>
|
||||
{weekOrder(weekStartOf(S)).map(d => {
|
||||
const r = S.routines.find(x => x.id === S.week[d])
|
||||
return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}>
|
||||
const dayRoutines = [].concat(S.week[d] || []).map(id => S.routines.find(x => x.id === id)).filter(Boolean)
|
||||
// An empty day stays one tappable row → pick its first routine (today's behaviour).
|
||||
if (!dayRoutines.length) return <div key={d} className="item" {...tappable(() => dayAssignSheet(d))}>
|
||||
<div className="grow"><div className="tt">{t(DAYN[d])}</div></div>
|
||||
{r ? <span className="tag acc"><Icon name={glyphOf(r.emoji)} />{r.name}</span> : <span className="tag">{t('Rest')}</span>}
|
||||
<span className="tag">{t('Rest')}</span>
|
||||
<Icon name="chevronRight" className="chev" /></div>
|
||||
// A populated day: always-visible routine sub-rows + inline ✕, then + Add routine.
|
||||
return <div key={d} className="item" style={{ display: 'block', padding: '10px 14px' }}>
|
||||
<div className="row between" style={{ marginBottom: 6 }}>
|
||||
<div className="tt">{t(DAYN[d])}</div>
|
||||
<div className="small dim">{t('{0} routines', dayRoutines.length)}</div>
|
||||
</div>
|
||||
{dayRoutines.map(r => <div key={r.id} className="row" style={{ gap: 8, padding: '4px 0 4px 8px' }}>
|
||||
<span className="lrow-i" style={{ width: 26, height: 26, fontSize: 14 }}><Icon name={glyphOf(r.emoji)} /></span>
|
||||
<div className="grow" style={{ minWidth: 0 }}><div className="tt" style={{ fontSize: 14 }}>{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
|
||||
<button className="iconbtn sm" aria-label={t('Remove')} onClick={() => removeFromDay(d, r.id)}><Icon name="xmark" /></button>
|
||||
</div>)}
|
||||
<button className="btn ghost sm" style={{ marginTop: 4, marginLeft: 8 }} onClick={() => dayAddRoutineSheet(d)}>
|
||||
<Icon name="plus" /> {t('Add routine')}
|
||||
</button>
|
||||
</div>
|
||||
})}
|
||||
</div>
|
||||
</div><div>
|
||||
|
||||
@@ -450,7 +450,12 @@ export default function RoutineEdit() {
|
||||
onConfirm: () => {
|
||||
update(s => {
|
||||
s.routines = s.routines.filter(x => x.id !== id)
|
||||
Object.keys(s.week).forEach(k => { if (s.week[k] === id) delete s.week[k] })
|
||||
// A weekday holds a routine-id list: pull the deleted id from each day, drop the
|
||||
// key when it empties (never store []). dayPlan stays scalar.
|
||||
Object.keys(s.week).forEach(k => {
|
||||
const next = [].concat(s.week[k]).filter(rid => rid !== id)
|
||||
if (next.length) s.week[k] = next; else delete s.week[k]
|
||||
})
|
||||
Object.keys(s.dayPlan).forEach(k => { if (s.dayPlan[k] === id) delete s.dayPlan[k] })
|
||||
})
|
||||
nav('/plan')
|
||||
|
||||
@@ -5,14 +5,14 @@ import { workoutControls } from '../lib/workout-controls.js'
|
||||
import { useUI } from '../store/useUI.js'
|
||||
import { exOr } from '../lib/exercises.js'
|
||||
import { usesBar, barWeightFor, plateSplit } from '../lib/bar.js'
|
||||
import { effectiveRoutine, lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, freestyleConfig, defaultConfig, setsDoneActive, setUnitsTotal, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from '../lib/history.js'
|
||||
import { effectiveRoutines, effectiveRoutineIds, lastEntryFor, bestWeightFor, bestWeightForEntry, buildSets, freestyleConfig, defaultConfig, setsDoneActive, setUnitsTotal, supersetUnits, unitOf, setLabel, modeOf, isBw, isPerSide, repStep, EFFORT, effortOf, stepEffort, capEffort, cascadeWeight, insertWarmupRow, removeRowAt, pairAdjacent, unpairSuperset, cleanupSg, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from '../lib/history.js'
|
||||
import { fmtNum, fmtDate, todayISO, exCount, DAYN } from '../lib/format.js'
|
||||
import { beep, vibrate } from '../lib/sound.js'
|
||||
import { t, exerciseNameFor } from '../lib/i18n.js'
|
||||
import { api } from '../lib/api.js'
|
||||
import { insertionIndexAfterCurrentUnit, nextUnfinishedUnit, setProgressHighWater, supersetFlowStep, restAfterSet, restOnRecheck, restSecFor } from '../lib/supersetFlow.js'
|
||||
import Media from '../components/Media.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet } from '../sheets.jsx'
|
||||
import { startFlow, exercisePicker, exConfigSheet, exerciseDetailSheet, finishWorkout, workoutCompleteSheet, confirmSheet, exerciseNoteSheet, sessionNoteSheet, swapActiveWorkoutExercise, barWeightSheet, menuSheet, effortPickerSheet, exerciseHistorySheet, addRoutineToSessionSheet } from '../sheets.jsx'
|
||||
import { effortColor } from '../lib/effort.js'
|
||||
import Icon from '../components/Icon.jsx'
|
||||
import { Button, Check, NumberField } from '../components/ui.jsx'
|
||||
@@ -30,26 +30,29 @@ const SWIPE_IGNORED_TARGETS = 'button,input,textarea,select,a,[role="button"],[r
|
||||
function StartChooser() {
|
||||
const nav = useNavigate()
|
||||
const S = useStore(s => s.S)
|
||||
const todayR = effectiveRoutine(S, todayISO())
|
||||
const todayIds = effectiveRoutineIds(S, todayISO())
|
||||
const todayRoutines = effectiveRoutines(S, todayISO())
|
||||
const todayName = todayRoutines.map(r => r.name).join(' + ')
|
||||
const todayOvr = S.dayPlan[todayISO()] !== undefined
|
||||
const others = S.routines.filter(r => r !== todayR)
|
||||
const idSet = new Set(todayIds)
|
||||
const others = S.routines.filter(r => !idSet.has(r.id))
|
||||
return <div className="narrow">
|
||||
<div className="hdr"><div><h1>{t('Start workout')}</h1><div className="sub">{t(DAYN[new Date().getDay()])} — {todayR ? t('today is {0}', todayR.name) : t('rest day, but no one’s stopping you')}</div></div></div>
|
||||
{todayR && <div className="card" style={{ borderColor: 'var(--acc)' }}>
|
||||
<div className="hdr"><div><h1>{t('Start workout')}</h1><div className="sub">{t(DAYN[new Date().getDay()])} — {todayRoutines.length ? t('today is {0}', todayName) : t('rest day, but no one’s stopping you')}</div></div></div>
|
||||
{todayRoutines.length > 0 && <div className="card" style={{ borderColor: 'var(--acc)' }}>
|
||||
<h2 className="accent">{t("Today's plan")}{todayOvr ? ' · ' + t('rescheduled') : ''}</h2>
|
||||
<div className="row between" style={{ marginBottom: 12 }}>
|
||||
<div><div className="big">{todayR.name}</div><div className="muted small">{exCount(todayR.ex.length)}</div></div>
|
||||
<span className="lrow-i" style={{ width: 38, height: 38, borderRadius: 9, fontSize: 22 }}><Icon name={glyphOf(todayR.emoji)} /></span>
|
||||
<div><div className="big">{todayName}</div><div className="muted small">{exCount(todayRoutines.reduce((n, r) => n + r.ex.length, 0))}</div></div>
|
||||
<span className="lrow-i" style={{ width: 38, height: 38, borderRadius: 9, fontSize: 22 }}><Icon name={glyphOf(todayRoutines[0].emoji)} /></span>
|
||||
</div>
|
||||
<Button variant="primary" icon="play" onClick={() => startFlow(todayR.id)}>{t('Start {0}', todayR.name)}</Button>
|
||||
<Button variant="primary" icon="play" onClick={() => startFlow(todayIds)}>{t('Start {0}', todayName)}</Button>
|
||||
</div>}
|
||||
{others.length > 0 && <><h4 className="sec">{t('Other routines')}</h4>
|
||||
<div className="list">{others.map(r => <div key={r.id} className="item" onClick={() => startFlow(r.id)}>
|
||||
<div className="list">{others.map(r => <div key={r.id} className="item" onClick={() => startFlow([r.id])}>
|
||||
<span className="lrow-i"><Icon name={glyphOf(r.emoji)} /></span>
|
||||
<div className="grow"><div className="tt">{r.name}</div><div className="ss">{exCount(r.ex.length)}</div></div>
|
||||
<span className="tag acc">{t('Start')}</span></div>)}</div></>}
|
||||
<div style={{ height: 14 }} />
|
||||
<Button icon="shuffle" onClick={() => startFlow(null)}>{t('Freestyle workout (pick as you go)')}</Button>
|
||||
<Button icon="shuffle" onClick={() => startFlow([])}>{t('Freestyle workout (pick as you go)')}</Button>
|
||||
{!S.routines.length && <><div style={{ height: 10 }} /><Button variant="primary" onClick={() => nav('/plan')}>{t('Build a plan first')}</Button></>}
|
||||
</div>
|
||||
}
|
||||
@@ -681,14 +684,23 @@ function ActiveWorkout() {
|
||||
// (Settings → During a workout → Workout view). It writes s.active.workoutView, which the
|
||||
// render above prefers over S.workoutView.
|
||||
const setWorkoutView = v => update(s => { if (s.active) s.active.workoutView = v })
|
||||
const openViewMenu = () => menuSheet({
|
||||
title: t('Workout view'),
|
||||
const LAYOUT_LABEL = { cards: t('Cards'), list: t('List'), compact: t('Compact') }
|
||||
const openLayoutMenu = () => menuSheet({
|
||||
title: t('Layout'),
|
||||
items: [
|
||||
{ icon: 'clipboard', label: t('Cards'), on: workoutView === 'cards', onClick: () => setWorkoutView('cards') },
|
||||
{ icon: 'list', label: t('List'), on: workoutView === 'list', onClick: () => setWorkoutView('list') },
|
||||
{ icon: 'minimize', label: t('Compact'), on: workoutView === 'compact', onClick: () => setWorkoutView('compact') },
|
||||
],
|
||||
})
|
||||
// The header ⋮: bring another routine into the session, then the layout switch nested a
|
||||
// level down (it used to be the whole menu).
|
||||
const openViewMenu = () => menuSheet({
|
||||
items: [
|
||||
{ icon: 'plus', label: t('Add routine'), sub: t('Bring another routine into this session'), onClick: addRoutineToSessionSheet },
|
||||
{ icon: 'list', label: t('Layout'), sub: LAYOUT_LABEL[workoutView] || LAYOUT_LABEL.cards, onClick: openLayoutMenu },
|
||||
],
|
||||
})
|
||||
const onSwipePointerDown = event => {
|
||||
if (swipe.current || (event.pointerType && event.pointerType !== 'touch' && event.pointerType !== 'pen')) return
|
||||
if (event.target.closest?.(SWIPE_IGNORED_TARGETS)) return
|
||||
@@ -714,7 +726,9 @@ function ActiveWorkout() {
|
||||
const activeId = state.active.id
|
||||
const entryId = entry.id
|
||||
const entryCount = state.active.entries.length
|
||||
const routine = state.routines.find(r => r.id === state.active.routineId)
|
||||
// A combined session's entries each carry a `rid`; progression settings read from that
|
||||
// entry's own routine, not a session-wide one.
|
||||
const routine = state.routines.find(r => r.id === entry.rid)
|
||||
exConfigSheet(exOr(entryId), entry.target, cfg => {
|
||||
// Store updates clone the state tree. If this exact object is no longer at the captured
|
||||
// index, the list changed while the sheet was open; an id check alone cannot distinguish
|
||||
@@ -730,7 +744,7 @@ function ActiveWorkout() {
|
||||
// happens to occupy the same index.
|
||||
if (!activeEntry || activeEntry.id !== entryId) return
|
||||
const full = { ...cfg, id: activeEntry.id }
|
||||
const activeRoutine = s.routines.find(r => r.id === s.active.routineId)
|
||||
const activeRoutine = s.routines.find(r => r.id === activeEntry.rid)
|
||||
const step = modeOf(full) === 'reps' ? weightIncrement(full, s.unit) : defaultIncrement(activeEntry.id, s.unit)
|
||||
// A config without a set count keeps the rows the session already has.
|
||||
if (!(full.sets > 0)) full.sets = activeEntry.sets.filter(x => !isWarmupRow(x)).length || 1
|
||||
@@ -990,15 +1004,20 @@ function ActiveWorkout() {
|
||||
{!listMode && <div style={{ height: 10 }} />}
|
||||
{wc.exerciseButtons && listMode && A.entries.length > 0 && <div className="muted small" style={{ marginBottom: 6 }}>{t('Move, swap and remove below act on the exercise marked {0}.', t('Current'))}</div>}
|
||||
<Button onClick={() => exercisePicker((ex, quick) => {
|
||||
const routine = S.routines.find(r => r.id === A.routineId)
|
||||
const freestyle = !A.routineId
|
||||
// A freehand add inherits the current unit's routine (its `rid`) so it lands in that
|
||||
// routine's block in a combined session and gets a real prescription; a routine-less
|
||||
// freestyle session has no `rid` to inherit. `noProg` is never set independently here —
|
||||
// the only mid-session route to an excluded entry is "Add routine".
|
||||
const curRid = A.entries[A.cur]?.rid
|
||||
const routine = curRid ? S.routines.find(r => r.id === curRid) : null
|
||||
const freestyle = !routine
|
||||
// Freestyle has no routine prescription to apply: show the last target in the config
|
||||
// sheet and carry its completed rows forward. A planned session uses its configured
|
||||
// target when progression is off, while progression-enabled sessions keep their path.
|
||||
const seed = freestyle ? freestyleConfig(S, { id: ex.id, ...defaultConfig(ex.id) }) : null
|
||||
const commit = cfg => update(s => {
|
||||
const full = { ...cfg, id: ex.id }
|
||||
const plan = freestyle ? null : nextPrescription(s, full, s.routines.find(r => r.id === s.active.routineId))
|
||||
const plan = freestyle ? null : nextPrescription(s, full, routine)
|
||||
const sets = buildSets(s, full, {
|
||||
step: modeOf(full) === 'reps' ? weightIncrement(full, s.unit) : defaultIncrement(ex.id, s.unit),
|
||||
...(freestyle ? { preferLast: true } : {}),
|
||||
@@ -1006,7 +1025,7 @@ function ActiveWorkout() {
|
||||
})
|
||||
const progressed = freestyle ? sets : applyPrescription(sets, plan, modeOf(full) === 'reps' ? weightIncrement(full, s.unit) : defaultIncrement(ex.id, s.unit))
|
||||
const insertAt = insertionIndexAfterCurrentUnit(supersetUnits(s.active.entries), s.active.cur, s.active.entries.length)
|
||||
s.active.entries.splice(insertAt, 0, { id: ex.id, target: { ...cfg }, plan, sets: applyIntensifierPlan(progressed, full) })
|
||||
s.active.entries.splice(insertAt, 0, { id: ex.id, target: { ...cfg }, plan, sets: applyIntensifierPlan(progressed, full), ...(curRid ? { rid: curRid } : {}) })
|
||||
s.active.cur = insertAt
|
||||
useUI.getState().shiftRestOwner(insertAt, 1)
|
||||
})
|
||||
|
||||
@@ -78,6 +78,7 @@ vi.mock('../sheets.jsx', () => ({
|
||||
sessionNoteSheet: vi.fn(),
|
||||
effortPickerSheet: mocks.effortPickerSheet,
|
||||
exerciseHistorySheet: mocks.exerciseHistorySheet,
|
||||
addRoutineToSessionSheet: vi.fn(),
|
||||
}))
|
||||
vi.mock('../components/Media.jsx', () => ({ default: () => null }))
|
||||
// api.js reads navigator.userAgent at module scope. This file installs its own DOM inside the
|
||||
@@ -1157,21 +1158,30 @@ describe('workout view header menu', () => {
|
||||
}
|
||||
const item = (menu, label) => menu.items.filter(Boolean).find(it => it.label === label)
|
||||
|
||||
it('offers the three layouts and marks the running session current', async () => {
|
||||
await mount([exercise('plain-bench', [false])], 0, { active: { workoutView: 'list' } })
|
||||
// The header ⋮ now leads with "Add routine"; the layouts moved to a nested "Layout" sheet.
|
||||
const openLayout = async menu => {
|
||||
await act(async () => { item(menu, 'Layout').onClick() })
|
||||
return mocks.menuSheet.mock.calls.at(-1)[0]
|
||||
}
|
||||
|
||||
it('leads with Add routine, then a Layout sheet with the three layouts marked current', async () => {
|
||||
await mount([exercise('plain-bench', [false])], 0, { active: { workoutView: 'list', routineIds: [] } })
|
||||
|
||||
const menu = await openMenu()
|
||||
expect(menu.items.filter(Boolean).map(it => it.label)).toEqual(['Cards', 'List', 'Compact'])
|
||||
expect(item(menu, 'List').on).toBe(true)
|
||||
expect(item(menu, 'Cards').on).toBe(false)
|
||||
expect(item(menu, 'Compact').on).toBe(false)
|
||||
expect(menu.items.filter(Boolean).map(it => it.label)).toEqual(['Add routine', 'Layout'])
|
||||
expect(item(menu, 'Layout').sub).toBe('List')
|
||||
|
||||
const layout = await openLayout(menu)
|
||||
expect(layout.items.filter(Boolean).map(it => it.label)).toEqual(['Cards', 'List', 'Compact'])
|
||||
expect(item(layout, 'List').on).toBe(true)
|
||||
expect(item(layout, 'Cards').on).toBe(false)
|
||||
})
|
||||
|
||||
it('writes the pick onto s.active without touching the global default', async () => {
|
||||
await mount([exercise('plain-bench', [false])], 0, { workoutView: 'cards', active: { workoutView: 'cards' } })
|
||||
it('writes the layout pick onto s.active without touching the global default', async () => {
|
||||
await mount([exercise('plain-bench', [false])], 0, { workoutView: 'cards', active: { workoutView: 'cards', routineIds: [] } })
|
||||
|
||||
const menu = await openMenu()
|
||||
await act(async () => { item(menu, 'Compact').onClick() })
|
||||
const layout = await openLayout(await openMenu())
|
||||
await act(async () => { item(layout, 'Compact').onClick() })
|
||||
|
||||
expect(mocks.S.active.workoutView).toBe('compact')
|
||||
expect(mocks.S.workoutView).toBe('cards')
|
||||
|
||||
@@ -46,7 +46,7 @@ vi.mock('./MobileOnboarding.jsx', () => ({ ConnectSheet: () => null }))
|
||||
vi.mock('../sheets.jsx', () => ({
|
||||
starterPlanSheet: vi.fn(), confirmSheet: vi.fn(), importFromApp: vi.fn(),
|
||||
importFromHevy: vi.fn(), equipmentProfileSheet: vi.fn(),
|
||||
dayAssignSheet: vi.fn(), planToolsSheet: vi.fn(),
|
||||
dayAssignSheet: vi.fn(), dayAddRoutineSheet: vi.fn(), planToolsSheet: vi.fn(),
|
||||
}))
|
||||
|
||||
globalThis.__APP_VERSION__ ??= 'test'
|
||||
@@ -118,3 +118,43 @@ describe('Plan — the week schedule follows the setting', () => {
|
||||
expect(rows[1].textContent).not.toContain('Push')
|
||||
})
|
||||
})
|
||||
|
||||
describe('Plan — inline per-day routine management (combine routines)', () => {
|
||||
const mount = () => act(() => root.render(<Plan />))
|
||||
const dayContainer = name => [...host.querySelectorAll('.item')].find(el => el.querySelector('.tt')?.textContent === name)
|
||||
|
||||
beforeEach(() => {
|
||||
mocks.S.routines = [
|
||||
{ id: 'r1', name: 'Push', emoji: null, ex: [{ id: 'a' }, { id: 'b' }] },
|
||||
{ id: 'r2', name: 'Core', emoji: null, ex: [{ id: 'c' }] },
|
||||
]
|
||||
})
|
||||
|
||||
it('renders a sub-row per routine on a populated day, with the count hint', () => {
|
||||
mocks.S.week = { 1: ['r1', 'r2'] }
|
||||
mount()
|
||||
const mon = dayContainer('Monday')
|
||||
expect(mon.textContent).toContain('Push')
|
||||
expect(mon.textContent).toContain('Core')
|
||||
expect(mon.textContent).toContain('2 routines')
|
||||
})
|
||||
|
||||
it('✕ removes a routine, and drops the day key on the last removal', () => {
|
||||
mocks.S.week = { 1: ['r1', 'r2'] }
|
||||
mount()
|
||||
const removeButtons = () => [...dayContainer('Monday').querySelectorAll('button[aria-label="Remove"]')]
|
||||
act(() => { removeButtons()[1].dispatchEvent(new Event('click', { bubbles: true })) })
|
||||
expect(mocks.S.week[1]).toEqual(['r1'])
|
||||
mount()
|
||||
act(() => { removeButtons()[0].dispatchEvent(new Event('click', { bubbles: true })) })
|
||||
expect(mocks.S.week).not.toHaveProperty('1')
|
||||
})
|
||||
|
||||
it('an empty day stays one tappable row', () => {
|
||||
mocks.S.week = {}
|
||||
mount()
|
||||
const tue = dayContainer('Tuesday')
|
||||
expect(tue.textContent).toContain('Rest')
|
||||
expect(tue.querySelectorAll('button[aria-label="Remove"]').length).toBe(0)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user