Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

rotation/Plan/Settings: grid stays up for any live queue, pins never outlive the pass that made them, an adopted pass keeps its own name

giulioleuci682ca78e08b8
diff --git a/frontend/src/lib/pt-br-locale.test.js b/frontend/src/lib/pt-br-locale.test.js
index 890175234..859d42319 100644
--- a/frontend/src/lib/pt-br-locale.test.js
+++ b/frontend/src/lib/pt-br-locale.test.js
@@ -41,7 +41,7 @@ describe('Brazilian Portuguese locale', () => {
// has to be taught is a number nobody reads. What the numbers stood for is asserted above.
// If the hash fails, review the changed keys and wording before accepting a new one. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
- expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('9be6cc7996a836338e4c6d4aaa075dc40f350dad94c72ef67c0a021870720c49')
+ expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('f36be87cd9ee66805ce9d9e0c3d3c5d219af6025728e17c53ffd3f9cc354942e')
})
test('does not leak European Portuguese UI terms', () => {
diff --git a/frontend/src/lib/rotation.js b/frontend/src/lib/rotation.js
index 373292dc1..0008bcac8 100644
--- a/frontend/src/lib/rotation.js
+++ b/frontend/src/lib/rotation.js
@@ -54,6 +54,19 @@ const creditWindow = (s, q) => (s.workouts || [])
*/
const sinceAfter = (s, q, now) => Math.max(now, ...creditWindow(s, q).map(w => (w.start ?? 0) + 1))
+/**
+ * Clears dayPlan pins dated `today` or later that name one of `ids` — a pass no longer owns
+ * them (dropped, replaced by a refill, or ended outright), so a leftover pin never resurfaces as
+ * an "open" pin on a session that isn't this pass's any more (pinState, queue.js) or, once no
+ * queue is left at all, as a plain routine override history.js was never meant to read it as.
+ */
+const sweepPins = (s, ids, today) => {
+ if (!ids.length) return
+ Object.keys(s.dayPlan || {}).forEach(iso => {
+ if (iso >= today && ids.includes(s.dayPlan[iso])) delete s.dayPlan[iso]
+ })
+}
+
/** Settings → Rotation with a saved rotation and no queue. False when nothing valid is left to start. */
export function startPass(s, today = todayISO(), now = Date.now()) {
const ids = rotationIds(s)
@@ -81,24 +94,28 @@ export function saveRotation(s, ids, label, today = todayISO(), now = Date.now()
}
// A session dropped from the rotation leaves its future pin behind otherwise — dayPlan then
// still resolves that date to a session the queue no longer has (pinState/queue.js).
- const removed = (prev?.ids || []).filter(id => !ids.includes(id))
- if (removed.length) {
- Object.keys(s.dayPlan || {}).forEach(iso => {
- if (iso >= today && removed.includes(s.dayPlan[iso])) delete s.dayPlan[iso]
- })
- }
+ sweepPins(s, (prev?.ids || []).filter(id => !ids.includes(id)), today)
// An edit (e.g. removing the last session still to do) can leave the pass complete on the
// spot — without this it would sit idle until a workout happened to reach refillAfter.
if (queueView(s, today)?.complete) startNewPass(s, today, now)
}
+/**
+ * Ends the current pass without touching the saved sequence — "Use Fixed Week", or the editor
+ * emptied down to nothing. Sweeps the same future pins saveRotation does, so a dropped pass never
+ * resurfaces as a plain routine override (history.js) once the weekday plan is back in charge.
+ */
+export function stopPass(s, today = todayISO()) {
+ const q = queueOf(s)
+ if (q) sweepPins(s, q.ids, today)
+ s.queue = null
+}
+
/** The latest day a workout could have credited the current pass, or null. */
const lastCreditDay = s => {
const q = queueOf(s)
if (!q) return null
- const days = (s.workouts || [])
- .filter(w => routineIdsOf(w).some(id => q.ids.includes(id)) && String(w.d || '') >= q.startsOn)
- .map(w => w.d)
+ const days = creditWindow(s, q).map(w => w.d)
return days.length ? days.sort().at(-1) : null
}
@@ -114,6 +131,7 @@ export function startNewPass(s, today = todayISO(), now = Date.now()) {
const q = queueOf(s)
const last = lastCreditDay(s)
const startsOn = last && last >= today ? dayAfter(last) : today
+ if (q) sweepPins(s, q.ids, today)
s.queue = newPass(ids, s.rotation.label || '', s.rotation.id, startsOn, q ? sinceAfter(s, q, now) : now)
}
@@ -148,6 +166,10 @@ export function refillAfter(s, w, today = todayISO(), now = Date.now()) {
const credited = routineIdsOf(w)
const last = q.ids.filter(id => credited.includes(id)).at(-1) ?? null
const bound = [w.d, lastCreditDay(s)].filter(Boolean).sort().at(-1)
- s.queue = newPass(rotate(seq, last), s.rotation.label || q.label || '', s.rotation.id, dayAfter(bound), sinceAfter(s, q, now))
+ sweepPins(s, q.ids, today)
+ // The rotation's own label only — never the closing pass's (q.label): once adopted from a
+ // planner, that would otherwise repeat its original week name ("US W1") on every pass this app
+ // generates on its own from then on.
+ s.queue = newPass(rotate(seq, last), s.rotation.label || '', s.rotation.id, dayAfter(bound), sinceAfter(s, q, now))
return true
}
diff --git a/frontend/src/lib/rotation.test.js b/frontend/src/lib/rotation.test.js
index 354355ece..33bda2d31 100644
--- a/frontend/src/lib/rotation.test.js
+++ b/frontend/src/lib/rotation.test.js
@@ -1,5 +1,5 @@
import { describe, it, expect } from 'vitest'
-import { scheduleModeOf, queueRecovery, rotationIds, startPass, saveRotation, startNewPass, refillAfter } from './rotation.js'
+import { scheduleModeOf, queueRecovery, rotationIds, startPass, saveRotation, startNewPass, stopPass, refillAfter } from './rotation.js'
import { queueRemaining, queueView } from './queue.js'
const routines = [{ id: 'a', name: 'A' }, { id: 'b', name: 'B' }, { id: 'c', name: 'C' }, { id: 'own', name: 'Core' }]
@@ -111,6 +111,37 @@ describe('editing the sequence', () => {
expect(fresh.queue.startsOn).toBe('2026-09-13')
expect(fresh.queue.since).toBe(NOW)
})
+
+ it('Start new pass sweeps the old pass\'s future pins — a stale one would otherwise resurface as open on the new pass', () => {
+ const s = S({
+ rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' },
+ queue: pass(['a', 'b'], { rotationId: 'r1' }),
+ dayPlan: { '2026-09-13': 'b', '2026-09-11': 'a' },
+ })
+ startNewPass(s, TODAY, NOW)
+ expect(s.dayPlan).toEqual({ '2026-09-11': 'a' }) // dated before today: left alone, already stale on its own
+ })
+})
+
+describe('stopPass', () => {
+ it('clears the queue and sweeps its future pins, leaving the saved sequence untouched', () => {
+ const s = S({
+ rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' },
+ queue: pass(['a', 'b'], { rotationId: 'r1' }),
+ dayPlan: { '2026-09-13': 'a', '2026-09-10': 'b' },
+ })
+ stopPass(s, TODAY)
+ expect(s.queue).toBe(null)
+ expect(s.rotation).toEqual({ id: 'r1', sequence: ['a', 'b'], label: 'My split' })
+ expect(s.dayPlan).toEqual({ '2026-09-10': 'b' }) // dated before today: not this pass's business
+ })
+
+ it('does nothing to dayPlan when there is no queue to stop', () => {
+ const s = S({ dayPlan: { '2026-09-13': 'a' } })
+ stopPass(s, TODAY)
+ expect(s.queue).toBe(null)
+ expect(s.dayPlan).toEqual({ '2026-09-13': 'a' })
+ })
})
describe('refilling a completed managed pass', () => {
@@ -193,6 +224,25 @@ describe('refilling a completed managed pass', () => {
expect(s.queue.startsOn).toBe('2026-09-12')
})
+ it("sweeps every future pin the closing pass left behind, so a fulfilled one does not reopen on the next pass", () => {
+ const last = w('c', TODAY)
+ const s = managed(['a', 'b', 'c'], [w('a', '2026-09-10'), w('b', '2026-09-11'), last])
+ s.dayPlan = { '2026-09-13': 'a', '2026-09-14': 'c', '2026-09-09': 'b' }
+ expect(refillAfter(s, last, TODAY, NOW)).toBe(true)
+ expect(s.dayPlan).toEqual({ '2026-09-09': 'b' }) // dated before today: already stale on its own
+ })
+
+ it("uses the rotation's own label, never the closing pass's — an adopted pass's planner name must not repeat on every pass after it", () => {
+ const last = w('c', TODAY)
+ const s = S({
+ rotation: { id: 'r1', sequence: ['a', 'b', 'c'], label: 'Rotation' },
+ queue: pass(['a', 'b', 'c'], { rotationId: 'r1', label: 'US W1' }), // this pass still carries the planner's name
+ workouts: [w('a', '2026-09-10'), w('b', '2026-09-11'), last],
+ })
+ expect(refillAfter(s, last, TODAY, NOW)).toBe(true)
+ expect(s.queue.label).toBe('Rotation')
+ })
+
it('a workout logged with a clock ahead of now does not re-credit the new pass', () => {
// The bug: `since = Date.now()` at refill time sits before a workout whose own clock (a
// backfilled entry, or a device a few minutes fast) already reads later — that workout then
@@ -218,6 +268,8 @@ describe('the finished-workout boundary', () => {
rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' },
queue: pass(['a', 'b'], { rotationId: 'r1' }),
workouts: [w('a', '2026-09-11')],
+ // a pin on an adopted coach queue, dated after today — must not bleed into the next pass
+ dayPlan: { '2026-09-13': 'a' },
})
s.workouts.push(done) // what doFinishWorkout does, in order
expect(refillAfter(s, done, TODAY, NOW)).toBe(true)
@@ -228,5 +280,6 @@ describe('the finished-workout boundary', () => {
// the pass has not started yet.
expect(queueRemaining(s)).toEqual(['a', 'b'])
expect(queueView(s, TODAY).waiting).toBe(true)
+ expect(s.dayPlan).toEqual({})
})
})
diff --git a/frontend/src/locales/de.js b/frontend/src/locales/de.js
index 496cfdcc2..41545481e 100644
--- a/frontend/src/locales/de.js
+++ b/frontend/src/locales/de.js
@@ -1716,4 +1716,5 @@ export default {
'Pass complete': 'Durchgang abgeschlossen',
'Next pass starts {0}': 'Nächster Durchgang beginnt {0}',
+
}
diff --git a/frontend/src/locales/es.js b/frontend/src/locales/es.js
index bf6b40444..25f2e23db 100644
--- a/frontend/src/locales/es.js
+++ b/frontend/src/locales/es.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': 'Pasada completada',
'Next pass starts {0}': 'La próxima pasada empieza {0}',
+
}
diff --git a/frontend/src/locales/fr.js b/frontend/src/locales/fr.js
index 7ec918979..690bee407 100644
--- a/frontend/src/locales/fr.js
+++ b/frontend/src/locales/fr.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': 'Passage terminé',
'Next pass starts {0}': 'Le prochain passage commence {0}',
+
}
diff --git a/frontend/src/locales/hi.js b/frontend/src/locales/hi.js
index 71f1db4ac..59d004e6f 100644
--- a/frontend/src/locales/hi.js
+++ b/frontend/src/locales/hi.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': 'पास पूरा हुआ',
'Next pass starts {0}': 'अगला पास {0} से शुरू होगा',
+
}
diff --git a/frontend/src/locales/hu.js b/frontend/src/locales/hu.js
index d6756ba1f..531f97acd 100644
--- a/frontend/src/locales/hu.js
+++ b/frontend/src/locales/hu.js
@@ -1699,4 +1699,5 @@ export default {
'Pass complete': 'Menet kész',
'Next pass starts {0}': 'A következő menet {0}-kor kezdődik',
+
}
diff --git a/frontend/src/locales/it.js b/frontend/src/locales/it.js
index 1d78748b6..e740fd03e 100644
--- a/frontend/src/locales/it.js
+++ b/frontend/src/locales/it.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': 'Giro completato',
'Next pass starts {0}': 'Il prossimo giro inizia {0}',
+
}
diff --git a/frontend/src/locales/ko.js b/frontend/src/locales/ko.js
index 760bd609c..310edd924 100644
--- a/frontend/src/locales/ko.js
+++ b/frontend/src/locales/ko.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': '패스 완료',
'Next pass starts {0}': '다음 패스는 {0}에 시작해요',
+
}
diff --git a/frontend/src/locales/pl.js b/frontend/src/locales/pl.js
index 20e725dc1..746b7775a 100644
--- a/frontend/src/locales/pl.js
+++ b/frontend/src/locales/pl.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': 'Przejście ukończone',
'Next pass starts {0}': 'Następne przejście zaczyna się {0}',
+
}
diff --git a/frontend/src/locales/pt-BR.js b/frontend/src/locales/pt-BR.js
index d1254231c..125cc1a34 100644
--- a/frontend/src/locales/pt-BR.js
+++ b/frontend/src/locales/pt-BR.js
@@ -1040,6 +1040,7 @@ export const PT_BR_OVERRIDES = {
'Set up in Plan': 'Configurar no Plano',
'Pass complete': 'Passagem concluída',
'Next pass starts {0}': 'A próxima passagem começa em {0}',
+ 'Add routine': 'Adicionar rotina',
}
export default { ...pt, ...PT_BR_OVERRIDES }
diff --git a/frontend/src/locales/pt.js b/frontend/src/locales/pt.js
index 2cb2ea4a9..e439bb3a5 100644
--- a/frontend/src/locales/pt.js
+++ b/frontend/src/locales/pt.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': 'Passagem concluída',
'Next pass starts {0}': 'A próxima passagem começa a {0}',
+
}
diff --git a/frontend/src/locales/ru.js b/frontend/src/locales/ru.js
index 7e4fd877f..edb0f7638 100644
--- a/frontend/src/locales/ru.js
+++ b/frontend/src/locales/ru.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': 'Проход завершён',
'Next pass starts {0}': 'Следующий проход начнётся {0}',
+
}
diff --git a/frontend/src/locales/th.js b/frontend/src/locales/th.js
index 71ce966c3..be73ee584 100644
--- a/frontend/src/locales/th.js
+++ b/frontend/src/locales/th.js
@@ -1707,4 +1707,5 @@ export default {
'Pass complete': 'รอบเสร็จสมบูรณ์',
'Next pass starts {0}': 'รอบถัดไปเริ่ม {0}',
+
}
diff --git a/frontend/src/locales/tr.js b/frontend/src/locales/tr.js
index 25a5b6bf5..282581c2d 100644
--- a/frontend/src/locales/tr.js
+++ b/frontend/src/locales/tr.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': 'Tur tamamlandı',
'Next pass starts {0}': 'Sıradaki tur {0} tarihinde başlıyor',
+
}
diff --git a/frontend/src/locales/zh.js b/frontend/src/locales/zh.js
index 55c9f2d47..df276f25a 100644
--- a/frontend/src/locales/zh.js
+++ b/frontend/src/locales/zh.js
@@ -1696,4 +1696,5 @@ export default {
'Pass complete': '本轮已完成',
'Next pass starts {0}': '下一轮从 {0} 开始',
+
}
diff --git a/frontend/src/views/Home.queue.test.jsx b/frontend/src/views/Home.queue.test.jsx
index 988894824..1098bbc80 100644
--- a/frontend/src/views/Home.queue.test.jsx
+++ b/frontend/src/views/Home.queue.test.jsx
@@ -198,6 +198,19 @@ describe('Home — coach week progress row', () => {
expect(host.querySelectorAll('.queue .row .small')[1].textContent).toBe('1 / 3')
})
+ it('a managed pass counts your own day beside it exactly as an external one does — ownership plays no part in the tally', () => {
+ const now = Date.now()
+ const core = { id: 'w-own', d: todayISO(), start: now - 3600000, end: now, routineIds: ['own'], routineId: 'own', name: 'Core', entries: [] }
+ setS({
+ queue: queue({ rotationId: 'r1' }),
+ rotation: { id: 'r1', sequence: ['d1', 'd2', 'd3'], label: 'US W1' },
+ week: { [new Date().getDay()]: ['own'] }, workouts: [logged('d1'), core],
+ })
+ mount()
+ expect(card()).toMatch(/^2 \/ 4 this week · 2 workouts total$/)
+ expect(host.querySelectorAll('.queue .row .small')[1].textContent).toBe('1 / 3')
+ })
+
it('without a queue the weekday dots are back', () => {
setS({ queue: null })
mount()
diff --git a/frontend/src/views/Plan.jsx b/frontend/src/views/Plan.jsx
index c69534812..e65a69bd9 100644
--- a/frontend/src/views/Plan.jsx
+++ b/frontend/src/views/Plan.jsx
@@ -13,7 +13,7 @@ import { DEMO } from '../lib/demo.js'
import { MOBILE } from '../lib/mobile.js'
import { coachAvailable } from '../lib/coach.js'
import { queueOf } from '../lib/queue.js'
-import { scheduleModeOf, queueRecovery, rotationIds, saveRotation, startNewPass, startPass } from '../lib/rotation.js'
+import { scheduleModeOf, queueRecovery, rotationIds, saveRotation, startNewPass, startPass, stopPass } from '../lib/rotation.js'
export default function Plan() {
const nav = useNavigate()
@@ -71,15 +71,18 @@ export default function Plan() {
const external = !!liveQ && !managed
// The editor shows for any live queue — so "Use this rotation" stays reachable for a planner's
// week — or once Rotation is chosen with nothing built yet (S.scheduleMode). The weekday grid
- // is hidden only for a pass this app actually manages: an external queue keeps both on screen,
- // since the weekday routines still ride alongside it (effectiveRoutineIds, history.js).
+ // stays up for ANY live queue, managed or not: the weekday routines ride along beside it either
+ // way (effectiveRoutineIds, history.js) and feed the same tally (weekTally, queue.js), so hiding
+ // the grid would hide the very thing that explains a combined count. It is hidden only while
+ // Rotation is chosen with nothing built yet — there is no queue at that point for it to sit
+ // beside, so a plain weekday grid would just be noise.
const rotating = scheduleModeOf(S) === 'rotation' || queueRecovery(S)
- const hideGrid = managed || S.scheduleMode === 'rotation'
+ const hideGrid = !liveQ && S.scheduleMode === 'rotation'
const setSeq = ids => update(s => {
// Emptying the sequence is how you leave the rotation from here: no pass, no definition, and
// the weekday plan — untouched all along — is the schedule again.
if (ids.length) saveRotation(s, ids, seqLabel)
- else { s.queue = null; s.rotation = null; s.scheduleMode = 'week' }
+ else { stopPass(s); s.rotation = null; s.scheduleMode = 'week' }
})
const moveInSeq = (i, d) => { const n = [...seq]; const [x] = n.splice(i, 1); n.splice(i + d, 0, x); setSeq(n) }
const addToSeq = () => menuSheet({
@@ -90,11 +93,13 @@ export default function Plan() {
})
// The only path from a coach-written queue into a managed one: behind a confirmation, since it
// hands refilling over to this app from here on — the coach's app should not still be writing it.
+ // The rotation takes a name of its own here rather than the planner's (e.g. "US W1") — that
+ // name is this one pass's, and refillAfter would otherwise repeat it on every pass after it.
const adopt = () => confirmSheet({
title: t('Use this rotation?'),
message: t('openGym will take over refilling this queue from here on — the coach’s app should no longer write to it.'),
confirmText: t('Use this rotation'),
- onConfirm: () => setSeq(seq),
+ onConfirm: () => update(s => saveRotation(s, seq, t('Rotation'))),
})
return <>
@@ -113,15 +118,18 @@ export default function Plan() {
<div className="cols"><div>
{/* Rotation (lib/rotation.js) shows for any live queue, so a coach's week can still be
- adopted from here — but only a pass this app manages hides the weekday grid below it;
- an external queue keeps both, editor above grid, since the weekday routines still ride
- alongside it (effectiveRoutineIds, history.js). */}
+ adopted from here. The weekday grid stays up beside it either way — managed or
+ external — since the weekday routines ride along regardless (effectiveRoutineIds,
+ history.js) and the grid is what explains their share of the combined tally. */}
{rotating && <div className="rotation">
<h4 className="sec">{t('Rotation')}{external && <span className="tag" style={{ marginLeft: 8 }}>{t('Externally managed')}</span>}</h4>
{queueRecovery(S) ? <div className="empty">
{t('This rotation could not be read — it may have been written by another device.')}
<div style={{ marginTop: 10 }}>
- <Button size="sm" variant="tinted" aria-label={t('Discard it')} onClick={() => update(s => { s.queue = null })}>{t('Discard it')}</Button>
+ {/* Also gives up S.scheduleMode='rotation' — otherwise the editor stays up with a
+ saved sequence and no queue, and hideGrid keeps the weekday grid (and its own
+ "Start pass" way out of that state) hidden along with it: a dead end. */}
+ <Button size="sm" variant="tinted" aria-label={t('Discard it')} onClick={() => update(s => { s.queue = null; s.scheduleMode = 'week' })}>{t('Discard it')}</Button>
</div>
</div> : <>
{seq.length ? <div className="list" style={{ display: 'flex', flexDirection: 'column' }}>
@@ -191,7 +199,7 @@ export default function Plan() {
{!liveQ && seq.length > 0
? <Button size="sm" variant="tinted" icon="shuffle" style={{ marginTop: 8 }}
aria-label={t('Start pass')} onClick={() => update(s => startPass(s))}>{t('Start pass')}</Button>
- : !S.rotation && <Button size="sm" variant="tinted" icon="shuffle" style={{ marginTop: 8 }}
+ : !liveQ && !S.rotation && <Button size="sm" variant="tinted" icon="shuffle" style={{ marginTop: 8 }}
aria-label={t('Build a rotation instead')} onClick={() => update(s => { s.scheduleMode = 'rotation' })}>{t('Build a rotation instead')}</Button>}
</>}
</div><div>
diff --git a/frontend/src/views/Plan.rotation.test.jsx b/frontend/src/views/Plan.rotation.test.jsx
index cb3f6c514..e72093256 100644
--- a/frontend/src/views/Plan.rotation.test.jsx
+++ b/frontend/src/views/Plan.rotation.test.jsx
@@ -54,10 +54,22 @@ const click = el => act(() => el.dispatchEvent(new MouseEvent('click', { bubbles
const byLabel = label => [...host.querySelectorAll('button')].find(b => b.getAttribute('aria-label') === label || b.textContent.trim() === label)
describe('Plan — the rotation editor', () => {
- it('lists the live pass in order, and hides the weekday grid for a managed pass', () => {
+ it('lists the live pass in order, and keeps the weekday grid up for a managed pass too', () => {
+ // A managed pass no longer hides the grid: the weekday routines still ride alongside it
+ // (effectiveRoutineIds, history.js) and feed the same tally (weekTally, queue.js), so hiding
+ // the grid would hide the very thing a combined count depends on.
mount({ queue: live({ rotationId: 'r1' }), rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' } })
expect(names()).toEqual(['A', 'B'])
- expect(host.textContent).not.toContain('Week schedule')
+ expect(host.textContent).toContain('Week schedule')
+ expect(host.textContent).toContain('C') // week[1] = ['c'] (baseS) rides along beside the pass
+ })
+
+ it('a coach queue with S.scheduleMode stuck on "rotation" still shows Week schedule, never Build a rotation instead', () => {
+ // scheduleMode is stale/irrelevant once a queue is live — it only matters with no queue at
+ // all (the from-scratch setup gap hideGrid exists for).
+ mount({ queue: live(), scheduleMode: 'rotation' }) // external queue; no S.rotation
+ expect(host.textContent).toContain('Week schedule')
+ expect(byLabel('Build a rotation instead')).toBeUndefined()
})
it('nothing saved shows the weekday grid, with a button into the rotation editor', () => {
@@ -118,10 +130,14 @@ describe('Plan — the rotation editor', () => {
act(() => confirmSheet.mock.calls.at(-1)[0].onConfirm())
expect(mocks.S.rotation.sequence).toEqual(['a', 'b'])
expect(mocks.S.queue.rotationId).toBe(mocks.S.rotation.id)
+ // Adopting takes a name of its own rather than the planner's ("My split") — refillAfter would
+ // otherwise repeat that name on every pass this app generates on its own from here on.
+ expect(mocks.S.rotation.label).toBe('Rotation')
+ expect(mocks.S.queue.label).toBe('Rotation')
// (the mocked store is not reactive, so re-mount to see the adopted pass render)
mount({ queue: live({ rotationId: mocks.S.rotation.id }), rotation: mocks.S.rotation })
expect(host.textContent).not.toContain('Externally managed')
- expect(host.textContent).not.toContain('Week schedule')
+ expect(host.textContent).toContain('Week schedule')
})
it('an external queue keeps its rows read-only — no button but the adoption one writes rotationId', () => {
@@ -155,6 +171,22 @@ describe('Plan — the rotation editor', () => {
expect(mocks.S.queue).toBe(null)
})
+ it('Discard it leaves a clear way back in, not a hidden grid with a saved sequence stuck behind it', () => {
+ // A saved sequence survives the corrupt queue — without also giving up scheduleMode, that
+ // combination (no queue, scheduleMode still 'rotation') keeps hideGrid true and the grid's
+ // own "Start pass" — the way out — hidden right along with it.
+ mount({ queue: { ids: ['gone'], since: Date.now() }, rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' } })
+ click(byLabel('Discard it'))
+ expect(mocks.S.queue).toBe(null)
+ expect(mocks.S.scheduleMode).toBe('week')
+ // (the mocked store is not reactive, so re-mount to see the discarded state render)
+ mount({ scheduleMode: mocks.S.scheduleMode, rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' } })
+ expect(host.textContent).toContain('Week schedule')
+ expect(byLabel('Start pass')).toBeDefined()
+ click(byLabel('Start pass'))
+ expect(mocks.S.queue.ids).toEqual(['a', 'b'])
+ })
+
it('a saved sequence with no live pass offers Start pass, not Build a rotation instead', () => {
// The state "Discard it" or Settings' "Use Fixed Week" leave behind: a saved rotation, no queue.
mount({ rotation: { id: 'r1', sequence: ['a', 'b'], label: 'My split' } })
diff --git a/frontend/src/views/Settings.jsx b/frontend/src/views/Settings.jsx
index 333fbb054..2b5e72f73 100644
--- a/frontend/src/views/Settings.jsx
+++ b/frontend/src/views/Settings.jsx
@@ -9,7 +9,7 @@ import { ACCENTS, ACCENT_NAMES, todayISO, localTZ, weekStartOf, MONDAY, SUNDAY,
import { inventoryFor, ownsPlates } from '../lib/plates.js'
import { effortOf } from '../lib/history.js'
import { unlock, playOnSilentSupported, vibrateSupported } from '../lib/sound.js'
-import { scheduleModeOf, queueRecovery, rotationIds, startPass } from '../lib/rotation.js'
+import { scheduleModeOf, queueRecovery, rotationIds, startPass, stopPass } from '../lib/rotation.js'
import { queueOf } from '../lib/queue.js'
import { api, webauthnOK, passkeyRegister, IS_ANDROID } from '../lib/api.js'
import { pushSupported, enablePush, disablePush, sendTestPush, syncPushSubscription } from '../lib/push.js'
@@ -89,7 +89,7 @@ export default function Settings() {
title: t('Switch to Fixed Week?'),
message: t('The rotation stops and its current pass is dropped. Your weekday plan comes back exactly as it is, and the sequence is kept so you can start a new pass later.'),
confirmText: t('Use Fixed Week'),
- onConfirm: () => update(s => { if (!externalQ) s.queue = null; s.scheduleMode = 'week' }),
+ onConfirm: () => update(s => { if (!externalQ) stopPass(s); s.scheduleMode = 'week' }),
})
return
}
diff --git a/frontend/src/views/Settings.schedule.test.jsx b/frontend/src/views/Settings.schedule.test.jsx
index 299c7aef1..a325c265f 100644
--- a/frontend/src/views/Settings.schedule.test.jsx
+++ b/frontend/src/views/Settings.schedule.test.jsx
@@ -98,11 +98,14 @@ describe('Settings — Scheduling', () => {
expect(host.textContent).toContain('Externally managed')
})
- it('Fixed Week asks first, then drops the pass and keeps the sequence', () => {
+ it('Fixed Week asks first, then drops the pass, sweeps its future pins, and keeps the sequence', () => {
mount({
queue: { ids: ['a', 'b'], since: Date.now(), startsOn: todayISO(), label: 'Rotation', rotationId: 'r1' },
rotation: { id: 'r1', sequence: ['a', 'b'], label: 'Rotation' },
week: { 1: ['a'] },
+ // a pin dated today names a session the dropped pass no longer has to give — left as a
+ // plain override, history.js would otherwise read it as a routine choice nobody made
+ dayPlan: { [todayISO()]: 'a', '2020-01-01': 'b' },
})
pick('Fixed Week')
expect(mocks.S.queue).not.toBe(null) // nothing happens before the confirmation
@@ -111,6 +114,7 @@ describe('Settings — Scheduling', () => {
expect(mocks.S.scheduleMode).toBe('week')
expect(mocks.S.rotation.sequence).toEqual(['a', 'b'])
expect(mocks.S.week).toEqual({ 1: ['a'] })
+ expect(mocks.S.dayPlan).toEqual({ '2020-01-01': 'b' }) // today's pin swept; the past one is not this pass's business
})
it('Rotation starts a fresh pass from the saved sequence', () => {