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:
co-authored by
Claude Opus 5.5
parent
888aec1003
commit
84b4027796
@@ -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 -------------------------------------------------------
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
// Installation de l'app : plateforme, moment de la carte, invite du navigateur.
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { createInstaller, dismissInstall, installPlatform, shouldOfferInstall } from "../../app/ui/install.js";
|
||||
|
||||
const IPHONE = "Mozilla/5.0 (iPhone; CPU iPhone OS 17_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Mobile/15E148 Safari/604.1";
|
||||
const IPAD = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.5 Safari/605.1.15";
|
||||
const ANDROID_FIREFOX = "Mozilla/5.0 (Android 14; Mobile; rv:132.0) Gecko/132.0 Firefox/132.0";
|
||||
const ANDROID_CHROME = "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Mobile Safari/537.36";
|
||||
|
||||
test("plateforme : iPhone et iPad à part, les autres par le menu", () => {
|
||||
assert.equal(installPlatform(IPHONE), "ios");
|
||||
assert.equal(installPlatform(IPAD, 5), "ios", "l'iPad se présente comme un Mac tactile");
|
||||
assert.equal(installPlatform(IPAD, 0), "other", "un vrai Mac n'est pas tactile");
|
||||
assert.equal(installPlatform(ANDROID_FIREFOX), "other");
|
||||
assert.equal(installPlatform(ANDROID_CHROME), "other");
|
||||
assert.equal(installPlatform(""), "other");
|
||||
});
|
||||
|
||||
const fresh = { dismissals: 0, dismissedAt: 0 };
|
||||
/** @param {Partial<Parameters<typeof shouldOfferInstall>[0]>} o */
|
||||
const offer = (o) => shouldOfferInstall({ place: "home", installed: false, hasProgram: true, sessions: 0, pref: fresh, ...o });
|
||||
|
||||
test("jamais une fois installée, ni pendant l'onboarding", () => {
|
||||
assert.equal(offer({ installed: true }), false);
|
||||
assert.equal(offer({ place: "finish", sessions: 1, installed: true }), false);
|
||||
assert.equal(offer({ hasProgram: false }), false);
|
||||
});
|
||||
|
||||
test("accueil : après l'adoption, jusqu'à la première séance", () => {
|
||||
assert.equal(offer({ sessions: 0 }), true);
|
||||
assert.equal(offer({ sessions: 1 }), false);
|
||||
assert.equal(offer({ sessions: 5 }), false);
|
||||
});
|
||||
|
||||
test("fin de séance : après la 1re, puis la 3e, et plus ensuite", () => {
|
||||
const at = (/** @type {number} */ sessions) => offer({ place: "finish", sessions });
|
||||
assert.deepEqual([1, 2, 3, 4, 5, 6].map(at), [true, false, true, false, false, false]);
|
||||
});
|
||||
|
||||
test("« Plus tard » cache la carte pour 3 séances, deux refus l'arrêtent", () => {
|
||||
const once = dismissInstall(fresh, 0);
|
||||
assert.deepEqual(once, { dismissals: 1, dismissedAt: 0 });
|
||||
assert.equal(offer({ pref: once }), false, "plus sur l'accueil");
|
||||
assert.equal(offer({ place: "finish", sessions: 1, pref: once }), false, "pas à la 1re séance");
|
||||
assert.equal(offer({ place: "finish", sessions: 2, pref: once }), false);
|
||||
assert.equal(offer({ place: "finish", sessions: 3, pref: once }), true, "de retour 3 séances plus tard");
|
||||
assert.equal(offer({ place: "home", sessions: 3, pref: once }), false, "à la fin d'une séance seulement");
|
||||
|
||||
const later = dismissInstall(fresh, 1);
|
||||
assert.equal(offer({ place: "finish", sessions: 3, pref: later }), false, "refusée à la 1re : pas à la 3e");
|
||||
assert.equal(offer({ place: "finish", sessions: 4, pref: later }), true);
|
||||
|
||||
const twice = dismissInstall(once, 3);
|
||||
assert.deepEqual(twice, { dismissals: 2, dismissedAt: 3 });
|
||||
for (const sessions of [3, 6, 10, 50]) assert.equal(offer({ place: "finish", sessions, pref: twice }), false);
|
||||
});
|
||||
|
||||
/** Fausse fenêtre : événements à la main, display-mode réglable. */
|
||||
function fakeWindow({ standalone = false, iosStandalone = false } = {}) {
|
||||
/** @type {Record<string, ((e: any) => void)[]>} */
|
||||
const handlers = {};
|
||||
return {
|
||||
addEventListener: (/** @type {string} */ type, /** @type {(e: any) => void} */ fn) => { (handlers[type] ??= []).push(fn); },
|
||||
matchMedia: (/** @type {string} */ q) => ({ matches: standalone && q === "(display-mode: standalone)" }),
|
||||
navigator: { standalone: iosStandalone },
|
||||
/** @param {string} type @param {any} [e] */
|
||||
fire: (type, e = {}) => { for (const fn of handlers[type] ?? []) fn(e); },
|
||||
};
|
||||
}
|
||||
|
||||
/** @param {"accepted"|"dismissed"} outcome */
|
||||
function promptEvent(outcome) {
|
||||
const e = { prevented: false, prompted: 0, preventDefault() { e.prevented = true; }, async prompt() { e.prompted++; }, userChoice: Promise.resolve({ outcome }) };
|
||||
return e;
|
||||
}
|
||||
|
||||
test("installateur : garde l'invite, l'ouvre une fois, note l'installation", async () => {
|
||||
const win = fakeWindow();
|
||||
const installer = createInstaller(win);
|
||||
let changes = 0;
|
||||
installer.subscribe(() => changes++);
|
||||
assert.equal(installer.installed, false);
|
||||
assert.equal(installer.canPrompt, false);
|
||||
assert.equal(await installer.offer(), "unavailable");
|
||||
|
||||
const e = promptEvent("accepted");
|
||||
win.fire("beforeinstallprompt", e);
|
||||
assert.equal(e.prevented, true, "le navigateur ne l'affiche pas de lui-même");
|
||||
assert.equal(installer.canPrompt, true);
|
||||
assert.equal(await installer.offer(), "accepted");
|
||||
assert.equal(e.prompted, 1);
|
||||
assert.equal(installer.canPrompt, false, "une invite ne sert qu'une fois");
|
||||
|
||||
win.fire("appinstalled");
|
||||
assert.equal(installer.installed, true);
|
||||
assert.ok(changes >= 3);
|
||||
});
|
||||
|
||||
test("installateur : déjà installée (display-mode ou iOS)", () => {
|
||||
assert.equal(createInstaller(fakeWindow({ standalone: true })).installed, true);
|
||||
assert.equal(createInstaller(fakeWindow({ iosStandalone: true })).installed, true);
|
||||
});
|
||||
|
||||
test("installateur : se désabonner", () => {
|
||||
const win = fakeWindow();
|
||||
const installer = createInstaller(win);
|
||||
let changes = 0;
|
||||
const stop = installer.subscribe(() => changes++);
|
||||
stop();
|
||||
win.fire("appinstalled");
|
||||
assert.equal(changes, 0);
|
||||
});
|
||||
Reference in New Issue
Block a user