Combine routines (ENG-9) phase 4: UI surfaces
- Plan → Week schedule: inline per-day management. A populated weekday shows always-visible routine sub-rows with an inline ✕ (removes; drops the day key on the last one) and a + Add routine action (single-pick append; already-added routines disabled). An empty day stays one tappable row → the first-routine picker. Day header shows an "N routines" hint. DayAssign is now the empty-day / single-pick sheet only; new dayAddRoutineSheet does the append. - Workout header ⋮: "Add routine" is the first item; Cards / List / Compact move to a nested "Layout" sheet. addRoutineToSessionSheet appends the picked routine's entries (each stamped with its rid), extends s.active.routineIds, re-derives the name, toasts; a routine already in the session or with no exercises is disabled + tagged. s.active.cur is left where it is. - History WorkoutDetail: a combined workout's entries are grouped into per-routine sections in merge order, each with a glyph+name / "N sets · volume" subheader. A legacy single-routine workout renders flat, exactly as before. - Home today card: title is the derived session name (done in phase 3). Tests: Plan inline management (week-start.test.jsx), the ⋮ Add-routine / nested Layout menu (Workout.test.jsx), addRoutineToSessionSheet + WorkoutDetail grouping (sheets.combine-ui.test.jsx). Six new UI strings render English in translated packs — flagged by check-source-strings (report-only) for a translation follow-up, as docs/COMBINE_ROUTINES.md notes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01JVbWJtoyQU4WgwFR4eAKgy
This commit is contained in:
1 parent
3dd2092a8d
commit
c63ec2ca6c
6 files changed
+314
-30
No files matched your search
@@ -0,0 +1,111 @@
|
||||
// @vitest-environment happy-dom
|
||||
import React, { act } from 'react'
|
||||
import { afterEach, beforeEach, describe, expect, it } from 'vitest'
|
||||
import { createRoot } from 'react-dom/client'
|
||||
import { useStore } from './store/useStore.js'
|
||||
import { useUI } from './store/useUI.js'
|
||||
import { addRoutineToSessionSheet, workoutDetailSheet } from './sheets.jsx'
|
||||
import { EXDB } from './lib/exercises.js'
|
||||
|
||||
const clone = v => JSON.parse(JSON.stringify(v))
|
||||
const ids = EXDB.filter(e => e.bp !== 'cardio').slice(0, 4).map(e => e.id)
|
||||
const mounted = []
|
||||
|
||||
function renderTop() {
|
||||
const sheet = useUI.getState().sheets.at(-1)
|
||||
const host = document.createElement('div')
|
||||
document.body.appendChild(host)
|
||||
const root = createRoot(host)
|
||||
mounted.push(root)
|
||||
act(() => root.render(sheet.render(() => useUI.getState().closeSheet(sheet.id))))
|
||||
return host
|
||||
}
|
||||
const rowFor = (host, name) => [...host.querySelectorAll('.item')].find(el => el.querySelector('.tt')?.textContent === name)
|
||||
|
||||
beforeEach(() => {
|
||||
globalThis.IS_REACT_ACT_ENVIRONMENT = true
|
||||
useUI.setState({ sheets: [], toastMsg: '' })
|
||||
document.body.innerHTML = ''
|
||||
})
|
||||
afterEach(() => { act(() => { mounted.splice(0).forEach(r => r.unmount()) }) })
|
||||
|
||||
describe('Add routine mid-session sheet', () => {
|
||||
const setup = () => {
|
||||
const S = clone(useStore.getState().S)
|
||||
S.routines = [
|
||||
{ id: 'strength', name: 'Strength', emoji: '🏋️', prog: 'off', ex: [{ id: ids[0], sets: 3, reps: 5, weight: 60 }] },
|
||||
{ id: 'core', name: 'Core', emoji: '🧘', prog: 'off', ex: [{ id: ids[1], sets: 3, reps: 12, weight: 0 }, { id: ids[2], sets: 3, reps: 10, weight: 0 }] },
|
||||
{ id: 'empty', name: 'Empty', emoji: '📝', ex: [] },
|
||||
]
|
||||
S.workouts = []
|
||||
S.active = {
|
||||
id: 'a', d: '2026-09-06', start: 1, routineIds: ['strength'], name: 'Strength', cur: 0,
|
||||
entries: [{ id: ids[0], rid: 'strength', target: {}, sets: [{ w: 60, r: 5, done: true }] }],
|
||||
workoutView: 'cards',
|
||||
}
|
||||
useStore.setState({ S, user: null })
|
||||
}
|
||||
|
||||
it('appends the picked routine’s entries with rid, updates routineIds + name, toasts', () => {
|
||||
setup()
|
||||
addRoutineToSessionSheet()
|
||||
const host = renderTop()
|
||||
act(() => { rowFor(host, 'Core').click() })
|
||||
|
||||
const a = useStore.getState().S.active
|
||||
expect(a.routineIds).toEqual(['strength', 'core'])
|
||||
expect(a.name).toBe('Strength + Core')
|
||||
expect(a.entries.map(e => e.rid)).toEqual(['strength', 'core', 'core'])
|
||||
expect(a.cur).toBe(0) // current unit is left where it was
|
||||
expect(useUI.getState().toastMsg).toContain('Core added')
|
||||
})
|
||||
|
||||
it('disables a routine already in the session and one with no exercises', () => {
|
||||
setup()
|
||||
addRoutineToSessionSheet()
|
||||
const host = renderTop()
|
||||
expect(rowFor(host, 'Strength').className).toContain('disabled')
|
||||
expect(rowFor(host, 'Strength').textContent).toContain('already added')
|
||||
expect(rowFor(host, 'Empty').className).toContain('disabled')
|
||||
expect(rowFor(host, 'Empty').textContent).toContain('no exercises')
|
||||
})
|
||||
})
|
||||
|
||||
describe('WorkoutDetail — per-routine grouping', () => {
|
||||
const combined = {
|
||||
id: 'w', d: '2026-09-06', start: 1, end: 2, name: 'Strength + Core', vol: 500,
|
||||
routineIds: ['strength', 'core'], prs: [],
|
||||
entries: [
|
||||
{ id: ids[0], rid: 'strength', target: { reps: 5 }, sets: [{ w: 60, r: 5, done: true }, { w: 60, r: 5, done: true }] },
|
||||
{ id: ids[1], rid: 'core', target: { reps: 12 }, sets: [{ w: 0, r: 12, done: true }] },
|
||||
],
|
||||
}
|
||||
const legacy = {
|
||||
id: 'w2', d: '2026-09-06', start: 1, end: 2, name: 'Push', vol: 100, routineIds: ['strength'], prs: [],
|
||||
entries: [{ id: ids[0], target: { reps: 5 }, sets: [{ w: 100, r: 5, done: true }] }],
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
const S = clone(useStore.getState().S)
|
||||
S.routines = [
|
||||
{ id: 'strength', name: 'Strength', emoji: '🏋️', ex: [] },
|
||||
{ id: 'core', name: 'Core', emoji: '🧘', ex: [] },
|
||||
]
|
||||
useStore.setState({ S, user: null })
|
||||
})
|
||||
|
||||
it('groups a combined workout into per-routine sections with a sets/volume subheader', () => {
|
||||
const host = (workoutDetailSheet(combined), renderTop())
|
||||
expect(host.textContent).toContain('Strength')
|
||||
expect(host.textContent).toContain('Core')
|
||||
expect(host.textContent).toMatch(/2 sets/)
|
||||
expect(host.textContent).toMatch(/1 sets|1 set/)
|
||||
})
|
||||
|
||||
it('renders a legacy single-routine workout flat — no routine subheader', () => {
|
||||
const host = (workoutDetailSheet(legacy), renderTop())
|
||||
// the only routine name that could appear is the header <h3> (w.name = "Push"); there is
|
||||
// no "Strength" subheader row
|
||||
expect(host.querySelectorAll('.row.between').length).toBe(0)
|
||||
})
|
||||
})
|
||||
+104
-12
@@ -1539,8 +1539,9 @@ export const dayOverrideSheet = iso => ui().openSheet(close => <DayOverride iso=
|
||||
|
||||
function DayAssign({ day, close }) {
|
||||
const st = useStore(s => s.S)
|
||||
// A weekday holds a routine-id list; this single-pick sheet sets the day to exactly one
|
||||
// routine (or rest). The inline per-day management on the Plan screen is what appends.
|
||||
// A weekday holds a routine-id list; this single-pick sheet sets an empty day to exactly one
|
||||
// routine (or rest). The inline + Add routine on the Plan screen is what appends to a
|
||||
// populated day.
|
||||
const cur = [].concat(st.week[day] || [])
|
||||
const set = v => { update(s => { if (v) s.week[day] = [v]; else delete s.week[day] }); close() }
|
||||
return <>
|
||||
@@ -1556,6 +1557,29 @@ function DayAssign({ day, close }) {
|
||||
}
|
||||
export const dayAssignSheet = day => ui().openSheet(close => <DayAssign day={day} close={close} />)
|
||||
|
||||
// + Add routine on a populated weekday: single-pick, appends to the day's list. A routine
|
||||
// already on that day is disabled; picking one closes the sheet.
|
||||
function DayAddRoutine({ day, close }) {
|
||||
const st = useStore(s => s.S)
|
||||
const on = new Set([].concat(st.week[day] || []))
|
||||
const add = id => { update(s => { s.week[day] = [...[].concat(s.week[day] || []), id] }); close() }
|
||||
return <>
|
||||
<h3>{t('Add routine')}</h3>
|
||||
<div className="list">
|
||||
{st.routines.map(r => {
|
||||
const already = on.has(r.id)
|
||||
return <div key={r.id} className={'item' + (already ? ' disabled' : '')} aria-disabled={already || undefined}
|
||||
{...tappable(already ? null : () => add(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>
|
||||
{already ? <span className="tag">{t('already added')}</span> : <Icon name="chevronRight" className="chev" />}
|
||||
</div>
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
export const dayAddRoutineSheet = day => ui().openSheet(close => <DayAddRoutine day={day} close={close} />)
|
||||
|
||||
/* ============================ workout detail ============================ */
|
||||
function WorkoutDetail({ w, close }) {
|
||||
const noteRef = useRef(null)
|
||||
@@ -1587,20 +1611,44 @@ function WorkoutDetail({ w, close }) {
|
||||
if (text) rec.note = text; else delete rec.note
|
||||
})
|
||||
}, [])
|
||||
// A combined session's entries carry a `rid`; group them into per-routine sections in merge
|
||||
// order. A legacy single-routine workout (one routineIds, or no rid anywhere) renders flat.
|
||||
const entryRow = (e, i) => {
|
||||
const ex = EXIDX[e.id]
|
||||
return <div key={i} className="row" style={{ marginBottom: 12, alignItems: 'flex-start' }}>
|
||||
{ex && <Thumb ex={ex} />}
|
||||
<div className="grow"><div className="tt capitalize" style={{ fontWeight: 600 }}>{ex ? exerciseNameFor(ex) : (e.n || e.id)} {w.prs && w.prs.includes(e.id) && <span className="pr"><Icon name="trophy" />PR</span>}</div>
|
||||
<div className="ss">{e.sets.filter(s => s.done).map(s => setLabel(e.id, s, e.target)).join(' · ') || t('no sets')}</div>
|
||||
{e.note && <div className="small dim" style={{ marginTop: 3 }}>
|
||||
{e.notePin && <Icon name="flag" style={{ fontSize: 12, marginRight: 4, verticalAlign: '-1px', color: 'var(--yellow)' }} />}{e.note}
|
||||
</div>}</div>
|
||||
</div>
|
||||
}
|
||||
const groups = []
|
||||
w.entries.forEach((e, i) => {
|
||||
const key = e.rid || '__none'
|
||||
let g = groups.find(x => x.key === key)
|
||||
if (!g) { g = { key, rid: e.rid || null, items: [] }; groups.push(g) }
|
||||
g.items.push([e, i])
|
||||
})
|
||||
const grouped = groups.length > 1 || (groups[0] && groups[0].rid && (w.routineIds || []).length > 1)
|
||||
return <>
|
||||
<h3>{w.name}</h3>
|
||||
<div className="muted small" style={{ marginBottom: 12 }}>{[fmtDate(w.d, true), ...durPart(w.end - w.start), fmtVol(w.vol, st.unit), ...(w.bw ? [fmtNum(w.bw) + ' ' + st.unit] : [])].join(' · ')}</div>
|
||||
{w.entries.map((e, i) => {
|
||||
const ex = EXIDX[e.id]
|
||||
return <div key={i} className="row" style={{ marginBottom: 12, alignItems: 'flex-start' }}>
|
||||
{ex && <Thumb ex={ex} />}
|
||||
<div className="grow"><div className="tt capitalize" style={{ fontWeight: 600 }}>{ex ? exerciseNameFor(ex) : (e.n || e.id)} {w.prs && w.prs.includes(e.id) && <span className="pr"><Icon name="trophy" />PR</span>}</div>
|
||||
<div className="ss">{e.sets.filter(s => s.done).map(s => setLabel(e.id, s, e.target)).join(' · ') || t('no sets')}</div>
|
||||
{e.note && <div className="small dim" style={{ marginTop: 3 }}>
|
||||
{e.notePin && <Icon name="flag" style={{ fontSize: 12, marginRight: 4, verticalAlign: '-1px', color: 'var(--yellow)' }} />}{e.note}
|
||||
</div>}</div>
|
||||
{grouped ? groups.map(g => {
|
||||
const r = g.rid ? st.routines.find(x => x.id === g.rid) : null
|
||||
const setN = g.items.reduce((n, [e]) => n + e.sets.filter(s => s.done && !isWarmupRow(s)).length, 0)
|
||||
const vol = workoutVolume({ entries: g.items.map(([e]) => e) })
|
||||
return <div key={g.key}>
|
||||
<div className="row between" style={{ margin: '2px 0 8px', paddingBottom: 6, borderBottom: '1px solid var(--sep)' }}>
|
||||
<div className="row" style={{ gap: 7, fontWeight: 600 }}>
|
||||
{r && <Icon name={glyphOf(r.emoji)} />}{r ? r.name : t('Freestyle')}
|
||||
</div>
|
||||
<div className="small dim">{t('{0} sets', setN)} · {fmtVol(vol, st.unit)}</div>
|
||||
</div>
|
||||
{g.items.map(([e, i]) => entryRow(e, i))}
|
||||
</div>
|
||||
})}
|
||||
}) : w.entries.map((e, i) => entryRow(e, i))}
|
||||
<div className="small muted" style={{ margin: '4px 0 6px' }}>{t('Session note')}</div>
|
||||
<textarea ref={noteRef} className="input" rows={2} maxLength={NOTE_MAX} value={note}
|
||||
placeholder={t('How the session went as a whole.')}
|
||||
@@ -1771,6 +1819,50 @@ function beginBackfill({ iso, time, durationMin, routineId, replaceId }) {
|
||||
useUI.getState().stopRest()
|
||||
nav('/workout')
|
||||
}
|
||||
|
||||
/* ============================ add a routine mid-session ============================ */
|
||||
// The workout header ⋮ → Add routine. Single-pick: a routine already in the session, or one
|
||||
// with no exercises, is shown disabled and tagged. Picking one appends its entries (each
|
||||
// stamped with its `rid`), extends `s.active.routineIds`, and re-derives the session name.
|
||||
// `s.active.cur` is left where it is — the appended block is reached by scrolling / Next.
|
||||
function AddRoutineToSession({ close }) {
|
||||
const st = useStore(s => s.S)
|
||||
const active = st.active
|
||||
if (!active) return null
|
||||
const inSession = new Set([].concat(active.routineIds || []))
|
||||
const add = r => {
|
||||
const entries = buildSessionEntries(st, r).map(e => ({ ...e, rid: r.id }))
|
||||
update(s => {
|
||||
if (!s.active) return
|
||||
s.active.entries.push(...entries)
|
||||
s.active.routineIds = [...[].concat(s.active.routineIds || []), r.id]
|
||||
s.active.name = deriveSessionName(s.active.routineIds.map(id => s.routines.find(x => x.id === id)?.name).filter(Boolean))
|
||||
})
|
||||
close()
|
||||
toast(t('{0} added — {1}', r.name, exCount(r.ex.length)))
|
||||
}
|
||||
return <>
|
||||
<h3>{t('Add routine')}</h3>
|
||||
<div className="list">
|
||||
{st.routines.map(r => {
|
||||
const already = inSession.has(r.id)
|
||||
const empty = !(r.ex || []).length
|
||||
const disabled = already || empty
|
||||
return <div key={r.id} className={'item' + (disabled ? ' disabled' : '')} aria-disabled={disabled || undefined}
|
||||
{...tappable(disabled ? null : () => add(r))}>
|
||||
<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>
|
||||
{already ? <span className="tag">{t('already added')}</span> : empty ? <span className="tag">{t('no exercises')}</span> : <Icon name="chevronRight" className="chev" />}
|
||||
</div>
|
||||
})}
|
||||
</div>
|
||||
</>
|
||||
}
|
||||
export function addRoutineToSessionSheet() {
|
||||
if (!S().active) return
|
||||
ui().openSheet(close => <AddRoutineToSession close={close} />)
|
||||
}
|
||||
|
||||
function TopWeight({ entryIdx, close }) {
|
||||
const st = useStore(s => s.S)
|
||||
const A = st.active
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -12,7 +12,7 @@ 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'
|
||||
@@ -556,14 +556,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
|
||||
|
||||
@@ -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