Matériel coché dans le profil, bibliothèque « ce que mon matériel permet » (5a)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-23 02:12:25 +01:00
co-authored by Claude Opus 5.5
parent 938d6cf198
commit 72adffb613
15 changed files with 281 additions and 20 deletions
+66
View File
@@ -0,0 +1,66 @@
// Le matériel coché (lot 5a) : ce que demande chaque exercice, ce qui manque,
// le profil, la bibliothèque et le texte pour l'IA. Glossaire : docs/glossaire/materiel.md
import { test } from "node:test";
import assert from "node:assert/strict";
import { EXERCISES } from "../../app/domain/exercises.js";
import { KIT, canDo, isKit, kitLabels, missingKit, requiredKit } from "../../app/domain/kit.js";
import { DEFAULT_PROFILE, validateProfile } from "../../app/domain/profile.js";
import { filterLibrary, formatCriteria, parseCriteria } from "../../app/domain/library.js";
import { buildEvolutionBrief, buildOnboardingBrief } from "../../app/domain/ai-brief.js";
import { createEvent } from "../../app/domain/events.js";
import { foldEvents } from "../../app/domain/state.js";
import { profileFromForm } from "../../app/ui/screens/profile.js";
test("chaque exercice demande du matériel connu ; la catégorie et les exceptions s'additionnent", () => {
for (const ref of Object.keys(EXERCISES)) for (const k of requiredKit(ref)) assert.ok(isKit(k), `${ref} : ${k}`);
assert.deepEqual(requiredKit("bench-press").sort(), ["barbell", "bench", "rack"]);
assert.deepEqual(requiredKit("pull-up"), ["pullup-bar"]);
assert.deepEqual(requiredKit("push-up"), []);
assert.deepEqual(requiredKit("rowing-machine"), ["rower"]);
assert.deepEqual(requiredKit("inconnu"), [], "hors bibliothèque : on ne sait pas, rien n'est exigé");
// Tout ce qui n'est pas au poids du corps demande quelque chose.
for (const [ref, x] of Object.entries(EXERCISES))
if (x.equipment !== "bodyweight") assert.ok(requiredKit(ref).length > 0, `${ref} (${x.equipment}) ne demande rien`);
});
test("ce qui manque : rien tant que le matériel n'est pas renseigné", () => {
assert.deepEqual(missingKit("bench-press", undefined), []);
assert.deepEqual(missingKit("bench-press", ["barbell", "bench"]), ["rack"]);
assert.equal(canDo("bench-press", ["barbell", "bench", "rack"]), true);
assert.equal(canDo("push-up", []), true);
assert.deepEqual(kitLabels(["bench", "barbell"]), ["Barre et disques", "Banc"], "dans l'ordre de KIT");
});
test("profil : kit facultatif, clés connues, sans doublon", () => {
assert.deepEqual(validateProfile(DEFAULT_PROFILE), []);
assert.deepEqual(validateProfile({ ...DEFAULT_PROFILE, kit: ["barbell", "rack"] }), []);
assert.deepEqual(validateProfile({ ...DEFAULT_PROFILE, kit: [] }), []);
assert.match(validateProfile({ ...DEFAULT_PROFILE, kit: ["trampoline"] })[0], /'kit'/);
assert.match(validateProfile({ ...DEFAULT_PROFILE, kit: ["bench", "bench"] })[0], /'kit'/);
});
test("formulaire du profil : kit omis s'il n'a jamais été renseigné, dans l'ordre de KIT sinon", () => {
const form = { goal: "", context: "", equipment: "", constraints: "", heightCm: "", sessionMinutes: "50" };
assert.equal("kit" in profileFromForm(form).profile, false);
assert.deepEqual(profileFromForm({ ...form, kit: ["bench", "barbell"] }).profile.kit, ["barbell", "bench"]);
assert.deepEqual(profileFromForm({ ...form, kit: [] }).profile.kit, []);
});
test("bibliothèque : « ce que mon matériel permet », gardé dans l'adresse", () => {
assert.deepEqual(parseCriteria("possible=1"), { possible: true });
assert.equal(formatCriteria({ possible: true, zone: "upper" }), "zone=upper&possible=1");
const refs = (/** @type {any} */ c, /** @type {string[]|undefined} */ kit) => filterLibrary(c, kit).flatMap((g) => g.items.map((i) => i.ref));
const bodyweight = refs({ possible: true }, []);
assert.ok(bodyweight.includes("push-up") && !bodyweight.includes("pull-up") && !bodyweight.includes("squat"));
assert.ok(refs({ possible: true }, ["pullup-bar"]).includes("pull-up"));
assert.equal(refs({ possible: true }, undefined).length, Object.keys(EXERCISES).length, "matériel non renseigné : tout");
});
test("texte pour l'IA : le format du profil liste les clés, le profil montre le matériel coché", () => {
assert.match(buildOnboardingBrief({ baseUrl: "https://ia-fit.example" }), /kit\?: \[matériel coché, parmi "barbell", "rack"/);
const profile = { ...DEFAULT_PROFILE, kit: /** @type {any} */ (["barbell", "bench"]) };
const s = foldEvents([createEvent("ProfileUpdated", { profile }, { device: "d", at: "2026-11-01T10:00:00.000Z" })]);
assert.match(buildEvolutionBrief(s, { today: "2026-11-02", baseUrl: "https://ia-fit.example" }), /Matériel coché : Barre et disques, Banc/);
assert.match(buildEvolutionBrief(foldEvents([]), { today: "2026-11-02", baseUrl: "https://ia-fit.example" }), /Matériel coché : non renseigné/);
assert.equal(Object.keys(KIT).length >= 20, true);
});