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
@@ -379,6 +379,38 @@ function check(scheme, cond, msg) {
|
||||
await settle();
|
||||
ok(await monday.getByRole("button", { name: "Faite" }).isVisible(), "lundi : de nouveau à faire");
|
||||
|
||||
// ---- WOD (lot 4b) : séance à format, chrono, score ------------------------------
|
||||
const wodLink = await page.evaluate(async () => {
|
||||
const { store } = await import("./main.js");
|
||||
const program = structuredClone(store.getState().program);
|
||||
program.sessions.push({ key: "W", name: "Mini Fran", format: { type: "fortime", capMinutes: 2 }, warmup: [],
|
||||
exercises: [{ ref: "barbell-thruster", sets: 1, reps: "21-15-9", rest: 0, note: "RX 43 kg / 29 kg" }, { ref: "kipping-pull-up", sets: 1, reps: "21-15-9", rest: 0 }] });
|
||||
return "#import-json=" + encodeURIComponent(JSON.stringify({ program, reason: "Un WOD pour essayer." }));
|
||||
});
|
||||
await go(wodLink);
|
||||
await button("Adopter").click();
|
||||
await settle();
|
||||
await go("#/seance/W");
|
||||
ok(await page.locator(".wod-format__label").textContent() === "For Time · cap 2 min", "WOD : format affiché");
|
||||
ok(await page.locator(".wod-move").count() === 2, "WOD : deux mouvements");
|
||||
await button("Terminer la séance").click();
|
||||
ok(/temps/.test(await page.locator(".status").textContent() ?? ""), "WOD : score exigé avant d'enregistrer");
|
||||
await button("Démarrer").click();
|
||||
ok(await page.locator(".wod-clock__phase").textContent() === "Prêt ?", "WOD : compte à rebours");
|
||||
await page.clock.fastForward(5000 + 42000);
|
||||
await page.waitForTimeout(300);
|
||||
ok(await page.locator(".wod-clock__phase").textContent() === "Chrono · cap 2 min" && /^0:4\d$/.test(await page.locator(".wod-clock__time").textContent() ?? ""), "WOD : chrono lancé, il monte");
|
||||
await shot("23-wod", true);
|
||||
await button("Fini !").click();
|
||||
const wodTime = await page.locator("#wod-time").inputValue();
|
||||
ok(/^0:4\d$/.test(wodTime), "WOD : temps relevé au « Fini » : " + wodTime);
|
||||
await button("Scaled").click();
|
||||
await button("Terminer la séance").click();
|
||||
await settle();
|
||||
ok(page.url().endsWith("#/bravo"), "WOD : séance enregistrée");
|
||||
await go("#/historique");
|
||||
ok(await page.getByText(`WOD · ${wodTime} · Scaled`).first().isVisible(), "WOD : score dans l'historique");
|
||||
|
||||
// ---- réinitialisation --------------------------------------------------------------
|
||||
await go("#/donnees");
|
||||
await button("Tout effacer").click();
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { clockText, currentMovement, formatLabel, formatSeconds, parseClock, scoreLabel, validateFormat, wodClock, wodResultProblem } from "../../app/domain/wod.js";
|
||||
import { validateProgram } from "../../app/domain/program.js";
|
||||
import { estimatedMinutes } from "../../app/domain/progression.js";
|
||||
import { buildOnboardingBrief } from "../../app/domain/ai-brief.js";
|
||||
|
||||
test("formats valides et invalides, messages pour l'IA", () => {
|
||||
for (const f of [{ type: "amrap", minutes: 12 }, { type: "emom", minutes: 10, every: 90 }, { type: "fortime" }, { type: "fortime", rounds: 3, capMinutes: 15 },
|
||||
{ type: "tabata" }, { type: "tabata", rounds: 6, work: 30, rest: 15 }, { type: "rounds", rounds: 5 }])
|
||||
assert.deepEqual(validateFormat(f, "séance W"), [], JSON.stringify(f));
|
||||
assert.deepEqual(validateFormat({ type: "amrap" }, "séance W"), ["séance W : 'format.minutes' doit être un entier de 1 à 120."]);
|
||||
assert.match(validateFormat({ type: "hiit" }, "séance W")[0], /'format.type' doit valoir amrap, emom, fortime, tabata, rounds/);
|
||||
assert.match(validateFormat("amrap", "séance W")[0], /doit être un objet/);
|
||||
assert.deepEqual(validateFormat({ type: "fortime", capMinutes: 0 }, "s"), ["s : 'format.capMinutes' doit être un entier de 1 à 180."]);
|
||||
});
|
||||
|
||||
test("libellés et durées", () => {
|
||||
assert.equal(formatLabel({ type: "amrap", minutes: 12 }), "AMRAP 12 min");
|
||||
assert.equal(formatLabel({ type: "emom", minutes: 10 }), "EMOM 10 min");
|
||||
assert.equal(formatLabel({ type: "emom", minutes: 12, every: 90 }), "EMOM 12 min · toutes les 1:30");
|
||||
assert.equal(formatLabel({ type: "fortime", rounds: 3, capMinutes: 15 }), "For Time · 3 tours · cap 15 min");
|
||||
assert.equal(formatLabel({ type: "tabata" }), "Tabata 8 × 20 s / 10 s");
|
||||
assert.equal(formatSeconds({ type: "tabata" }), 240);
|
||||
assert.equal(formatSeconds({ type: "fortime" }), null);
|
||||
assert.equal(formatSeconds({ type: "fortime", capMinutes: 10 }), 600);
|
||||
});
|
||||
|
||||
test("horloge : AMRAP, EMOM, Tabata, For Time", () => {
|
||||
assert.deepEqual(wodClock({ type: "amrap", minutes: 12 }, 61.7), { phase: "work", round: null, rounds: null, remaining: 659, elapsed: 61 });
|
||||
assert.equal(wodClock({ type: "amrap", minutes: 12 }, 720).phase, "done");
|
||||
const emom = wodClock({ type: "emom", minutes: 10 }, 125);
|
||||
assert.deepEqual([emom.round, emom.rounds, emom.remaining], [3, 10, 55]);
|
||||
const t1 = wodClock({ type: "tabata" }, 19), t2 = wodClock({ type: "tabata" }, 20), t3 = wodClock({ type: "tabata" }, 31);
|
||||
assert.deepEqual([t1.phase, t1.round, t1.remaining], ["work", 1, 1]);
|
||||
assert.deepEqual([t2.phase, t2.round, t2.remaining], ["rest", 1, 10]);
|
||||
assert.deepEqual([t3.phase, t3.round], ["work", 2]);
|
||||
assert.equal(wodClock({ type: "tabata" }, 240).phase, "done");
|
||||
assert.deepEqual(wodClock({ type: "fortime" }, 400), { phase: "work", round: null, rounds: null, remaining: null, elapsed: 400 });
|
||||
assert.equal(wodClock({ type: "fortime", capMinutes: 10 }, 600).phase, "done");
|
||||
assert.equal(currentMovement(emom, 2), 0);
|
||||
assert.equal(currentMovement(t3, 2), 1);
|
||||
assert.equal(currentMovement(wodClock({ type: "amrap", minutes: 5 }, 10), 3), null);
|
||||
});
|
||||
|
||||
test("temps saisis et score en mots", () => {
|
||||
assert.equal(clockText(462), "7:42");
|
||||
for (const [t, s] of [["7:42", 462], ["7 min 42", 462], ["12 min", 720], ["95", 95], ["95 s", 95], ["", null], ["abc", null], ["7:99", null]])
|
||||
assert.equal(parseClock(/** @type {string} */ (t)), s, String(t));
|
||||
const base = { rx: true, seconds: null, rounds: null, reps: null, kg: null, capped: false };
|
||||
assert.equal(scoreLabel({ ...base, format: { type: "amrap", minutes: 12 }, rounds: 5, reps: 12 }), "5 tours + 12 rép. · RX");
|
||||
assert.equal(scoreLabel({ ...base, format: { type: "fortime" }, seconds: 462, rx: false }), "7:42 · Scaled");
|
||||
assert.equal(scoreLabel({ ...base, format: { type: "fortime", capMinutes: 10 }, capped: true, reps: 18, kg: 42.5 }), "Cap + 18 rép. · 42,5 kg · RX");
|
||||
assert.equal(wodResultProblem({ ...base, format: { type: "amrap", minutes: 12 } }), null);
|
||||
assert.match(String(wodResultProblem({ ...base, format: { type: "amrap" } })), /format/);
|
||||
assert.match(String(wodResultProblem({ ...base, format: { type: "fortime" }, seconds: -1 })), /seconds/);
|
||||
});
|
||||
|
||||
test("une séance WOD dans le programme : validée, durée estimée, exemple de ia.md valide", () => {
|
||||
const brief = buildOnboardingBrief({ baseUrl: "https://ia-fit.sans.pub" });
|
||||
const fran = JSON.parse(/### Écrire un WOD[\s\S]*?```\n(\{.*\})\n```/.exec(brief)?.[1] ?? "null");
|
||||
assert.equal(fran.name, "Fran");
|
||||
assert.deepEqual(validateProgram({ name: "P", sessions: [fran] }), []);
|
||||
// échauffement (3 min + 1 min) + approche (thruster chargé) 3 min + cap 10 min + 5 min de mise en place
|
||||
assert.equal(estimatedMinutes(fran), 20);
|
||||
assert.match(validateProgram({ name: "P", sessions: [{ ...fran, format: { type: "emom" } }] })[0], /séance W : 'format.minutes'/);
|
||||
});
|
||||
@@ -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