Accueil, tutoriel, aide en questions, installation et mise à jour de l'application
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
3f5b00133d
commit
441bca1bd7
@@ -0,0 +1,84 @@
|
||||
// Tests de l'accueil et de l'invitation à installer, sans navigateur :
|
||||
// premier lancement, règles d'apparition de la carte d'installation,
|
||||
// réglages enregistrés par une version précédente.
|
||||
//
|
||||
// Copyright (C) 2026 les auteurs d'Ustagammon.
|
||||
// Licence : GPLv3 ou ultérieure (voir LICENSE).
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
import { installPlatform } from "../src/ui/install.js";
|
||||
import {
|
||||
DEFAULT_SETTINGS,
|
||||
INSTALL_AGAIN_AFTER,
|
||||
installCardShown,
|
||||
isFirstLaunch,
|
||||
parseSettings,
|
||||
type Settings,
|
||||
} from "../src/ui/settings.js";
|
||||
|
||||
test("réglages d'une version précédente : les nouveaux champs prennent leur valeur par défaut", () => {
|
||||
const old = parseSettings('{"vibrations": false, "theme": "dark", "gamesStarted": 4}');
|
||||
assert.equal(old.welcomed, false);
|
||||
assert.equal(old.gamesFinished, 0);
|
||||
assert.equal(old.tutorialSeen, 0);
|
||||
assert.equal(old.installed, false);
|
||||
const saved = parseSettings(
|
||||
'{"welcomed": true, "gamesFinished": 2, "tutorialSeen": 5, "installDismissals": 1, ' +
|
||||
'"installDismissedAt": 2, "installed": true}',
|
||||
);
|
||||
assert.deepEqual(saved, {
|
||||
...DEFAULT_SETTINGS,
|
||||
welcomed: true,
|
||||
gamesFinished: 2,
|
||||
tutorialSeen: 5,
|
||||
installDismissals: 1,
|
||||
installDismissedAt: 2,
|
||||
installed: true,
|
||||
});
|
||||
assert.equal(parseSettings('{"tutorialSeen": -3, "welcomed": "oui"}').tutorialSeen, 0);
|
||||
});
|
||||
|
||||
test("premier lancement : tant que rien n'a été fait, une seule fois", () => {
|
||||
assert.ok(isFirstLaunch(DEFAULT_SETTINGS));
|
||||
// La partie commencée d'office au chargement ne compte pas.
|
||||
assert.ok(isFirstLaunch({ ...DEFAULT_SETTINGS, gamesStarted: 1 }));
|
||||
assert.ok(!isFirstLaunch({ ...DEFAULT_SETTINGS, welcomed: true }));
|
||||
assert.ok(!isFirstLaunch({ ...DEFAULT_SETTINGS, gamesStarted: 2 }));
|
||||
assert.ok(!isFirstLaunch({ ...DEFAULT_SETTINGS, gamesFinished: 1 }));
|
||||
assert.ok(!isFirstLaunch({ ...DEFAULT_SETTINGS, tutorialSeen: 1 }));
|
||||
});
|
||||
|
||||
test("invitation à installer : après la première partie terminée, une seule relance", () => {
|
||||
const at = (changes: Partial<Settings>, installed = false) =>
|
||||
installCardShown({ ...DEFAULT_SETTINGS, ...changes }, installed);
|
||||
assert.ok(!at({}), "jamais avant la première partie terminée");
|
||||
assert.ok(at({ gamesFinished: 1 }));
|
||||
assert.ok(!at({ gamesFinished: 1 }, true), "jamais une fois installée");
|
||||
assert.ok(!at({ gamesFinished: 1, installed: true }));
|
||||
// « Plus tard » : masquée, puis de retour après trois parties de plus.
|
||||
const later = { installDismissals: 1, installDismissedAt: 1 };
|
||||
assert.equal(INSTALL_AGAIN_AFTER, 3);
|
||||
assert.ok(!at({ ...later, gamesFinished: 1 }));
|
||||
assert.ok(!at({ ...later, gamesFinished: 3 }));
|
||||
assert.ok(at({ ...later, gamesFinished: 4 }));
|
||||
// Une seconde fois « Plus tard » : plus jamais sur l'accueil.
|
||||
assert.ok(!at({ installDismissals: 2, installDismissedAt: 4, gamesFinished: 40 }));
|
||||
});
|
||||
|
||||
test("la marche à suivre pour installer dépend du navigateur", () => {
|
||||
const iphone =
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 " +
|
||||
"(KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1";
|
||||
const ipad = "Mozilla/5.0 (iPad; CPU OS 16_0 like Mac OS X) AppleWebKit/605.1.15";
|
||||
const firefox = "Mozilla/5.0 (Android 14; Mobile; rv:131.0) Gecko/131.0 Firefox/131.0";
|
||||
const chrome =
|
||||
"Mozilla/5.0 (Linux; Android 14) AppleWebKit/537.36 (KHTML, like Gecko) " +
|
||||
"Chrome/130.0 Mobile Safari/537.36";
|
||||
assert.equal(installPlatform(iphone), "ios");
|
||||
assert.equal(installPlatform(ipad), "ios");
|
||||
assert.equal(installPlatform(firefox), "firefox");
|
||||
// Sans invite du système, Chrome suit la marche à suivre de Firefox
|
||||
// (menu ⋮, « Installer »), la plus proche de la sienne.
|
||||
assert.equal(installPlatform(chrome), "firefox");
|
||||
});
|
||||
@@ -218,14 +218,18 @@ function sources(dir: string): string[] {
|
||||
}
|
||||
|
||||
test("aucune boîte native du navigateur (confirm, alert, prompt) dans l'application", () => {
|
||||
// Une méthode d'un autre objet ne compte pas : event.prompt() est l'invite
|
||||
// d'installation de Chrome (install.ts), pas une boîte de dialogue.
|
||||
for (const path of sources("app/src/")) {
|
||||
const text = read(path);
|
||||
assert.doesNotMatch(
|
||||
text,
|
||||
/\b(window\.)?(confirm|alert|prompt)\s*\(/,
|
||||
/(^|[^.\w])(window\.)?(confirm|alert|prompt)\s*\(/m,
|
||||
`${path} appelle une boîte native`,
|
||||
);
|
||||
}
|
||||
assert.match("window.alert(1)", /(^|[^.\w])(window\.)?(confirm|alert|prompt)\s*\(/m);
|
||||
assert.match("x = confirm('?')", /(^|[^.\w])(window\.)?(confirm|alert|prompt)\s*\(/m);
|
||||
});
|
||||
|
||||
test("les deux blocs du thème sombre de app.css sont identiques", () => {
|
||||
|
||||
@@ -0,0 +1,181 @@
|
||||
// Étapes des scénarios docs/scenarios/decouvrir-l-application.feature et
|
||||
// installer-l-application.feature (ADR 0008) : l'accueil et l'invitation à
|
||||
// installer passent par les modules de l'interface qui les décident
|
||||
// (home-model.ts, settings.ts, install.ts), la partie par le domaine et le
|
||||
// vrai moteur, le tutoriel par son texte source.
|
||||
//
|
||||
// Copyright (C) 2026 les auteurs d'Ustagammon.
|
||||
// Licence : GPLv3 ou ultérieure (voir LICENSE).
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { BeforeAll, Given, Then, When } from "@cucumber/cucumber";
|
||||
import type { Engine } from "../../src/domain/game/engine.js";
|
||||
import { Game } from "../../src/domain/game/game.js";
|
||||
import {
|
||||
dismissInstall,
|
||||
homeModel,
|
||||
installMenuShown,
|
||||
launchHash,
|
||||
WELCOME_LINKS,
|
||||
welcomed,
|
||||
} from "../../src/ui/home-model.js";
|
||||
import { HOME_TEXTS } from "../../src/ui/home-texts.js";
|
||||
import { installPlatform } from "../../src/ui/install.js";
|
||||
import { parseRoute } from "../../src/ui/router.js";
|
||||
import { parseSettings, type Settings } from "../../src/ui/settings.js";
|
||||
import { placeOf } from "../../src/ui/tutorial-nav.js";
|
||||
import { parseTutorial } from "../../src/ui/tutorial-text.js";
|
||||
import { loadNodeEngine } from "../support/node-engine.js";
|
||||
import { seededDice, step } from "../support/play.js";
|
||||
|
||||
const root = new URL("../../../../", import.meta.url);
|
||||
|
||||
let engine: Engine;
|
||||
let settings: Settings;
|
||||
let game: Game | null = null;
|
||||
let installed = false;
|
||||
let route = "";
|
||||
let installSteps: readonly string[] = [];
|
||||
|
||||
BeforeAll(async () => {
|
||||
engine = await loadNodeEngine();
|
||||
});
|
||||
|
||||
/** Ce que montre l'accueil, la partie étant celle du scénario. */
|
||||
function home() {
|
||||
const playing = game === null ? false : game.state.phase !== "over";
|
||||
return homeModel(settings, playing, installed);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------- Premier lancement
|
||||
|
||||
Given("vous ouvrez Ustagammon pour la toute première fois", () => {
|
||||
settings = parseSettings(null);
|
||||
game = null;
|
||||
installed = false;
|
||||
});
|
||||
|
||||
Then("l'accueil vous propose de découvrir les règles ou de jouer tout de suite", () => {
|
||||
assert.equal(launchHash(""), "#/accueil");
|
||||
assert.equal(parseRoute(launchHash("") ?? "").screen, "home");
|
||||
assert.ok(home().welcome);
|
||||
assert.equal(parseRoute(WELCOME_LINKS.play).screen, "game");
|
||||
});
|
||||
|
||||
When("vous choisissez de découvrir les règles", () => {
|
||||
settings = { ...settings, ...welcomed() };
|
||||
route = WELCOME_LINKS.discover;
|
||||
});
|
||||
|
||||
Then("le tutoriel s'ouvre à sa première étape", () => {
|
||||
const tutorial = parseTutorial(readFileSync(new URL("docs/tutoriel/regles.md", root), "utf8"));
|
||||
assert.deepEqual(placeOf(tutorial, parseRoute(route)), { step: 1, practice: false });
|
||||
});
|
||||
|
||||
Then("ce choix ne vous est plus proposé", () => {
|
||||
assert.ok(!home().welcome);
|
||||
});
|
||||
|
||||
Given("vous avez choisi de jouer tout de suite", () => {
|
||||
settings = { ...parseSettings(null), ...welcomed() };
|
||||
installed = false;
|
||||
});
|
||||
|
||||
Given("une partie est en cours", () => {
|
||||
game = Game.start(engine, { dice: seededDice(11), ply: 0 });
|
||||
settings = { ...settings, gamesStarted: settings.gamesStarted + 1 };
|
||||
});
|
||||
|
||||
When("vous rouvrez Ustagammon", () => {
|
||||
route = launchHash("") ?? "";
|
||||
});
|
||||
|
||||
Then("l'accueil vous propose de reprendre votre partie", () => {
|
||||
assert.equal(parseRoute(route).screen, "home");
|
||||
assert.ok(home().resume);
|
||||
});
|
||||
|
||||
When("la partie se termine", async () => {
|
||||
assert.ok(game !== null);
|
||||
for (let i = 0; game.state.phase !== "over"; i++) {
|
||||
assert.ok(i < 2000, "la partie ne finit pas");
|
||||
await step(game, engine);
|
||||
}
|
||||
});
|
||||
|
||||
Then("l'accueil vous propose une nouvelle partie", () => {
|
||||
assert.equal(parseRoute(route).screen, "home");
|
||||
assert.ok(!home().resume);
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------- Installation
|
||||
|
||||
Given("votre navigateur ne propose pas lui-même l'installation", () => {
|
||||
installSteps = [];
|
||||
});
|
||||
|
||||
When("vous demandez à installer l'application avec Firefox", () => {
|
||||
const firefox = "Mozilla/5.0 (Android 14; Mobile; rv:131.0) Gecko/131.0 Firefox/131.0";
|
||||
installSteps = HOME_TEXTS.installSteps[installPlatform(firefox)];
|
||||
});
|
||||
|
||||
When("vous demandez à installer l'application sur iPhone", () => {
|
||||
const iphone =
|
||||
"Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 " +
|
||||
"(KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1";
|
||||
installSteps = HOME_TEXTS.installSteps[installPlatform(iphone)];
|
||||
});
|
||||
|
||||
Then("la marche à suivre compte trois étapes, en commençant par le menu du navigateur", () => {
|
||||
assert.equal(installSteps.length, 3);
|
||||
assert.match(installSteps[0] ?? "", /menu du navigateur/);
|
||||
});
|
||||
|
||||
Then("la marche à suivre compte trois étapes, en commençant par le bouton de partage", () => {
|
||||
assert.equal(installSteps.length, 3);
|
||||
assert.match(installSteps[0] ?? "", /bouton de partage/);
|
||||
});
|
||||
|
||||
Then("l'accueil ne vous propose pas d'installer l'application", () => {
|
||||
assert.ok(!home().installCard);
|
||||
});
|
||||
|
||||
Then("l'accueil vous propose d'installer l'application", () => {
|
||||
assert.ok(home().installCard);
|
||||
});
|
||||
|
||||
When("vous terminez une partie", () => {
|
||||
settings = { ...settings, gamesFinished: settings.gamesFinished + 1 };
|
||||
});
|
||||
|
||||
When("vous terminez {int} parties de plus", (n: number) => {
|
||||
settings = { ...settings, gamesFinished: settings.gamesFinished + n };
|
||||
});
|
||||
|
||||
When("vous choisissez « Plus tard »", () => {
|
||||
settings = { ...settings, ...dismissInstall(settings) };
|
||||
});
|
||||
|
||||
Then("le menu vous le propose toujours", () => {
|
||||
assert.ok(installMenuShown(settings, installed));
|
||||
});
|
||||
|
||||
Given("vous avez terminé une partie", () => {
|
||||
settings = { ...parseSettings(null), welcomed: true, gamesFinished: 1 };
|
||||
installed = false;
|
||||
assert.ok(home().installCard);
|
||||
});
|
||||
|
||||
When("vous installez l'application", () => {
|
||||
// L'événement appinstalled du navigateur, retenu dans les réglages.
|
||||
installed = true;
|
||||
settings = { ...settings, installed: true };
|
||||
});
|
||||
|
||||
Then("le menu non plus", () => {
|
||||
assert.ok(!installMenuShown(settings, installed));
|
||||
// Même dans un onglet ouvert plus tard, hors de l'application installée.
|
||||
assert.ok(!installMenuShown(settings, false));
|
||||
assert.ok(!homeModel(settings, true, false).installCard);
|
||||
});
|
||||
@@ -0,0 +1,132 @@
|
||||
// Étapes du scénario docs/scenarios/apprendre-les-regles.feature (ADR 0008) :
|
||||
// le texte du tutoriel est lu dans sa source (docs/tutoriel/regles.md), et
|
||||
// chaque geste est jugé par le domaine branché sur le vrai moteur, comme
|
||||
// dans l'application.
|
||||
//
|
||||
// Copyright (C) 2026 les auteurs d'Ustagammon.
|
||||
// Licence : GPLv3 ou ultérieure (voir LICENSE).
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { readFileSync } from "node:fs";
|
||||
import { BeforeAll, Given, Then, When } from "@cucumber/cucumber";
|
||||
import type { Engine } from "../../src/domain/game/engine.js";
|
||||
import {
|
||||
MovePractice,
|
||||
type PracticeVerdict,
|
||||
shouldTake,
|
||||
tutorialBoard,
|
||||
} from "../../src/domain/learning/tutorial.js";
|
||||
import { progress, seenAfter, type TutorialPlace } from "../../src/ui/tutorial-nav.js";
|
||||
import { parseTutorial, type Tutorial, type TutorialScreen } from "../../src/ui/tutorial-text.js";
|
||||
import { loadNodeEngine } from "../support/node-engine.js";
|
||||
|
||||
const root = new URL("../../../../", import.meta.url);
|
||||
|
||||
let engine: Engine;
|
||||
let tutorial: Tutorial;
|
||||
let seen = 0;
|
||||
let place: TutorialPlace = { step: 1, practice: false };
|
||||
let screen: TutorialScreen;
|
||||
let practice: MovePractice | null = null;
|
||||
let verdict: PracticeVerdict = "continue";
|
||||
let answeredRight = false;
|
||||
|
||||
BeforeAll(async () => {
|
||||
engine = await loadNodeEngine();
|
||||
tutorial = parseTutorial(readFileSync(new URL("docs/tutoriel/regles.md", root), "utf8"));
|
||||
});
|
||||
|
||||
Given("vous commencez le tutoriel", () => {
|
||||
seen = 0;
|
||||
place = { step: 1, practice: false };
|
||||
seen = seenAfter(seen, place);
|
||||
});
|
||||
|
||||
Then("il compte huit étapes, dont quatre où c'est à vous de jouer", () => {
|
||||
assert.equal(tutorial.steps.length, 8);
|
||||
assert.equal(tutorial.steps.filter((s) => s.practice !== null).length, 4);
|
||||
});
|
||||
|
||||
Then("chaque position du tutoriel se lit sur le plateau", async () => {
|
||||
for (const step of tutorial.steps) {
|
||||
for (const current of [step.explain, step.practice]) {
|
||||
if (current !== null) {
|
||||
const board = await tutorialBoard(engine, current.position, current.onRoll);
|
||||
assert.equal(board.sides.player.points.length, 24);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
When("vous arrivez à l'étape {int}", (n: number) => {
|
||||
for (let step = 1; step <= n; step++) {
|
||||
place = { step, practice: false };
|
||||
seen = seenAfter(seen, place);
|
||||
}
|
||||
});
|
||||
|
||||
Then("la barre de progression vous ramène aux étapes 1 et 2, mais pas aux suivantes", () => {
|
||||
const links = progress(tutorial.steps.length, place, seen)
|
||||
.filter((segment) => segment.link)
|
||||
.map((segment) => segment.step);
|
||||
assert.deepEqual(links, [1, 2]);
|
||||
});
|
||||
|
||||
Given("vous êtes à l'écran « à vous » de l'étape {int}", async (n: number) => {
|
||||
const found = tutorial.steps[n - 1]?.practice;
|
||||
assert.ok(found != null, `l'étape ${n} n'a pas d'écran « à vous »`);
|
||||
screen = found;
|
||||
practice =
|
||||
screen.roll === null || screen.expected.length === 0
|
||||
? null
|
||||
: await MovePractice.start(engine, screen.position, screen.roll, screen.expected);
|
||||
verdict = "continue";
|
||||
answeredRight = false;
|
||||
});
|
||||
|
||||
When(
|
||||
"vous déplacez un pion de la flèche {int} à la flèche {int}",
|
||||
async (from: number, to: number) => {
|
||||
assert.ok(practice !== null);
|
||||
verdict = await practice.play({ from, to });
|
||||
if (verdict === "wrong") {
|
||||
practice.reset();
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
Then("le pion revient, et une phrase vous dit pourquoi", () => {
|
||||
assert.equal(verdict, "wrong");
|
||||
assert.deepEqual(practice?.pendingHalfMoves, []);
|
||||
assert.ok(screen.wrong.map((part) => part.text).join("").length > 20);
|
||||
});
|
||||
|
||||
When("vous réunissez deux pions sur la flèche 5", async () => {
|
||||
assert.ok(practice !== null);
|
||||
verdict = await practice.play({ from: 8, to: 5 });
|
||||
assert.equal(verdict, "continue");
|
||||
verdict = await practice.play({ from: 6, to: 5 });
|
||||
});
|
||||
|
||||
Then("le tutoriel salue votre coup", () => {
|
||||
assert.equal(verdict, "right");
|
||||
assert.ok(screen.right.length > 0);
|
||||
});
|
||||
|
||||
When("vous répondez « Je passe »", async () => {
|
||||
answeredRight = (await shouldTake(engine, screen.position)) === false;
|
||||
});
|
||||
|
||||
When("vous répondez « Je prends »", async () => {
|
||||
answeredRight = (await shouldTake(engine, screen.position)) === true;
|
||||
});
|
||||
|
||||
Then("le maître dit qu'il aurait pris", () => {
|
||||
assert.ok(!answeredRight);
|
||||
assert.match(screen.wrong.map((part) => part.text).join(""), /Le maître prendrait/);
|
||||
});
|
||||
|
||||
Then("le tutoriel salue votre réponse", () => {
|
||||
assert.ok(answeredRight);
|
||||
assert.match(screen.right.map((part) => part.text).join(""), /Le maître prend aussi/);
|
||||
});
|
||||
@@ -20,6 +20,7 @@ import { memoryStorage } from "../../src/storage/open-library.js";
|
||||
import { BANNER_MS } from "../../src/ui/app.js";
|
||||
import { createHaptics } from "../../src/ui/haptics.js";
|
||||
import { nextTheme, parseSettings, type Settings } from "../../src/ui/settings.js";
|
||||
import { updateBannerShown } from "../../src/ui/updates.js";
|
||||
import { loadNodeEngine } from "../support/node-engine.js";
|
||||
|
||||
setDefaultTimeout(30_000);
|
||||
@@ -163,3 +164,36 @@ Then("il passe à clair, puis à sombre, puis revient à automatique", () => {
|
||||
}
|
||||
assert.deepEqual(seen, ["auto", "light", "dark", "auto"]);
|
||||
});
|
||||
|
||||
// ------------------------------------------------------------ Mise à jour
|
||||
|
||||
// Le bandeau dépend de deux choses : une version attend (le service worker
|
||||
// l'a installée), et aucun coup n'est en cours de saisie. La partie est
|
||||
// celle du domaine, sur le vrai moteur.
|
||||
let updateAvailable = false;
|
||||
|
||||
Given("une nouvelle version d'Ustagammon est disponible", () => {
|
||||
updateAvailable = true;
|
||||
});
|
||||
|
||||
Given("vous avez déjà déplacé un pion de votre coup", async () => {
|
||||
// Jet d'ouverture 3-1 : vous commencez.
|
||||
game = Game.start(engine, { dice: fixedDice([3, 1, 6, 4, 5, 2]), ply: 0 });
|
||||
assert.equal(game.state.turn, "player");
|
||||
assert.ok(await game.playHalfMove({ from: 8, to: 5 }));
|
||||
});
|
||||
|
||||
Then("l'application ne vous propose pas encore de mettre à jour", () => {
|
||||
assert.ok(!updateBannerShown(updateAvailable, game.pendingHalfMoves.length > 0, false));
|
||||
});
|
||||
|
||||
When("vous avez joué votre coup", async () => {
|
||||
assert.ok(await game.playHalfMove({ from: 6, to: 5 }));
|
||||
await game.confirmMove();
|
||||
});
|
||||
|
||||
Then("l'application vous propose de mettre à jour", () => {
|
||||
assert.ok(updateBannerShown(updateAvailable, game.pendingHalfMoves.length > 0, false));
|
||||
// Jamais par-dessus le bandeau « Reprendre l'ancienne ».
|
||||
assert.ok(!updateBannerShown(updateAvailable, false, true));
|
||||
});
|
||||
|
||||
+46
-13
@@ -36,10 +36,14 @@ test("le texte du tutoriel a huit étapes, une fin, et ses écrans « à vous »
|
||||
const practice = step.practice;
|
||||
if (practice !== null) {
|
||||
assert.ok(practice.paragraphs.length > 0, `étape ${step.number} : consigne absente`);
|
||||
assert.ok(practice.right.length > 0 && practice.wrong.length > 0,
|
||||
`étape ${step.number} : phrases juste et refus absentes`);
|
||||
assert.ok(practice.expected.length > 0 || practice.answer !== null,
|
||||
`étape ${step.number} : ni coup attendu, ni réponse au double`);
|
||||
assert.ok(
|
||||
practice.right.length > 0 && practice.wrong.length > 0,
|
||||
`étape ${step.number} : phrases juste et refus absentes`,
|
||||
);
|
||||
assert.ok(
|
||||
practice.expected.length > 0 || practice.answer !== null,
|
||||
`étape ${step.number} : ni coup attendu, ni réponse au double`,
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -53,7 +57,10 @@ test("chaque mot du glossaire cité par le tutoriel a sa fiche", () => {
|
||||
const terms = inlines.flatMap((i) => (i.term === undefined ? [] : [i.term]));
|
||||
assert.ok(terms.length >= 10, `seulement ${terms.length} liens vers le glossaire`);
|
||||
for (const term of terms) {
|
||||
assert.ok(existsSync(new URL(`docs/glossaire/${term}.md`, root)), `fiche ${term}.md absente`);
|
||||
assert.ok(
|
||||
existsSync(new URL(`docs/glossaire/${term}.md`, root)),
|
||||
`fiche ${term}.md absente`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -68,7 +75,9 @@ test("les liens et le gras du texte sont lus", () => {
|
||||
});
|
||||
|
||||
test("un texte mal formé est refusé", () => {
|
||||
assert.throws(() => parseTutorial("## 2. Sans la première\n\n- position: x\n\nTexte.\n\n## Fin\n"));
|
||||
assert.throws(() =>
|
||||
parseTutorial("## 2. Sans la première\n\n- position: x\n\nTexte.\n\n## Fin\n"),
|
||||
);
|
||||
assert.throws(() => parseTutorial("## 1. Sans position\n\nTexte.\n\n## Fin\n"));
|
||||
assert.throws(() => parseTutorial("## 1. Jet faux\n\n- position: x\n- jet: 7-1\n\n## Fin\n"));
|
||||
assert.throws(() => parseTutorial("## 1. Sans fin\n\n- position: x\n\nTexte.\n"));
|
||||
@@ -104,8 +113,12 @@ test("chaque coup illustré est légal, et la partie de l'étape 7 finit par un
|
||||
continue;
|
||||
}
|
||||
assert.ok(screen.roll !== null, `${name} : coup sans jet`);
|
||||
const { steps, after } = await illustratedMove(engine, screen.position, screen.roll,
|
||||
screen.move);
|
||||
const { steps, after } = await illustratedMove(
|
||||
engine,
|
||||
screen.position,
|
||||
screen.roll,
|
||||
screen.move,
|
||||
);
|
||||
assert.equal(steps.boards.length, steps.halfMoves.length + 1, name);
|
||||
if (name === "étape 7") {
|
||||
assert.deepEqual(after.result, { winner: "player", kind: "gammon" });
|
||||
@@ -127,8 +140,12 @@ test("chaque écran « à vous » accepte ses coups attendus et refuse les autre
|
||||
assert.ok(screen.roll !== null, `${name} : pas de jet`);
|
||||
const legal = await engine.legalMoves(screen.position, screen.roll);
|
||||
for (const move of legal) {
|
||||
const practice = await MovePractice.start(engine, screen.position, screen.roll,
|
||||
screen.expected);
|
||||
const practice = await MovePractice.start(
|
||||
engine,
|
||||
screen.position,
|
||||
screen.roll,
|
||||
screen.expected,
|
||||
);
|
||||
let verdict = "continue";
|
||||
for (const halfMove of move.halfMoves) {
|
||||
verdict = await practice.play(halfMove);
|
||||
@@ -140,7 +157,10 @@ test("chaque écran « à vous » accepte ses coups attendus et refuse les autre
|
||||
assert.equal(verdict, right ? "right" : "wrong", `${name} : ${move.notation}`);
|
||||
}
|
||||
// Un coup attendu au moins, et un coup refusé au moins.
|
||||
assert.ok(legal.some((m) => !screen.expected.includes(m.notation)), `${name} : rien à refuser`);
|
||||
assert.ok(
|
||||
legal.some((m) => !screen.expected.includes(m.notation)),
|
||||
`${name} : rien à refuser`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -171,9 +191,22 @@ test("des demi-coups peuvent encore mener à un coup attendu, ou plus", () => {
|
||||
halfMoves: halfMoves.map(([from, to]) => ({ from, to })),
|
||||
position: notation,
|
||||
});
|
||||
const expected = [move("8/5 6/5", [[8, 5], [6, 5]])];
|
||||
const expected = [
|
||||
move("8/5 6/5", [
|
||||
[8, 5],
|
||||
[6, 5],
|
||||
]),
|
||||
];
|
||||
assert.ok(canStillLeadTo([], expected));
|
||||
assert.ok(canStillLeadTo([{ from: 6, to: 5 }], expected));
|
||||
assert.ok(!canStillLeadTo([{ from: 8, to: 7 }], expected));
|
||||
assert.ok(!canStillLeadTo([{ from: 8, to: 5 }, { from: 8, to: 5 }], expected));
|
||||
assert.ok(
|
||||
!canStillLeadTo(
|
||||
[
|
||||
{ from: 8, to: 5 },
|
||||
{ from: 8, to: 5 },
|
||||
],
|
||||
expected,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
+75
-8
@@ -19,7 +19,15 @@ import {
|
||||
pointColor,
|
||||
pointSlot,
|
||||
} from "../src/ui/board-model.js";
|
||||
import { parseFeature, parseGlossaryEntry, parseGlossaryIndex } from "../src/ui/help-text.js";
|
||||
import { FEATURES } from "../src/ui/help.js";
|
||||
import { HELP_QUESTIONS, helpHash } from "../src/ui/help-context.js";
|
||||
import {
|
||||
matchesSearch,
|
||||
parseFeature,
|
||||
parseGlossaryEntry,
|
||||
parseGlossaryIndex,
|
||||
} from "../src/ui/help-text.js";
|
||||
import { slug } from "../src/ui/router.js";
|
||||
import { TEXTS } from "../src/ui/texts.js";
|
||||
|
||||
// Compilé dans build/web/tests/ : la racine du dépôt est trois dossiers plus haut.
|
||||
@@ -143,21 +151,77 @@ test("l'aide lit le scénario tel qu'il est écrit dans docs/scenarios/", () =>
|
||||
const feature = parseFeature(read("docs/scenarios/jouer-une-partie.feature"));
|
||||
assert.equal(feature.title, "Jouer une partie contre l'ordinateur");
|
||||
assert.match(feature.description[0] ?? "", /^Vous jouez une partie complète/);
|
||||
assert.equal(feature.scenarios[0]?.title, "Commencer une partie");
|
||||
assert.equal(feature.scenarios[0]?.title, "Comment commence une partie ?");
|
||||
assert.equal(feature.scenarios[0]?.position, "4HPwATDgc/ABMA");
|
||||
assert.deepEqual(feature.scenarios[0]?.steps, [
|
||||
"Quand vous commencez une nouvelle partie",
|
||||
"Alors les pions sont en position de départ",
|
||||
"Et le premier jet de dés désigne qui commence",
|
||||
]);
|
||||
const refused = feature.scenarios.find((s) => s.title === "Un coup interdit est refusé");
|
||||
assert.match(refused?.description[0] ?? "", /^La case 12 est tenue/);
|
||||
const refused = feature.scenarios.find(
|
||||
(s) => s.title === "Pourquoi je ne peux pas poser mon pion sur cette flèche ?",
|
||||
);
|
||||
assert.match(
|
||||
refused?.description[0] ?? "",
|
||||
/^Une flèche où l'ordinateur a au moins deux pions/,
|
||||
);
|
||||
assert.equal(refused?.steps[0], "Étant donné que c'est à vous de jouer avec le jet 3-1");
|
||||
assert.equal(feature.scenarios[2]?.position, null);
|
||||
// Chaque scénario a des étapes : aucune n'a été prise pour du texte libre.
|
||||
for (const scenario of feature.scenarios) {
|
||||
assert.ok(scenario.steps.length >= 2, scenario.title);
|
||||
}
|
||||
});
|
||||
|
||||
test("aide : chaque scénario affiché est une question avec sa réponse", () => {
|
||||
const listed = read("docs/scenarios/README.md");
|
||||
const ids = new Set<string>();
|
||||
for (const url of FEATURES) {
|
||||
assert.ok(
|
||||
listed.includes(`](${url.replace("docs/scenarios/", "")})`),
|
||||
`${url} hors de l'index`,
|
||||
);
|
||||
const feature = parseFeature(read(url));
|
||||
assert.ok(feature.description.length > 0, `${url} : pas d'introduction`);
|
||||
for (const scenario of feature.scenarios) {
|
||||
// La réponse se lit seule : pas de vocabulaire technique.
|
||||
assert.ok(scenario.description.length > 0, `${scenario.title} : pas de réponse`);
|
||||
for (const word of ["scénario", "événement", "moteur", "Étant donné"]) {
|
||||
assert.ok(
|
||||
!scenario.description.join(" ").includes(word),
|
||||
`${scenario.title} : « ${word} » dans la réponse`,
|
||||
);
|
||||
}
|
||||
const id = slug(scenario.title);
|
||||
assert.ok(id !== "" && !ids.has(id), `${scenario.title} : identifiant ${id} en double`);
|
||||
ids.add(id);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("aide contextuelle : chaque question ouverte depuis la partie existe dans les scénarios", () => {
|
||||
const titles = FEATURES.flatMap((url) => parseFeature(read(url)).scenarios.map((s) => s.title));
|
||||
for (const title of Object.values(HELP_QUESTIONS)) {
|
||||
assert.ok(titles.includes(title), `« ${title} » n'est plus le titre d'un scénario`);
|
||||
}
|
||||
assert.equal(helpHash("stuck"), "#/aide/je-ne-peux-rien-jouer-avec-mes-des");
|
||||
assert.equal(helpHash(null), "#/aide");
|
||||
});
|
||||
|
||||
test("glossaire : nom anglais, renvois, recherche sans accents", () => {
|
||||
const entry = parseGlossaryEntry(read("docs/glossaire/camp.md"));
|
||||
assert.ok(entry !== null);
|
||||
assert.equal(entry.english, "Home board");
|
||||
assert.deepEqual(
|
||||
entry.seeAlso.map((s) => s.name),
|
||||
["sortie", "barre", "point"],
|
||||
);
|
||||
assert.ok(matchesSearch(entry, "camp"));
|
||||
assert.ok(matchesSearch(entry, "HOME"));
|
||||
assert.ok(matchesSearch(entry, "fleches sortir"));
|
||||
assert.ok(!matchesSearch(entry, "videau"));
|
||||
});
|
||||
|
||||
test("l'aide lit chaque fiche de l'index du glossaire", () => {
|
||||
const files = parseGlossaryIndex(read("docs/glossaire/README.md"));
|
||||
assert.ok(files.includes("videau.md"));
|
||||
@@ -167,10 +231,13 @@ test("l'aide lit chaque fiche de l'index du glossaire", () => {
|
||||
assert.ok(entry !== null, file);
|
||||
assert.ok(entry.brief.length > 10, file);
|
||||
}
|
||||
assert.deepEqual(parseGlossaryEntry(read("docs/glossaire/videau.md")), {
|
||||
term: "Videau",
|
||||
brief: "le dé à doubler, marqué 2, 4, 8, 16, 32 et 64 : il indique la valeur actuelle de la partie.",
|
||||
});
|
||||
const videau = parseGlossaryEntry(read("docs/glossaire/videau.md"));
|
||||
assert.equal(videau?.term, "Videau");
|
||||
assert.equal(videau?.english, "Cube");
|
||||
assert.equal(
|
||||
videau?.brief,
|
||||
"le dé à doubler, marqué 2, 4, 8, 16, 32 et 64 : il indique la valeur actuelle de la partie.",
|
||||
);
|
||||
assert.equal(parseGlossaryEntry("pas une fiche"), null);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user