Proposer l'installation de l'app au bon moment (lot 3d)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Pierre MARTIN
2026-11-18 15:17:39 +01:00
co-authored by Claude Opus 5.5
parent 888aec1003
commit 84b4027796
7 changed files with 461 additions and 4 deletions
+36 -1
View File
@@ -22,7 +22,7 @@ const START = new Date("2026-11-18T09:00:00");
const TYPES = {
".html": "text/html; charset=utf-8", ".js": "text/javascript; charset=utf-8", ".mjs": "text/javascript; charset=utf-8", ".css": "text/css; charset=utf-8",
".json": "application/json", ".webmanifest": "application/manifest+json", ".svg": "image/svg+xml",
".json": "application/json", ".webmanifest": "application/manifest+json", ".svg": "image/svg+xml", ".png": "image/png",
".woff2": "font/woff2", ".md": "text/markdown; charset=utf-8", ".txt": "text/plain; charset=utf-8",
};
@@ -107,6 +107,28 @@ function check(scheme, cond, msg) {
ok(await page.getByText("Pas de planning").isVisible(), "accueil sans planning : rotation annoncée");
ok(await page.locator(".hud").isVisible(), "HUD de niveau affiché");
// ---- installation : carte après l'adoption, « Plus tard », icônes ----------------
const install = page.locator(".install");
ok(await install.isVisible() && await install.getByText("Ouvre le menu").isVisible(), "carte d'installation après l'adoption (marche à suivre)");
await shot("02b-installation", true);
await install.getByRole("button", { name: "Plus tard" }).click();
ok(await install.count() === 0, "« Plus tard » cache la carte");
await go("#/");
ok(await page.locator(".install").count() === 0, "carte toujours cachée après rechargement");
ok(await page.evaluate(() => localStorage.getItem("ia-fit.install")) === '{"dismissals":1,"dismissedAt":0}', "refus gardé sur l'appareil");
const manifest = await (await page.request.get(base + "manifest.webmanifest")).json();
const pngs = manifest.icons.filter((i) => i.type === "image/png");
ok(pngs.some((i) => i.sizes === "192x192") && pngs.some((i) => i.sizes === "512x512" && i.purpose === "any")
&& pngs.some((i) => i.sizes === "512x512" && i.purpose === "maskable"), "manifeste : PNG 192, 512 et maskable 512");
const apple = await page.locator('link[rel="apple-touch-icon"]').getAttribute("href");
for (const { src, sizes } of [...pngs, { src: apple, sizes: "180x180" }]) {
const res = await page.request.get(base + src);
const body = await res.body();
// Largeur et hauteur d'un PNG : octets 16 à 23 (en-tête IHDR).
const size = `${body.readUInt32BE(16)}x${body.readUInt32BE(20)}`;
ok(res.status() === 200 && res.headers()["content-type"] === "image/png" && size === sizes, `icône ${src} servie, ${size}`);
}
// ---- semaine : jours, jour imposé, semaine suivante, .ics ------------------------
await go("#/semaine");
for (const d of ["lundi", "mercredi", "vendredi", "samedi"]) await page.getByRole("button", { name: d, exact: true }).click();
@@ -200,6 +222,7 @@ function check(scheme, cond, msg) {
ok(await page.getByText("Bien joué.").isVisible(), "écran de fin de séance");
ok(await page.locator(".reward__gain").innerText().then((t) => /\+\d+ XP/.test(t.replace(/\s/g, " "))), "XP gagnée affichée");
ok(await page.locator(".reward__big .big-number").innerText().then((t) => t.replace(/\s/g, "") === "1860"), "1 860 kg soulevés (31 répétitions × 60 kg)");
ok(await page.locator(".install").count() === 0, "fin de la 1re séance : pas de carte, refusée il y a moins de 3 séances");
await shot("07-fin-de-seance", true);
await page.getByRole("link", { name: "Continuer" }).click();
await settle();
@@ -275,6 +298,18 @@ function check(scheme, cond, msg) {
await button("Maintien").click();
ok(await button("Maintien").getAttribute("aria-pressed") === "true", "mode maintien");
await shot("11-profil", true);
// Entrée permanente : invite du navigateur simulée, puis installation.
await button("Installer l'app sur l'écran d'accueil").click();
ok(await page.locator(".install-entry .install").getByText("Choisis « Installer »").isVisible(), "profil : marche à suivre sans invite du navigateur");
await page.evaluate(() => {
const e = new Event("beforeinstallprompt", { cancelable: true });
Object.assign(e, { prompt: async () => { window.__prompted = true; }, userChoice: Promise.resolve({ outcome: "accepted" }) });
window.dispatchEvent(e);
});
await page.locator(".install-entry").getByRole("button", { name: "Installer", exact: true }).click();
ok(await page.evaluate(() => window.__prompted === true), "profil : « Installer » ouvre l'invite du navigateur");
await page.evaluate(() => window.dispatchEvent(new Event("appinstalled")));
ok(await page.locator(".install-entry").count() === 0, "plus d'entrée une fois l'app installée");
await button("Progression", { exact: true }).click();
// ---- analyses, progression -------------------------------------------------------