WOD : séance à format, chrono et score (lot 4b, ADR 0010)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
d9604d43ec
commit
ee3f55a515
@@ -4,7 +4,7 @@ import assert from "node:assert/strict";
|
||||
import { createEvent } from "../../app/domain/events.js";
|
||||
import { foldEvents } from "../../app/domain/state.js";
|
||||
import {
|
||||
buildSessionData, completion, createDraft, draftMatches, draftTotals, markSet, parseReplace, proposedReps, replaceExercise, replaceQuery, sessionDataOf, sessionSummary, setsInOrder, targetLabel, targetReps,
|
||||
buildSessionData, completion, createDraft, draftMatches, draftTotals, markSet, parseReplace, proposedReps, replaceExercise, replaceQuery, sessionDataOf, sessionSummary, wodElapsed, wodMissing, setsInOrder, targetLabel, targetReps,
|
||||
} from "../../app/ui/session-draft.js";
|
||||
import { PROGRAM } from "./fixtures.js";
|
||||
|
||||
@@ -184,3 +184,34 @@ test("adresse du mode choix : remplacer=A.3, relue ; invalide ignorée", () => {
|
||||
assert.deepEqual(parseReplace("remplacer=A.3&zone=lower"), { sessionKey: "A", index: 2 });
|
||||
for (const q of ["", "remplacer=A", "remplacer=A.0", "remplacer=ABCD.1", "remplacer=A.x"]) assert.equal(parseReplace(q), null, q);
|
||||
});
|
||||
|
||||
test("séance WOD : horloge calée sur l'heure, score exigé selon le format, SessionLogged valide", () => {
|
||||
const W = { key: "W", name: "Fran", format: { type: /** @type {const} */ ("fortime"), capMinutes: 10 },
|
||||
exercises: [{ ref: "barbell-thruster", sets: 1, reps: "21-15-9", rest: 0 }, { ref: "kipping-pull-up", sets: 1, reps: "21-15-9", rest: 0 }] };
|
||||
const program = { ...PROGRAM, sessions: [...PROGRAM.sessions, W] };
|
||||
const state = foldEvents([createEvent("ProgramAdopted", { program, source: "ai" }, { device, at: "2026-11-01T10:00:00.000Z" })]);
|
||||
const d = createDraft(W, state, "2026-11-18", 0);
|
||||
const w = /** @type {NonNullable<typeof d.wod>} */ (d.wod);
|
||||
assert.deepEqual(w, { format: W.format, startedAt: null, banked: 0, rx: true, seconds: null, rounds: null, reps: null, kg: null, capped: false });
|
||||
assert.ok(!draftMatches(structuredClone(d), A, 0), "pas pour une autre séance");
|
||||
assert.ok(draftMatches(structuredClone(d), W, 0));
|
||||
assert.ok(!draftMatches({ ...structuredClone(d), wod: undefined }, W, 0), "un brouillon sans WOD n'est pas repris");
|
||||
// horloge
|
||||
w.banked = 30; w.startedAt = 1_000_000;
|
||||
assert.equal(wodElapsed(w, 1_010_000), 40);
|
||||
w.startedAt = null;
|
||||
assert.equal(wodElapsed(w, 9e9), 30);
|
||||
// score
|
||||
assert.match(String(wodMissing(w)), /temps/);
|
||||
w.capped = true; w.reps = 18;
|
||||
assert.equal(wodMissing(w), null);
|
||||
const data = buildSessionData(d);
|
||||
assert.deepEqual(data.wod, { format: W.format, rx: true, seconds: null, rounds: null, reps: 18, kg: null, capped: true });
|
||||
assert.deepEqual(data.exercises.map((x) => x.sets.length), [1, 1], "chaque mouvement compte pour une série");
|
||||
const logged = foldEvents([createEvent("ProgramAdopted", { program, source: "ai" }, { device, at: "2026-11-01T10:00:00.000Z" }), createEvent("SessionLogged", data, { device, at: "2026-11-18T10:00:00.000Z" })]);
|
||||
assert.equal(logged.sessions.length, 1);
|
||||
assert.equal(sessionSummary(logged.sessions[0]), "WOD · Cap + 18 rép. · RX");
|
||||
// AMRAP : les tours sont obligatoires
|
||||
const amrap = createDraft({ ...W, format: { type: "amrap", minutes: 12 } }, state, "2026-11-18", 0);
|
||||
assert.match(String(wodMissing(/** @type {any} */ (amrap.wod))), /tours/);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user