Merge !107: feat(checkin): track one-sided exercises per side (L/R)

This commit is contained in:
Duarte Santos committed 2026-09-07 19:38:14 +02:00
commit 30e91cd06a
21 files changed
+636 -37

No files matched your search

+51 -16
View File
@@ -1,7 +1,7 @@
// Pure helpers over the state object S (ported 1:1 from the vanilla app).
import { todayISO, isoOf, weekKey, weekStartOf, fmtNum } from './format.js'
import { isCardio, isBodyweightEq } from './exercises.js'
import { phaseForSet, modeForSet, modeForEntry, isWarmupRow, normalizeMode, extraVolumeOf, nextDropWeight, splitBurstReps } from './workout-model.js'
import { phaseForSet, modeForSet, modeForEntry, isWarmupRow, normalizeMode, extraVolumeOf, nextDropWeight, splitBurstReps, makeSideSet, isSideSet, syncSideAggregate } from './workout-model.js'
const objectOf = value => value && typeof value === 'object' && !Array.isArray(value) ? value : {}
// Completed-state-independent work rows whose authoritative mode matches the requested mode.
const workRowsForMode = (entry = {}, mode = 'reps') => {
@@ -110,16 +110,21 @@ export function setLabel(id, s, cfg) {
const mode = modeOf(c)
if (mode === 'cardio') return `${s.min || 0} min @ ${fmtNum(s.speed || 0)} km/h`
if (mode === 'time') return fmtSec(s.sec) + (s.w > 0 ? ` · ${fmtNum(s.w)}` : '')
const bw = isBw({ ...c, id: c.id ?? id })
// One side's "weight×reps" (or bodyweight "reps" / "+belt × reps"), the same shape a whole
// straight set reads as — reused for each side of a unilateral set below.
const oneSide = side => {
const reps = side.r || 0
return bw ? (side.w > 0 ? `+${fmtNum(side.w)} × ` : '') + reps : `${fmtNum(side.w || 0)}×${reps}`
}
// A unilateral set logged per side (issue #60) reads "L 15×8 · R 15×7" — the asymmetry is the
// whole point, so both sides are shown rather than a single combined total.
if (isSideSet(s)) {
return `${t('L')} ${oneSide(s.sides.L)}${effortTail(s.sides.L)} · ${t('R')} ${oneSide(s.sides.R)}${effortTail(s.sides.R)}`
}
// Bodyweight reads as what you did — "12", or "+10 × 12" once there is a belt involved —
// rather than "0×12", which says a set was performed with no weight and means nothing.
// A per-side set needs no mark here: the number logged is the total, the same as every
// other set in the app.
const reps = s.r || 0
if (isBw({ ...c, id: c.id ?? id })) {
const load = s.w > 0 ? `+${fmtNum(s.w)} × ` : ''
return `${load}${reps}` + effortTail(s)
}
return `${fmtNum(s.w || 0)}×${reps}` + effortTail(s)
return oneSide(s) + effortTail(s)
}
// Default config for a freshly added exercise.
export function defaultConfig(id, mode) {
@@ -372,11 +377,26 @@ function buildWorkSets(S, cfg, options = {}) {
const w = useTarget
? (cfg.weight > 0 ? cfg.weight : (lastRegular && lastRegular.r > 0 ? lastRegular.w : cfg.weight))
: preferLast && usable ? usable.w : (conf && conf.w > 0 ? conf.w : (usable ? usable.w : cfg.weight))
sets.push({ w, r: usable ? usable.r : cfg.reps, done: false })
const row = { w, r: usable ? usable.r : cfg.reps, done: false }
// A unilateral exercise logs each side on its own (issue #60): the row splits into L/R,
// each seeded with half the total reps at the same weight. When "last time" was itself a
// per-side set, carry its two sides over verbatim so an asymmetry you logged persists.
if (isPerSide(cfg)) sets.push(usable && isSideSet(usable) ? seedSideFromLast(row, usable) : makeSideSet(row))
else sets.push(row)
}
return sets
}
// Seed a fresh per-side row from a previous per-side set: same reps/weight each side, nothing
// done, no effort carried (that is logged afresh each session). Falls back to an even split if
// the previous row was not actually per-side.
function seedSideFromLast(row, prev) {
const base = makeSideSet(row)
if (!isSideSet(prev)) return base
const carry = s => ({ w: Number(s?.w) || 0, r: Number(s?.r) || 0, done: false })
return syncSideAggregate({ ...base, sides: { L: carry(prev.sides.L), R: carry(prev.sides.R) } })
}
/**
* Stamp every work row with the exercise's planned intensifier and pre-fill its drops/clusters,
* already computed and editable — the plan designs the set, not a button pressed mid-workout.
@@ -392,12 +412,19 @@ export function applyIntensifierPlan(sets, cfg) {
if (kind === 'dropset') {
const count = Math.max(1, Math.round(cfg.intensifier.count) || 1)
const pct = cfg.intensifier.pct
// Stamp a descending chain of drops onto a row (or one side of a per-side row): each drop is
// pct% lighter than the last, at that row/side's own rep count.
const withDrops = row => {
const drops = []
let w = row.w || 0
for (let k = 0; k < count; k++) { w = nextDropWeight(w, pct); drops.push({ w, r: row.r }) }
return { ...row, type: 'dropset', drops }
}
return sets.map(s => {
if (isWarmupRow(s)) return s
const drops = []
let w = s.w || 0
for (let k = 0; k < count; k++) { w = nextDropWeight(w, pct); drops.push({ w, r: s.r }) }
return { ...s, type: 'dropset', drops }
// A unilateral set drops per side (issue #60): stamp each side, then resync the aggregate.
if (isSideSet(s)) return syncSideAggregate({ ...s, sides: { L: withDrops(s.sides.L), R: withDrops(s.sides.R) } })
return withDrops(s)
})
}
// Rest-pause trains as exactly two sets, not one per configured `sets` count: a warm-up at
@@ -430,14 +457,22 @@ export function workoutVolume(w) {
}))
return v
}
// A unilateral row counts as two toward the "x / y sets" progress — one per side — since each
// side is logged and ticked on its own (issue #60). Every other row counts as one.
export const setUnits = s => (isSideSet(s) ? 2 : 1)
// How many of a row's units are done: both sides independently for a per-side row, else 0/1.
export const doneUnits = s => (isSideSet(s) ? (s.sides.L.done ? 1 : 0) + (s.sides.R.done ? 1 : 0) : (s.done ? 1 : 0))
// Total completion-units across a session's rows (both sides of every unilateral set counted).
export const setUnitsTotal = entries => (entries || []).reduce((n, e) => n + (e.sets || []).reduce((m, s) => m + setUnits(s), 0), 0)
export function setsDone(w) {
let n = 0
w.entries.forEach(e => e.sets.forEach(s => { if (s.done) n++ }))
w.entries.forEach(e => e.sets.forEach(s => { n += doneUnits(s) }))
return n
}
export function setsDoneActive(A) {
let n = 0
if (A) A.entries.forEach(e => e.sets.forEach(s => { if (s.done) n++ }))
if (A) A.entries.forEach(e => e.sets.forEach(s => { n += doneUnits(s) }))
return n
}
export const lastBW = S => (S.bodyweight.length ? S.bodyweight[S.bodyweight.length - 1] : null)
+63 -1
View File
@@ -1,5 +1,6 @@
import { describe, it, expect } from 'vitest'
import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from './history.js'
import { nextTrainingDay, modeOf, isTimed, fmtSec, setLabel, defaultConfig, buildSets, freestyleConfig, exLine, workoutVolume, bestWeightFor, bestWeightForEntry, effortOf, stepEffort, capEffort, isBw, isPerSide, sideReps, repStep, cascadeWeight, insertWarmupRow, removeRowAt, workSetsDone, setsDone, setsDoneActive, setUnits, doneUnits, setUnitsTotal, pairAdjacent, unpairSuperset, supersetUnits, applyIntensifierPlan, pinnedNoteFor, exNoteFor } from './history.js'
import { makeSideSet, setSideField, toggleSide } from './workout-model.js'
import { EXDB } from './exercises.js'
// Real ids out of the shipped catalogue, so the body-part fallback is exercised for real.
@@ -1019,3 +1020,64 @@ describe('nextTrainingDay', () => {
expect(nextTrainingDay(off, TUE)).toMatchObject({ weekday: 5 })
})
})
/* ---------- one-sided (unilateral) sets, logged per side (issue #60) ---------- */
// A per-side row carries its two sides and a scalar aggregate. These pin that the display shows
// both sides, and — crucially — that every aggregate-reading consumer (volume, best weight, the
// x/y-sets counters) treats the row correctly without knowing sides exist.
describe('setLabel — per side', () => {
it('shows both sides so an asymmetry is visible, not a single combined total', () => {
const s = setSideField(setSideField(makeSideSet({ w: 15, r: 16 }), 'R', 'r', 7), 'L', 'r', 8)
expect(setLabel(LIFT, s, { id: LIFT, side: true })).toBe('L 15×8 · R 15×7')
})
it('keeps each side effort tail and reads bodyweight sides as reps alone', () => {
let s = makeSideSet({ w: 0, r: 16 })
s = setSideField(s, 'L', 'rir', 1)
expect(setLabel(BW, s, { id: BW, side: true })).toBe('L 8 (RIR 1) · R 8')
})
})
describe('per-side aggregate stays readable by existing consumers', () => {
it('workoutVolume counts both sides via the row total, unchanged from a straight set', () => {
// 15×8 per side = 15×16 total = 240, exactly what a straight {w:15,r:16} would score.
const side = { ...makeSideSet({ w: 15, r: 16 }), done: true }
const synced = toggleSide(toggleSide(makeSideSet({ w: 15, r: 16 }), 'L'), 'R') // both done
const w = { entries: [{ id: LIFT, sets: [synced] }] }
expect(synced.done).toBe(true)
expect(workoutVolume(w)).toBe(240)
// and a straight equivalent scores the same
expect(workoutVolume({ entries: [{ id: LIFT, sets: [{ w: 15, r: 16, done: true }] }] })).toBe(240)
})
it('bestWeightForEntry reads the aggregate weight of a completed per-side set', () => {
const s = toggleSide(toggleSide(setSideField(makeSideSet({ w: 15, r: 16 }), 'R', 'w', 17.5), 'L'), 'R')
expect(bestWeightForEntry({ id: LIFT, target: { id: LIFT, side: true }, sets: [s] })).toBe(17.5)
})
})
describe('per-side set counters', () => {
it('setUnits counts a per-side row as two, a straight row as one', () => {
expect(setUnits(makeSideSet({ w: 15, r: 16 }))).toBe(2)
expect(setUnits({ w: 15, r: 16 })).toBe(1)
})
it('doneUnits counts each finished side independently', () => {
const none = makeSideSet({ w: 15, r: 16 })
expect(doneUnits(none)).toBe(0)
expect(doneUnits(toggleSide(none, 'L'))).toBe(1)
expect(doneUnits(toggleSide(toggleSide(none, 'L'), 'R'))).toBe(2)
expect(doneUnits({ w: 15, r: 16, done: true })).toBe(1)
})
it('setUnitsTotal / setsDoneActive account for both sides across the session', () => {
const A = { entries: [
{ id: LIFT, sets: [toggleSide(makeSideSet({ w: 15, r: 16 }), 'L'), makeSideSet({ w: 15, r: 16 })] }, // 2 rows × 2 sides = 4 units, 1 side done
{ id: LIFT, sets: [{ w: 60, r: 8, done: true }] }, // 1 straight, done
] }
expect(setUnitsTotal(A.entries)).toBe(5)
expect(setsDoneActive(A)).toBe(2)
expect(setsDone({ entries: A.entries })).toBe(2)
})
})
+2 -2
View File
@@ -28,10 +28,10 @@ describe('Brazilian Portuguese locale', () => {
const fingerprint = createHash('sha256').update(JSON.stringify(inherited)).digest('hex')
expect(Object.keys(PT_BR_OVERRIDES)).toHaveLength(626)
expect(inherited).toHaveLength(616)
expect(inherited).toHaveLength(619)
// If this fails, review the changed keys and wording before accepting a new hash. From
// frontend/: node scripts/pt-br-inheritance-fingerprint.mjs --list
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('3db560d7104c324bcc54c94867c5f1e2b7f5eedf393d55e424b1c8d0bd5e7901')
expect(fingerprint, 'pt-PT inheritance changed; review the inherited pt-BR wording').toBe('3f014849b963a9ef4fa3ef79ee9f3c9b790ca28b8c28447f78812d6af4729bc2')
})
test('does not leak European Portuguese UI terms', () => {
+157 -1
View File
@@ -56,7 +56,14 @@ export function clustersOf(set) {
* `clustersOf(set)` here as well would double-count the same reps twice.
*/
export function extraVolumeOf(set) {
const drops = dropsOf(set)
const source = objectOf(set)
// A per-side set carries its drops on each side (issue #60), so the extra volume is the sum of
// both sides' drops — the row itself has no `drops`. dropsOf reads a side's own {type,drops}.
if (isSideSet(source)) {
return [source.sides.L, source.sides.R].reduce(
(v, side) => v + dropsOf(side).reduce((n, d) => n + (Number(d?.w) || 0) * (Number(d?.r) || 0), 0), 0)
}
const drops = dropsOf(source)
return drops.reduce((v, d) => v + (Number(d?.w) || 0) * (Number(d?.r) || 0), 0)
}
@@ -128,6 +135,155 @@ export function splitBurstReps(total) {
return bursts
}
// --- one-sided (unilateral) sets (issue #60) -------------------------------------------------
//
// A unilateral exercise (cfg.side, see history.js isPerSide) is trained one limb at a time, and
// asymmetries are the whole point of tracking it — a stronger right that carries a weaker left is
// exactly what a single combined row hides. So a per-side row logs each side on its own: weight,
// reps, effort and its own done tick, held in `sides: { L, R }`.
//
// Like `drops`/`clusters`, this rides on the row while the row's own `w`/`r`/`done`/effort stay a
// correct aggregate of the two sides — so volume, 1RM, PRs, progression, recovery, history and the
// coach keep reading a row's scalar fields and need not know sides exist:
// r = L.r + R.r (the both-sides total, exactly what those readers expect of a per-side set)
// w = max(L.w, R.w) (the heavier side; the two are usually equal)
// done = L.done && R.done (a set counts done only once both sides are)
// effort= the harder side's rating (lower RIR / higher RPE), for the history tail only
// `syncSideAggregate` recomputes those scalars from `sides` after any per-side edit.
export function isSideSet(set) {
const s = objectOf(set)
return !!(s.sides && typeof s.sides === 'object' && s.sides.L && s.sides.R)
}
const sideOf = value => {
const v = objectOf(value)
const out = { w: Number(v.w) || 0, r: Number(v.r) || 0, done: v.done === true }
if (v.rir != null) out.rir = v.rir
if (v.rpe != null) out.rpe = v.rpe
// A side can carry its own intensifier (issue #60): drop-sets and rest-pause bursts are logged
// per limb, exactly like the main set, so the same {type, drops, clusters} shape rides on the
// side. Reuses the row-level helpers below (addDrop/dropsOf/…), which read this very shape.
if (v.type === 'dropset' || v.type === 'restpause') out.type = v.type
if (Array.isArray(v.drops)) out.drops = v.drops
if (Array.isArray(v.clusters)) out.clusters = v.clusters
return out
}
// Build a per-side row from a plain row: each side starts as half the row's total reps (a unilateral
// target is always even, so the split is whole) at the same weight, carrying nothing done yet.
export function makeSideSet(row = {}) {
const base = objectOf(row)
const half = Math.round((Number(base.r) || 0) / 2)
const w = Number(base.w) || 0
const side = () => ({ w, r: half, done: false })
const next = { ...base, sides: { L: side(), R: side() } }
// effort/done/reps on the parent become derived — drop any straight-set leftovers so the row
// carries one source of truth, then recompute the aggregate.
delete next.rir; delete next.rpe
return syncSideAggregate(next)
}
// Recompute the row's scalar mirror from its two sides. No-op (returns a shallow copy) for a row
// that is not per-side, so callers can pipe every edit through it unconditionally.
export function syncSideAggregate(row) {
const base = objectOf(row)
if (!isSideSet(base)) return { ...base }
const L = sideOf(base.sides.L)
const R = sideOf(base.sides.R)
const out = { ...base, sides: { L, R }, r: L.r + R.r, w: Math.max(L.w, R.w), done: L.done && R.done }
// The row's effort tail shows the harder side: fewer reps in reserve (lower RIR) or a higher RPE.
// Only one scale is ever in play, matching how a straight row carries rir XOR rpe.
delete out.rir; delete out.rpe
const rirs = [L.rir, R.rir].filter(v => v != null)
const rpes = [L.rpe, R.rpe].filter(v => v != null)
if (rirs.length) out.rir = Math.min(...rirs)
else if (rpes.length) out.rpe = Math.max(...rpes)
// Drops/clusters live on the sides now, so the row itself never carries them — only the shared
// `type` so isDropSet/isRestPauseSet still classify the set. extraVolumeOf reads the sides.
delete out.drops; delete out.clusters; delete out.type
const sideType = setType(L) !== 'straight' ? setType(L) : setType(R)
if (sideType !== 'straight') out.type = sideType
return out
}
// Patch one field on one side ('L'|'R'), returning a new row with the aggregate resynced. A null
// value clears an optional field (effort), mirroring how a straight row drops the key.
export function setSideField(row, side, field, value) {
const base = objectOf(row)
if (!isSideSet(base) || (side !== 'L' && side !== 'R')) return { ...base }
const cur = { ...sideOf(base.sides[side]) }
if (value == null && (field === 'rir' || field === 'rpe')) delete cur[field]
else cur[field] = value
return syncSideAggregate({ ...base, sides: { ...base.sides, [side]: cur } })
}
// Flip one side's done tick, resyncing the row's own done (true only when both sides are).
export function toggleSide(row, side) {
const base = objectOf(row)
if (!isSideSet(base) || (side !== 'L' && side !== 'R')) return { ...base }
const cur = { ...sideOf(base.sides[side]), done: !sideOf(base.sides[side]).done }
return syncSideAggregate({ ...base, sides: { ...base.sides, [side]: cur } })
}
// --- per-side intensifiers (drop-sets / rest-pause) --------------------------------------------
//
// On a unilateral set the intensifier is logged per limb too. The structure stays symmetric —
// both sides always carry the same number of drops/bursts — while each side's weights and reps
// are edited independently, mirroring how the main set works. These reuse the side-agnostic
// helpers above (addDrop/dropsOf/setDropAt/…) on each side object, then resync the aggregate.
// Apply an editing fn to a single side and resync (used to edit one side's drop/burst).
function patchSide(row, side, fn) {
const base = objectOf(row)
if (!isSideSet(base) || (side !== 'L' && side !== 'R')) return { ...base }
return syncSideAggregate({ ...base, sides: { ...base.sides, [side]: fn(sideOf(base.sides[side])) } })
}
// Apply an editing fn to both sides and resync (used to add/remove a drop/burst symmetrically).
function patchBothSides(row, fn) {
const base = objectOf(row)
if (!isSideSet(base)) return { ...base }
return syncSideAggregate({ ...base, sides: { L: fn(sideOf(base.sides.L), 'L'), R: fn(sideOf(base.sides.R), 'R') } })
}
// Append a drop to both sides, each seeded from its own side's weight (pct lighter) and reps.
export function addSideDrop(row, pct) {
return patchBothSides(row, side => {
const drops = dropsOf(side)
const base = drops.length ? drops[drops.length - 1].w : (side.w || 0)
return addDrop(side, { w: nextDropWeight(base, pct), r: side.r })
})
}
export function removeSideDropAt(row, i) {
return patchBothSides(row, side => removeDropAt(side, i))
}
export function setSideDropAt(row, side, i, patch) {
return patchSide(row, side, sd => setDropAt(sd, i, patch))
}
// Append a rest-pause burst to both sides, each seeded from its own side's rep count. The side's
// own `r` grows by the added burst, mirroring the non-per-side rule that a rest-pause row's `r`
// is the running total across its bursts.
export function addSideCluster(row, restSec) {
return patchBothSides(row, side => {
const clusters = clustersOf(side)
const base = clusters.length ? clusters[clusters.length - 1].r : (side.r || 0)
const added = nextBurstReps(base)
return { ...addCluster(side, { r: added, restSec }), r: (side.r || 0) + added }
})
}
export function removeSideClusterAt(row, i) {
return patchBothSides(row, side => {
const removed = clustersOf(side)[i]?.r || 0
return { ...removeClusterAt(side, i), r: Math.max(0, (side.r || 0) - removed) }
})
}
export function setSideClusterAt(row, side, i, r) {
return patchSide(row, side, sd => {
const delta = (Number(r) || 0) - (clustersOf(sd)[i]?.r || 0)
return { ...setClusterAt(sd, i, { r }), r: Math.max(0, (sd.r || 0) + delta) }
})
}
export function normalizeMode(value, fallback = 'reps') {
const token = typeof value === 'string' ? value.trim().toLowerCase() : ''
if (MODES.includes(token)) return token
+166
View File
@@ -4,6 +4,8 @@ import {
setType, isDropSet, isRestPauseSet, dropsOf, clustersOf, extraVolumeOf,
addDrop, addCluster, removeDropAt, removeClusterAt, setDropAt, setClusterAt,
nextDropWeight, nextBurstReps, splitBurstReps,
isSideSet, makeSideSet, syncSideAggregate, setSideField, toggleSide,
addSideDrop, removeSideDropAt, setSideDropAt, addSideCluster, removeSideClusterAt, setSideClusterAt,
} from './workout-model.js'
describe('phaseForSet / isWarmupRow', () => {
@@ -69,6 +71,14 @@ describe('extraVolumeOf', () => {
expect(extraVolumeOf({ w: 100, r: 5 })).toBe(0)
expect(extraVolumeOf({ phase: 'warmup', w: 20, r: 8 })).toBe(0)
})
it('sums both sides drops for a per-side drop-set (issue #60)', () => {
let s = addSideDrop(makeSideSet({ w: 20, r: 16 }), 20) // each side: one 16×8 drop
expect(extraVolumeOf(s)).toBe(16 * 8 * 2) // L + R
// an asymmetric edit is reflected
s = setSideDropAt(s, 'R', 0, { w: 10, r: 6 })
expect(extraVolumeOf(s)).toBe(16 * 8 + 10 * 6)
})
})
describe('addDrop / addCluster', () => {
@@ -179,3 +189,159 @@ describe('modeForSet / modeForEntry stay reps-mode for drop-sets and rest-pause
expect(modeForEntry(entry)).toBe('reps')
})
})
// One-sided (unilateral) sets: each side logged on its own, with the row's scalar w/r/done/effort
// kept as a correct aggregate so every other consumer (volume, 1RM, PRs, progression, counters)
// reads a per-side row exactly as it always read a straight one (issue #60).
describe('isSideSet', () => {
it('is true only for a row carrying both L and R sides', () => {
expect(isSideSet({ sides: { L: { w: 10, r: 8 }, R: { w: 10, r: 8 } } })).toBe(true)
expect(isSideSet({ w: 10, r: 8 })).toBe(false)
expect(isSideSet({ sides: { L: { w: 10, r: 8 } } })).toBe(false)
expect(isSideSet(null)).toBe(false)
})
})
describe('makeSideSet', () => {
it('splits the row total evenly across two sides at the same weight, nothing done', () => {
const s = makeSideSet({ w: 15, r: 16, done: false })
expect(isSideSet(s)).toBe(true)
expect(s.sides.L).toEqual({ w: 15, r: 8, done: false })
expect(s.sides.R).toEqual({ w: 15, r: 8, done: false })
// aggregate mirror: r = both sides, w = the (equal) weight, not done yet
expect(s.r).toBe(16)
expect(s.w).toBe(15)
expect(s.done).toBe(false)
})
it('drops any straight-set effort so the row carries a single source of truth', () => {
const s = makeSideSet({ w: 20, r: 10, rir: 2 })
expect(s.rir).toBeUndefined()
expect(s.rpe).toBeUndefined()
})
})
describe('syncSideAggregate', () => {
it('recomputes r as the sum, w as the heavier side, done only when both sides are', () => {
const row = { sides: { L: { w: 15, r: 8, done: true }, R: { w: 17.5, r: 6, done: false } } }
const s = syncSideAggregate(row)
expect(s.r).toBe(14)
expect(s.w).toBe(17.5)
expect(s.done).toBe(false)
const bothDone = syncSideAggregate({ sides: { L: { w: 15, r: 8, done: true }, R: { w: 15, r: 8, done: true } } })
expect(bothDone.done).toBe(true)
})
it('takes the harder side for the row effort — lower RIR, higher RPE', () => {
const rir = syncSideAggregate({ sides: { L: { w: 15, r: 8, rir: 3 }, R: { w: 15, r: 8, rir: 1 } } })
expect(rir.rir).toBe(1)
expect(rir.rpe).toBeUndefined()
const rpe = syncSideAggregate({ sides: { L: { w: 15, r: 8, rpe: 7 }, R: { w: 15, r: 8, rpe: 9 } } })
expect(rpe.rpe).toBe(9)
expect(rpe.rir).toBeUndefined()
})
it('leaves a non-per-side row alone (returns a copy)', () => {
const s = syncSideAggregate({ w: 20, r: 10, done: true })
expect(s).toEqual({ w: 20, r: 10, done: true })
expect(isSideSet(s)).toBe(false)
})
})
describe('setSideField', () => {
it('patches one side and resyncs the aggregate', () => {
const base = makeSideSet({ w: 15, r: 16 })
const s = setSideField(base, 'R', 'w', 17.5)
expect(s.sides.R.w).toBe(17.5)
expect(s.sides.L.w).toBe(15)
expect(s.w).toBe(17.5) // aggregate = heavier side
})
it('clears an effort field on null, mirroring how a straight row drops the key', () => {
let s = setSideField(makeSideSet({ w: 15, r: 16 }), 'L', 'rir', 2)
expect(s.sides.L.rir).toBe(2)
expect(s.rir).toBe(2)
s = setSideField(s, 'L', 'rir', null)
expect(s.sides.L.rir).toBeUndefined()
expect(s.rir).toBeUndefined()
})
it('ignores an unknown side without throwing', () => {
const base = makeSideSet({ w: 15, r: 16 })
expect(isSideSet(setSideField(base, 'X', 'w', 20))).toBe(true)
})
})
describe('toggleSide', () => {
it('flips one side and marks the row done only once both sides are', () => {
let s = makeSideSet({ w: 15, r: 16 })
expect(s.done).toBe(false)
s = toggleSide(s, 'L')
expect(s.sides.L.done).toBe(true)
expect(s.done).toBe(false) // R still open
s = toggleSide(s, 'R')
expect(s.sides.R.done).toBe(true)
expect(s.done).toBe(true) // both sides done → row done
s = toggleSide(s, 'L')
expect(s.done).toBe(false) // un-tick one side → row no longer done
})
})
// Per-side intensifiers: a unilateral set's drop-sets and rest-pause bursts are logged per limb
// too (issue #60). The structure stays symmetric (both sides carry the same count) while each
// side's numbers are edited independently; drops/clusters live on the sides, and the aggregate's
// extra volume sums both.
describe('addSideDrop / removeSideDropAt / setSideDropAt', () => {
it('adds a drop to both sides, each seeded from its own side weight and reps', () => {
let s = makeSideSet({ w: 20, r: 16 }) // sides: 20×8 each
s = setSideField(s, 'R', 'w', 18) // make the sides asymmetric first
s = addSideDrop(s, 20) // 20% lighter
expect(s.sides.L.drops).toEqual([{ w: 16, r: 8 }]) // 20 → 16
expect(s.sides.R.drops).toEqual([{ w: 14.5, r: 8 }]) // 18 → 14.4 → rounds to 14.5
expect(s.type).toBe('dropset') // aggregate mirrors the intensifier type
expect(s.drops).toBeUndefined() // drops live on the sides, not the row
})
it('edits one side drop independently, leaving the other side untouched', () => {
let s = addSideDrop(makeSideSet({ w: 20, r: 16 }), 20)
s = setSideDropAt(s, 'L', 0, { w: 12 })
expect(s.sides.L.drops[0].w).toBe(12)
expect(s.sides.R.drops[0].w).toBe(16)
})
it('removes a drop from both sides, reverting to straight when the last goes', () => {
let s = addSideDrop(makeSideSet({ w: 20, r: 16 }), 20)
s = removeSideDropAt(s, 0)
expect(s.sides.L.drops).toEqual([])
expect(s.sides.R.drops).toEqual([])
expect(s.type).toBeUndefined() // no side is a drop-set anymore
})
})
describe('addSideCluster / removeSideClusterAt / setSideClusterAt', () => {
it('adds a burst to both sides and grows each side reps by its own added burst', () => {
let s = makeSideSet({ w: 20, r: 16 }) // 8 per side
s = addSideCluster(s, 15) // nextBurstReps(8) = 4
expect(s.sides.L.clusters).toEqual([{ r: 4, restSec: 15 }])
expect(s.sides.L.r).toBe(12) // 8 + 4
expect(s.sides.R.r).toBe(12)
expect(s.r).toBe(24) // aggregate total across both sides
expect(s.type).toBe('restpause')
})
it('editing one side burst keeps that side reps in step and leaves the other alone', () => {
let s = addSideCluster(makeSideSet({ w: 20, r: 16 }), 15) // L/R: r 12, burst 4
s = setSideClusterAt(s, 'L', 0, 6) // +2 on L
expect(s.sides.L.clusters[0].r).toBe(6)
expect(s.sides.L.r).toBe(14) // 12 + 2
expect(s.sides.R.r).toBe(12) // untouched
})
it('removing a burst subtracts its reps from that side', () => {
let s = addSideCluster(makeSideSet({ w: 20, r: 16 }), 15) // r 12 each
s = removeSideClusterAt(s, 0)
expect(s.sides.L.clusters).toEqual([])
expect(s.sides.L.r).toBe(8) // back to the base
expect(s.type).toBeUndefined()
})
})