Bibliothèque consultable (lot 3a), arbitrages du lot 4
Écran #/bibliotheque : recherche, filtres zone, muscle, famille et matériel dans l'adresse (nav.set), fiche avec place dans le programme, exercices proches et « Demander à mon IA » ; exercices génériques. #import-json= devient un fragment réservé. Plan du lot 4 (WOD). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
25639639cc
commit
be3e820b88
@@ -258,6 +258,37 @@ function check(scheme, cond, msg) {
|
||||
ok(await page.getByText("Premier pas").isVisible(), "succès « Premier pas »");
|
||||
await shot("14-progression", true);
|
||||
|
||||
// ---- bibliothèque : filtres dans l'adresse, fiche, retour (ADR 0009) -------------
|
||||
await go("#/");
|
||||
await page.getByRole("link", { name: /Bibliothèque/ }).click();
|
||||
await settle();
|
||||
ok(await page.locator("h1").textContent() === "Bibliothèque", "tuile vers la bibliothèque");
|
||||
await button("Bas du corps").click();
|
||||
await button("Fessiers").click();
|
||||
await page.locator("#lib-q").fill("pont");
|
||||
await page.waitForTimeout(400);
|
||||
ok(page.url().endsWith("#/bibliotheque?q=pont&zone=lower&muscle=glutes"), "filtres dans l'adresse : " + page.url().split("#")[1]);
|
||||
await shot("19-bibliotheque", true);
|
||||
await page.reload();
|
||||
await page.waitForSelector("h1");
|
||||
await settle();
|
||||
ok(await page.locator("#lib-q").inputValue() === "pont" && await button("Fessiers").getAttribute("aria-pressed") === "true", "filtres retrouvés après rechargement");
|
||||
const firstHit = page.locator(".lib-results .row").first();
|
||||
const hitName = (await firstHit.locator(".row__title").textContent()) ?? "";
|
||||
await firstHit.click();
|
||||
await settle();
|
||||
ok(await page.locator("h1").textContent() === hitName, "fiche : " + hitName);
|
||||
ok(await page.getByRole("heading", { name: "Exercices proches" }).isVisible(), "fiche : exercices proches");
|
||||
await shot("20-fiche", true);
|
||||
await page.goBack();
|
||||
await settle();
|
||||
ok(page.url().endsWith("?q=pont&zone=lower&muscle=glutes"), "retour : la liste filtrée");
|
||||
await go("#/bibliotheque/squat");
|
||||
ok(await page.getByText(/Fait \d+ fois/).isVisible(), "fiche du squat : historique et lien vers les analyses");
|
||||
await button(/Demander à mon IA/).click();
|
||||
await settle();
|
||||
ok(/## Ma demande/.test(await page.evaluate(() => navigator.clipboard.readText())), "texte pour l'IA copié");
|
||||
|
||||
// ---- données : export, texte pour l'IA, import ----------------------------------
|
||||
await go("#/donnees");
|
||||
const dl = page.waitForEvent("download");
|
||||
|
||||
@@ -0,0 +1,93 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { EXERCISES, MUSCLES } from "../../app/domain/exercises.js";
|
||||
import { EQUIPMENT_GROUPS, exerciseRequest, filterLibrary, formatCriteria, genericExercises, parseCriteria, similarExercises, usage } from "../../app/domain/library.js";
|
||||
import { createEvent } from "../../app/domain/events.js";
|
||||
import { foldEvents } from "../../app/domain/state.js";
|
||||
import { EXAMPLE_PROGRAM } from "../../app/domain/example-program.js";
|
||||
|
||||
const refs = (/** @type {ReturnType<typeof filterLibrary>} */ groups) => groups.flatMap((g) => g.items.map((i) => i.ref));
|
||||
|
||||
test("critères : lus dans l'adresse, valeurs inconnues ignorées, muscle cohérent avec la zone", () => {
|
||||
assert.deepEqual(parseCriteria(""), {});
|
||||
assert.deepEqual(parseCriteria("zone=lower&muscle=glutes&materiel=free&famille=legs&q=+fente+"),
|
||||
{ zone: "lower", muscle: "glutes", equipment: "free", family: "legs", q: "fente" });
|
||||
assert.deepEqual(parseCriteria("zone=lune&muscle=rate&materiel=x&famille=y&autre=1"), {});
|
||||
assert.deepEqual(parseCriteria("muscle=chest"), { zone: "upper", muscle: "chest" }, "le muscle fixe sa zone");
|
||||
assert.deepEqual(parseCriteria("zone=lower&muscle=chest"), { zone: "lower" }, "muscle hors zone ignoré");
|
||||
});
|
||||
|
||||
test("critères : écriture stable, relue à l'identique", () => {
|
||||
const c = { equipment: /** @type {const} */ ("band"), q: "développé couché", zone: /** @type {const} */ ("upper"), muscle: "chest" };
|
||||
const query = formatCriteria(c);
|
||||
assert.equal(query, "q=d%C3%A9velopp%C3%A9+couch%C3%A9&zone=upper&muscle=chest&materiel=band");
|
||||
assert.deepEqual(parseCriteria(query), c);
|
||||
assert.equal(formatCriteria({}), "");
|
||||
});
|
||||
|
||||
test("sans critère : toute la bibliothèque, par famille, triée par nom", () => {
|
||||
const groups = filterLibrary({});
|
||||
assert.equal(refs(groups).length, Object.keys(EXERCISES).length);
|
||||
for (const g of groups) {
|
||||
const names = g.items.map((i) => i.exercise.name);
|
||||
assert.deepEqual(names, [...names].sort((a, b) => a.localeCompare(b, "fr")), g.family);
|
||||
}
|
||||
});
|
||||
|
||||
test("recherche insensible aux accents et à la casse, sur le nom et la ref", () => {
|
||||
const found = refs(filterLibrary({ q: "DEVELOPPE couche" }));
|
||||
assert.ok(found.includes("bench-press"), found.join());
|
||||
assert.ok(refs(filterLibrary({ q: "pigeon" })).includes("pigeon-pose"));
|
||||
assert.ok(refs(filterLibrary({ q: "hip thrust" })).includes("hip-thrust"));
|
||||
assert.deepEqual(refs(filterLibrary({ q: "zzz" })), []);
|
||||
});
|
||||
|
||||
test("zone, muscle (principal) et matériel se combinent", () => {
|
||||
const glutes = refs(filterLibrary({ zone: "lower", muscle: "glutes" }));
|
||||
assert.ok(glutes.length > 5);
|
||||
assert.ok(glutes.every((r) => EXERCISES[r].primary.includes("glutes")), "muscle principal seulement");
|
||||
const upper = refs(filterLibrary({ zone: "upper" }));
|
||||
assert.ok(upper.every((r) => EXERCISES[r].primary.some((m) => MUSCLES[m].zone === "upper")));
|
||||
const band = refs(filterLibrary({ zone: "upper", equipment: "band" }));
|
||||
assert.ok(band.length > 0 && band.every((r) => EXERCISES[r].equipment === "band"));
|
||||
});
|
||||
|
||||
test("chaque matériel de la bibliothèque appartient à exactement un groupe", () => {
|
||||
const groups = Object.values(EQUIPMENT_GROUPS).map((g) => /** @type {readonly string[]} */ (g.equipment));
|
||||
for (const [ref, x] of Object.entries(EXERCISES))
|
||||
assert.equal(groups.filter((g) => g.includes(x.equipment)).length, 1, ref);
|
||||
});
|
||||
|
||||
test("exercices proches : même muscle principal d'abord, jamais l'exercice lui-même", () => {
|
||||
const near = similarExercises("leg-press");
|
||||
assert.ok(near.length >= 3 && near.length <= 6);
|
||||
assert.ok(!near.includes("leg-press"));
|
||||
assert.ok(EXERCISES[near[0]].primary.includes(EXERCISES["leg-press"].primary[0]));
|
||||
assert.deepEqual(similarExercises("inconnu"), []);
|
||||
});
|
||||
|
||||
test("usage : séances du programme, dernière fois, record ; exercices génériques", () => {
|
||||
const program = structuredClone(EXAMPLE_PROGRAM);
|
||||
program.sessions[0].exercises.push({ name: "Pigeon stretch", sets: 1, reps: "1 min", rest: 0 });
|
||||
const ev = (/** @type {string} */ date, /** @type {number} */ loadKg) => createEvent("SessionLogged", {
|
||||
date, kind: "strength", ref: "A", name: "A", warmup: null,
|
||||
exercises: [{ id: "squat", name: "Squat barre", target: "4 × 8", tracking: "load", loadKg, seconds: null, plannedSets: 4, sets: [{ reps: 8, effort: "ok" }] }],
|
||||
}, { device: "t" });
|
||||
const state = foldEvents([createEvent("ProgramAdopted", { program, source: "ai" }, { device: "t", at: "2026-11-01T00:00:00Z" }), ev("2026-11-03", 60), ev("2026-11-06", 57.5)]);
|
||||
const u = usage(state, "squat");
|
||||
assert.deepEqual(u.sessions.map((s) => s.key), ["A"]);
|
||||
assert.match(u.sessions[0].target, /^\d+ × /);
|
||||
assert.equal(u.times, 2);
|
||||
assert.equal(u.lastDate, "2026-11-06");
|
||||
assert.equal(u.lastLoadKg, 57.5);
|
||||
assert.equal(u.bestLoadKg, 60);
|
||||
assert.deepEqual(usage(state, "plank").times, 0);
|
||||
assert.deepEqual(genericExercises(state).map((x) => x.id), ["Pigeon stretch"]);
|
||||
assert.match(genericExercises(state)[0].tutorial, /youtube/);
|
||||
|
||||
const ask = exerciseRequest(state, "pigeon-pose", { today: "2026-11-18", baseUrl: "https://ia-fit.sans.pub" });
|
||||
assert.match(ask, /# IA-Fit : fais évoluer mon programme/);
|
||||
assert.match(ask, /## Ma demande\n\nJ'aimerais intégrer l'exercice « Posture du pigeon » \(`ref` : `pigeon-pose`\)/);
|
||||
assert.match(ask, /Propose où le placer/);
|
||||
assert.match(exerciseRequest(state, "squat", { today: "2026-11-18", baseUrl: "https://ia-fit.sans.pub" }), /déjà dans la séance A/);
|
||||
});
|
||||
@@ -56,7 +56,12 @@ test("routeur : une adresse par écran, #import= et #pair= réservés", () => {
|
||||
assert.deepEqual(parseRoute(href.historyEdit("abc-1")), { name: "history-edit", id: "abc-1" });
|
||||
assert.deepEqual(parseRoute("#import=xyz"), { name: "reserved" });
|
||||
assert.deepEqual(parseRoute("#pair=ABCD"), { name: "reserved" });
|
||||
assert.deepEqual(parseRoute("#import-json=%7B%7D"), { name: "reserved" });
|
||||
assert.deepEqual(parseRoute("#/nimporte/quoi/ici"), { name: "not-found" });
|
||||
// bibliothèque : la requête passe à l'écran (ADR 0009)
|
||||
assert.deepEqual(parseRoute(href.library()), { name: "library", query: "" });
|
||||
assert.deepEqual(parseRoute(href.library("zone=lower&muscle=glutes")), { name: "library", query: "zone=lower&muscle=glutes" });
|
||||
assert.deepEqual(parseRoute(href.libraryItem("Pigeon stretch")), { name: "library-item", id: "Pigeon stretch", query: "" });
|
||||
});
|
||||
|
||||
test("mise en forme française", () => {
|
||||
|
||||
Reference in New Issue
Block a user