WOD du jour composé par l'app, hors ligne (5c)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
442b3f0a56
commit
7194530b38
@@ -42,6 +42,8 @@ const server = http.createServer((req, res) => {
|
||||
});
|
||||
|
||||
let failures = 0;
|
||||
/** Les derniers messages de la page (console, erreurs), pour le diagnostic d'un arrêt. */
|
||||
const pageLog = [];
|
||||
/** Page en cours, pour une capture si le parcours s'interrompt. */
|
||||
let lastPage = null;
|
||||
/** @param {string} scheme @param {boolean} cond @param {string} msg */
|
||||
@@ -69,7 +71,8 @@ function check(scheme, cond, msg) {
|
||||
const page = await ctx.newPage();
|
||||
lastPage = page;
|
||||
const errors = [];
|
||||
page.on("pageerror", (e) => errors.push(String(e)));
|
||||
page.on("pageerror", (e) => { errors.push(String(e)); pageLog.push("pageerror: " + String(e)); });
|
||||
page.on("console", (m) => pageLog.push(`${m.type()}: ${m.text()}`.slice(0, 300)));
|
||||
page.on("console", (m) => { if (m.type() === "error") errors.push(m.text()); });
|
||||
const ok = (cond, msg) => check(scheme, cond, msg);
|
||||
const shot = (name, full = false) => page.screenshot({ path: `${outDir}/${scheme}-${name}.png`, fullPage: full });
|
||||
@@ -576,7 +579,19 @@ function check(scheme, cond, msg) {
|
||||
await go("#/");
|
||||
await page.getByRole("link", { name: /^WOD/ }).click();
|
||||
await settle();
|
||||
ok(await page.locator("h1").textContent() === "Références" && await page.getByRole("link", { name: /Fran · For Time/ }).isVisible(), "catalogue des WOD de référence");
|
||||
ok(await page.locator("h1").textContent() === "WOD" && await page.getByRole("link", { name: /Fran · For Time/ }).isVisible(), "catalogue des WOD de référence");
|
||||
// WOD du jour (lot 5c) : composé par l'app, un autre tirage dans l'adresse, le même en rouvrant.
|
||||
const daily = page.locator(".wod-daily");
|
||||
ok(await daily.getByRole("heading", { name: "WOD du jour" }).isVisible() && await daily.locator(".wod-move").count() >= 2, "WOD du jour composé par l'app");
|
||||
const firstDraw = await daily.locator(".wod-moves").innerText();
|
||||
await daily.getByRole("button", { name: "Un autre" }).click();
|
||||
ok(page.url().endsWith("#/wod?tirage=2"), "un autre tirage, dans l'adresse : " + page.url().split("#")[1]);
|
||||
const secondDraw = await daily.locator(".wod-moves").innerText();
|
||||
await shot("24a-wod-du-jour");
|
||||
await go("#/wod?tirage=2");
|
||||
ok(await page.locator(".wod-daily .wod-moves").innerText() === secondDraw, "même tirage, même WOD");
|
||||
await go("#/wod");
|
||||
ok(await page.locator(".wod-daily .wod-moves").innerText() === firstDraw, "tirage 1 retrouvé");
|
||||
await page.getByRole("link", { name: /Cindy · AMRAP 20 min/ }).click();
|
||||
await settle();
|
||||
ok(page.url().endsWith("#/wod/cindy") && await page.getByText("Scaled : ").isVisible(), "fiche de Cindy, avec sa variante scaled");
|
||||
@@ -631,7 +646,17 @@ function check(scheme, cond, msg) {
|
||||
process.exit(failures ? 1 : 0);
|
||||
})().catch(async (e) => {
|
||||
console.error(e);
|
||||
if (lastPage) await lastPage.screenshot({ path: `${outDir}/erreur.png`, fullPage: true }).catch(() => {});
|
||||
if (lastPage) {
|
||||
await lastPage.screenshot({ path: `${outDir}/erreur.png`, fullPage: true }).catch(() => {});
|
||||
// De quoi comprendre une page restée vide : état du document, scripts chargés, erreurs.
|
||||
const diag = await lastPage.evaluate(() => ({
|
||||
url: location.href, readyState: document.readyState, bodyChildren: document.body?.children.length ?? null,
|
||||
scripts: performance.getEntriesByType("resource").filter((r) => /\.js$/.test(r.name)).length,
|
||||
slowest: performance.getEntriesByType("resource").sort((a, b) => b.duration - a.duration).slice(0, 3).map((r) => `${r.name.split("/").pop()} ${Math.round(r.duration)} ms`),
|
||||
})).catch((err) => ({ evaluate: String(err) }));
|
||||
console.error("Diagnostic :", JSON.stringify(diag));
|
||||
console.error("Messages de la page :", JSON.stringify(pageLog.slice(-15)));
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
// Le générateur de WOD du jour (lot 5c) : déterministe, valide, faisable avec le
|
||||
// matériel, varié, sans répéter les mouvements récents.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { generateWod, WOD_MOVES } from "../../app/domain/wod-generator.js";
|
||||
import { EXERCISES } from "../../app/domain/exercises.js";
|
||||
import { KIT, canDo } from "../../app/domain/kit.js";
|
||||
import { validateProgram } from "../../app/domain/program.js";
|
||||
import { checkProgram } from "../../app/domain/checks.js";
|
||||
import { DEFAULT_PROFILE } from "../../app/domain/profile.js";
|
||||
|
||||
const KITS = [undefined, [], Object.keys(KIT), ["dumbbells", "pullup-bar"], ["barbell", "rower"], ["kettlebell", "jump-rope", "box"]];
|
||||
const DAYS = ["2026-11-23", "2026-11-24", "2026-12-01", "2027-03-15"];
|
||||
const modality = (/** @type {string} */ ref) => WOD_MOVES.find((x) => x.ref === ref)?.m;
|
||||
|
||||
test("chaque mouvement du générateur est dans la bibliothèque", () => {
|
||||
for (const x of WOD_MOVES) assert.ok(EXERCISES[x.ref], x.ref);
|
||||
});
|
||||
|
||||
test("le même jour, le même matériel et le même tirage donnent le même WOD ; un autre tirage, un autre", () => {
|
||||
const a = generateWod({ today: "2026-11-23", kit: Object.keys(KIT) });
|
||||
assert.deepEqual(generateWod({ today: "2026-11-23", kit: Object.keys(KIT) }), a);
|
||||
const others = [2, 3, 4, 5].map((draw) => JSON.stringify(generateWod({ today: "2026-11-23", draw, kit: Object.keys(KIT) }).exercises));
|
||||
assert.ok(others.some((x) => x !== JSON.stringify(a.exercises)));
|
||||
assert.equal(a.name, "WOD du jour · 23 nov.");
|
||||
assert.equal(generateWod({ today: "2026-11-23", draw: 2 }).name, "WOD du jour · 23 nov. (2)");
|
||||
});
|
||||
|
||||
test("toujours valide, ponctuel, faisable avec le matériel, sans alerte des règles de l'app", () => {
|
||||
for (const kit of KITS) for (const today of DAYS) for (let draw = 1; draw <= 8; draw++) {
|
||||
const session = generateWod({ today, draw, kit });
|
||||
const program = { name: "P", sessions: [{ key: "J1", ...session }] };
|
||||
const where = `${JSON.stringify(kit)} ${today} #${draw}`;
|
||||
assert.deepEqual(validateProgram(program), [], where);
|
||||
assert.equal(session.oneOff, true);
|
||||
assert.ok(session.exercises.length >= 2 && session.exercises.length <= 3, where);
|
||||
assert.equal(new Set(session.exercises.map((x) => x.ref)).size, session.exercises.length, where + " : doublon");
|
||||
for (const x of session.exercises) assert.ok(canDo(/** @type {string} */ (x.ref), kit ?? []), `${where} : ${x.ref}`);
|
||||
assert.deepEqual(checkProgram(program, { ...DEFAULT_PROFILE, kit: /** @type {any} */ (kit) }), [], where);
|
||||
}
|
||||
});
|
||||
|
||||
test("des modalités différentes quand le matériel le permet", () => {
|
||||
let mixed = 0, total = 0;
|
||||
for (const today of DAYS) for (let draw = 1; draw <= 10; draw++) {
|
||||
const s = generateWod({ today, draw, kit: Object.keys(KIT) });
|
||||
total++;
|
||||
if (new Set(s.exercises.map((x) => modality(/** @type {string} */ (x.ref)))).size === s.exercises.length) mixed++;
|
||||
}
|
||||
assert.equal(mixed, total, "salle complète : jamais deux mouvements de la même modalité");
|
||||
});
|
||||
|
||||
test("pas un mouvement des deux derniers jours, tant qu'il en reste d'autres ; aujourd'hui ne compte pas", () => {
|
||||
const kit = Object.keys(KIT);
|
||||
const first = generateWod({ today: "2026-11-23", kit });
|
||||
const done = (/** @type {string} */ date) => [{ date, exercises: first.exercises.map((x) => ({ id: /** @type {string} */ (x.ref) })) }];
|
||||
const next = generateWod({ today: "2026-11-23", kit, sessions: done("2026-11-22") });
|
||||
for (const x of next.exercises) assert.ok(!first.exercises.some((y) => y.ref === x.ref), `${x.ref} refait`);
|
||||
assert.deepEqual(generateWod({ today: "2026-11-23", kit, sessions: done("2026-11-23") }), first, "faire le WOD du jour ne le change pas");
|
||||
assert.deepEqual(generateWod({ today: "2026-11-23", kit, sessions: done("2026-11-19") }), first, "il y a quatre jours : sans effet");
|
||||
});
|
||||
Reference in New Issue
Block a user