Repository Public
1// Parcours de bout en bout (Playwright, Chromium).2// usage : BASE=http://127.0.0.1:5183 CHROME_EXE=/chemin/vers/chrome node e2e/smoke.mjs3// Vérifie les fonctions principales et la transition « Ouvrir la porte »,4// y compris les interruptions, l'accès direct et le mouvement réduit.56import { chromium } from "playwright-core";78const BASE = process.env.BASE ?? "http://127.0.0.1:5183";9const results = [];10const ok = (name, pass, detail = "") => {11 results.push({ name, pass, detail });12 console.log(`${pass ? "✓" : "✗"} ${name}${detail ? ` — ${detail}` : ""}`);13};1415const browser = await chromium.launch({16 executablePath: process.env.CHROME_EXE || undefined,17 headless: true,18 args: ["--use-angle=metal", "--enable-gpu", "--ignore-gpu-blocklist"],19});2021async function context(opts = {}) {22 const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 }, locale: "fr-CA", ...opts });23 const page = await ctx.newPage();24 const errors = [];25 page.on("pageerror", (e) => errors.push(String(e).slice(0, 160)));26 return { ctx, page, errors };27}2829const overlay = (page) => page.evaluate(() => !!document.querySelector(".lkd-root"));30const cards = (page) => page.locator("a:has([data-door-source])");31const card = (page, n = 0) => cards(page).nth(n);3233try {34 // 1 — accueil -------------------------------------------------------------------35 {36 const { ctx, page, errors } = await context();37 await page.goto(BASE + "/", { waitUntil: "domcontentloaded" });38 const h1 = await page.locator("h1").first().innerText();39 ok("Accueil : titre", /porte/i.test(h1), h1.replace(/\s+/g, " "));40 await card(page, 4).waitFor({ timeout: 20000 }).catch(() => undefined);41 ok("Accueil : de vrais logements sont affichés", (await cards(page).count()) >= 4, `${await cards(page).count()} cartes`);42 // 2 — recherche depuis l'accueil43 await page.getByLabel("Ville ou quartier").fill("Gatineau");44 await page.getByRole("button", { name: "Explorer" }).click();45 await page.waitForURL(/\/recherche\?.*city=Gatineau/, { timeout: 15000 });46 await page.waitForSelector("a:has([data-door-source])", { timeout: 20000 });47 ok("Recherche : la ville saisie devient un filtre", true, new URL(page.url()).search);48 await page.waitForTimeout(2500);49 const before = await cards(page).count();50 ok("Recherche : résultats", before > 0, `${before} cartes`);51 // filtre : grandeur 4½52 await page.getByRole("button", { name: "4½", exact: true }).first().click();53 await page.waitForURL(/unit_type=/, { timeout: 5000 });54 ok("Recherche : le filtre de grandeur est dans l'adresse", true);55 await page.waitForTimeout(1800);5657 // 3 — ouverture d'un logement : la porte58 const searchUrl = page.url();59 const first = card(page, 0);60 await first.scrollIntoViewIfNeeded();61 const t0 = Date.now();62 await first.click({ noWaitAfter: true });63 await page.waitForTimeout(90);64 ok("Porte : la scène de transition apparaît au clic", await overlay(page));65 await page.waitForURL(/\/logement\//, { timeout: 5000 });66 await page.waitForFunction(() => !document.querySelector(".lkd-root"), null, { timeout: 5000 });67 const dt = Date.now() - t0;68 ok("Porte : la scène disparaît d'elle-même", !(await overlay(page)), `${dt} ms après le clic`);69 const img = await page.evaluate(() => {70 const i = document.querySelector("[data-door-target] img");71 return i ? i.complete && i.naturalWidth > 0 : null;72 });73 ok("Fiche : la photo principale est affichée à l'arrivée", img === true, String(img));74 const focused = await page.evaluate(() => document.activeElement?.tagName);75 ok("Fiche : le focus est sur le titre", focused === "H1", String(focused));76 ok("Fiche : prix et action principale", (await page.getByRole("link", { name: /annonce/i }).count()) > 0);7778 // 4 — retour : filtres préservés79 await page.goBack();80 await page.waitForURL(/\/recherche/, { timeout: 5000 });81 ok("Retour : filtres préservés", page.url() === searchUrl, new URL(page.url()).search);8283 // 5 — clics rapides : aucune scène bloquée84 await page.waitForSelector("a:has([data-door-source])", { timeout: 15000 });85 await page.waitForTimeout(800);86 await card(page, 0).click({ noWaitAfter: true });87 await page.waitForTimeout(60);88 await page.mouse.click(700, 500); // clic pendant la transition : interruption89 await page.waitForTimeout(1200);90 ok("Interruption : on arrive sur une fiche, sans scène résiduelle", /\/logement\//.test(page.url()) && !(await overlay(page)), page.url().split("/").pop());9192 // 6 — favoris93 await page.goto(BASE + "/recherche?city=Gatineau", { waitUntil: "domcontentloaded" });94 await page.waitForSelector("a:has([data-door-source])", { timeout: 20000 });95 await page.getByRole("button", { name: "Ajouter aux favoris" }).first().click();96 const favs = await page.evaluate(() => Object.keys(JSON.parse(localStorage.getItem("louka:favoris") || "{}")).length);97 ok("Favoris : enregistré sur l'appareil", favs === 1 && /\/recherche/.test(page.url()), `${favs} favori`);98 await page.goto(BASE + "/favoris", { waitUntil: "domcontentloaded" });99 await page.waitForTimeout(1500);100 ok("Favoris : la page le liste", (await page.locator("a[href^='/logement/']").count()) >= 1);101102 // 7 — thème103 await page.goto(BASE + "/", { waitUntil: "domcontentloaded" });104 const t1 = await page.evaluate(() => document.documentElement.dataset.theme);105 await page.getByRole("button", { name: /thème/i }).first().click();106 const t2 = await page.evaluate(() => document.documentElement.dataset.theme);107 ok("Thème : bascule clair / sombre", t1 !== t2, `${t1} → ${t2}`);108109 await page.goto(BASE + "/villes", { waitUntil: "domcontentloaded" });110 await page.waitForTimeout(600);111 ok("En-tête : un seul indicateur actif", (await page.locator("header nav a span.bg-accent").count()) === 1);112 ok("Mouvement : attribut data-motion actif", (await page.evaluate(() => document.documentElement.dataset.motion)) === "on");113114 // 8 — pages principales : pas d'erreur de rendu115 for (const p of ["/gestionnaires", "/villes", "/stats", "/juste-valeur", "/scores", "/comparer", "/sources", "/demenageurs", "/a-propos", "/contact", "/confidentialite", "/conditions", "/lab", "/page-inexistante"]) {116 await page.goto(BASE + p, { waitUntil: "domcontentloaded" });117 await page.waitForTimeout(700);118 const has = await page.locator("main :is(h1, h2, h3)").count();119 ok(`Page ${p}`, has > 0);120 }121 ok("Aucune erreur JavaScript pendant le parcours", errors.length === 0, errors.slice(0, 3).join(" | "));122 await ctx.close();123 }124125 // 9 — accès direct : aucune animation imposée -------------------------------------126 {127 const { ctx, page } = await context();128 await page.goto(BASE + "/recherche?city=Montr%C3%A9al", { waitUntil: "domcontentloaded" });129 await page.waitForSelector("a:has([data-door-source])", { timeout: 20000 });130 const href = await card(page, 0).getAttribute("href");131 await page.goto(BASE + href, { waitUntil: "domcontentloaded" });132 let seen = false;133 for (let i = 0; i < 6; i++) {134 seen ||= await overlay(page);135 await page.waitForTimeout(60);136 }137 ok("Lien direct : aucune porte, le contenu s'affiche immédiatement", !seen);138 await ctx.close();139 }140141 // 10 — mouvement réduit --------------------------------------------------------------142 {143 const { ctx, page } = await context({ reducedMotion: "reduce" });144 await page.goto(BASE + "/recherche?city=Montr%C3%A9al", { waitUntil: "domcontentloaded" });145 await page.waitForSelector("a:has([data-door-source])", { timeout: 20000 });146 await page.waitForTimeout(1500);147 await card(page, 0).click({ noWaitAfter: true });148 const panel = await page.evaluate(() => {149 const p = document.querySelector(".lkd-root .lkd-panel");150 return p ? "présent" : "aucun";151 });152 await page.waitForURL(/\/logement\//, { timeout: 4000 });153 ok("Mouvement réduit : entrées et tracés neutralisés", (await page.evaluate(() => document.documentElement.dataset.motion)) === "off");154 ok("Mouvement réduit : pas de pivotement, navigation directe", panel === "aucun", `panneau ${panel}`);155 await ctx.close();156 }157158 // 11 — mobile : aucun débordement horizontal ----------------------------------------159 for (const w of [320, 375, 390, 430, 768]) {160 const { ctx, page } = await context({ viewport: { width: w, height: 800 }, isMobile: w < 700, hasTouch: w < 700 });161 const bad = [];162 for (const p of ["/", "/recherche?city=Gatineau", "/gestionnaires", "/stats", "/favoris"]) {163 await page.goto(BASE + p, { waitUntil: "domcontentloaded" });164 await page.waitForTimeout(1600);165 const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);166 if (over > 1) bad.push(`${p} +${over}px`);167 }168 ok(`Largeur ${w} px : aucun débordement horizontal`, bad.length === 0, bad.join(", "));169 await ctx.close();170 }171} catch (e) {172 ok("Parcours interrompu par une erreur", false, String(e).slice(0, 300));173} finally {174 await browser.close();175}176177const failed = results.filter((r) => !r.pass);178console.log(`\n${results.length - failed.length} réussis, ${failed.length} en échec`);179process.exit(failed.length ? 1 : 0);180