SPB Git

Repository Public

smoke.mjs 9.2 KB 172 lines javascript

1// Parcours de bout en bout d'Immo-Ka (Playwright, Chromium).2// usage : BASE=http://127.0.0.1:5184 CHROME_EXE=/chemin/vers/chrome node e2e/smoke.mjs3// Recherche, filtres, ouverture par la porte de la maison, retour, favoris,4// thème, pages principales, accès direct, mouvement réduit, largeurs mobiles.56import { chromium } from "playwright-core";78const BASE = process.env.BASE ?? "http://127.0.0.1:5184";9const results = [];10const ok = (name, pass, detail = "") => {11  results.push({ name, pass });12  console.log(`${pass ? "✓" : "✗"} ${name}${detail ? ` — ${detail}` : ""}`);13};14const browser = await chromium.launch({ executablePath: process.env.CHROME_EXE || undefined, headless: true, args: ["--use-angle=metal", "--enable-gpu", "--ignore-gpu-blocklist"] });1516async function context(opts = {}) {17  const ctx = await browser.newContext({ viewport: { width: 1440, height: 900 }, locale: "fr-CA", ...opts });18  const page = await ctx.newPage();19  const errors = [];20  page.on("pageerror", (e) => errors.push(String(e).slice(0, 160)));21  return { ctx, page, errors };22}23const overlay = (page) => page.evaluate(() => !!document.querySelector(".ikd-root"));24const CARD = "a:has([data-door-source])";25const cards = (page) => page.locator(CARD);26const card = (page, n = 0) => cards(page).nth(n);2728try {29  {30    const { ctx, page, errors } = await context();31    await page.goto(BASE + "/", { waitUntil: "domcontentloaded" });32    const h1 = await page.locator("h1").first().innerText();33    ok("Accueil : titre", /porte|maison/i.test(h1), h1.replace(/\s+/g, " "));34    await card(page, 4).waitFor({ timeout: 30000 }).catch(() => undefined);35    ok("Accueil : de vraies propriétés sont affichées", (await cards(page).count()) >= 4, `${await cards(page).count()} cartes`);3637    // liens entrants : q devient city38    await page.goto(BASE + "/recherche?q=Gatineau", { waitUntil: "domcontentloaded" });39    await page.waitForURL(/city=Gatineau/, { timeout: 15000 }).catch(() => undefined);40    ok("Recherche : la ville saisie devient un filtre", /city=Gatineau/.test(page.url()), new URL(page.url()).search);41    await page.waitForSelector(CARD, { timeout: 30000 });42    await page.waitForTimeout(2500);43    ok("Recherche : résultats", (await cards(page).count()) > 0, `${await cards(page).count()} cartes`);44    ok("Recherche : la carte est montée", (await page.locator(".mapboxgl-canvas").count()) > 0);4546    await page.goto(BASE + "/recherche?city=Gatineau&property_type=Condo&price_max=400000", { waitUntil: "domcontentloaded" });47    await page.waitForSelector(CARD, { timeout: 30000 });48    await page.waitForTimeout(2000);49    const prices = await page.evaluate((sel) => [...document.querySelectorAll(sel)].slice(0, 8).map((a) => Number((a.getAttribute("aria-label") || "").split("$")[0].replace(/[^\d]/g, ""))), CARD);50    ok("Recherche : le plafond de prix est respecté", prices.length > 0 && prices.every((p) => !p || p <= 400000), prices.join(", "));5152    // la porte de la maison53    const searchUrl = page.url();54    const first = card(page, 0);55    await first.scrollIntoViewIfNeeded();56    const t0 = Date.now();57    await first.click({ noWaitAfter: true });58    await page.waitForTimeout(120);59    ok("Porte : la scène apparaît au clic", await overlay(page));60    await page.waitForURL(/\/propriete\//, { timeout: 6000 });61    await page.waitForFunction(() => !document.querySelector(".ikd-root"), null, { timeout: 6000 });62    ok("Porte : la scène disparaît d'elle-même", !(await overlay(page)), `${Date.now() - t0} ms après le clic`);63    const img = await page.evaluate(() => {64      const i = document.querySelector("[data-door-target] img");65      return i ? i.complete && i.naturalWidth > 0 : null;66    });67    ok("Fiche : la photo principale est affichée à l'arrivée", img === true, String(img));68    ok("Fiche : titre et lien vers l'inscription d'origine", (await page.locator("h1").count()) > 0 && (await page.getByRole("link", { name: /inscription/i }).count()) > 0);69    ok("Fiche : position en haut de page", (await page.evaluate(() => window.scrollY)) < 4);7071    await page.goBack();72    await page.waitForURL(/\/recherche/, { timeout: 6000 });73    ok("Retour : filtres préservés", page.url() === searchUrl, new URL(page.url()).search);7475    // interruption76    await page.waitForSelector(CARD, { timeout: 20000 });77    await page.waitForTimeout(900);78    await card(page, 0).click({ noWaitAfter: true });79    await page.waitForTimeout(80);80    await page.mouse.click(700, 500);81    await page.waitForTimeout(1600);82    ok("Interruption : fiche atteinte, aucune scène résiduelle", /\/propriete\//.test(page.url()) && !(await overlay(page)));8384    // favoris85    await page.goto(BASE + "/recherche?city=Gatineau", { waitUntil: "domcontentloaded" });86    await page.waitForSelector(CARD, { timeout: 30000 });87    await page.getByRole("button", { name: "Ajouter aux favoris" }).first().click();88    const favs = await page.evaluate(() => {89      const k = Object.keys(localStorage).find((x) => /^immoka:fav/.test(x));90      const v = k ? JSON.parse(localStorage.getItem(k) || "{}") : {};91      return Array.isArray(v) ? v.length : Object.keys(v).length;92    });93    ok("Favoris : enregistré sur l'appareil", favs === 1 && /\/recherche/.test(page.url()), `${favs} favori`);94    await page.goto(BASE + "/favoris", { waitUntil: "domcontentloaded" });95    await page.waitForTimeout(2500);96    ok("Favoris : la page le liste", (await page.locator("a[href^='/propriete/']").count()) >= 1);9798    // thème99    await page.goto(BASE + "/", { waitUntil: "domcontentloaded" });100    const t1 = await page.evaluate(() => document.documentElement.dataset.theme);101    await page.getByRole("button", { name: /thème/i }).first().click();102    const t2 = await page.evaluate(() => document.documentElement.dataset.theme);103    ok("Thème : bascule clair / sombre", t1 !== t2, `${t1} → ${t2}`);104105    for (const p of ["/villes", "/a-vendre/gatineau", "/agences", "/marche", "/taux", "/vrai-prix", "/comparer", "/sources", "/inspecteurs", "/demenageurs", "/a-propos", "/contact", "/confidentialite", "/conditions", "/lab", "/page-inexistante"]) {106      await page.goto(BASE + p, { waitUntil: "domcontentloaded" });107      await page.waitForTimeout(900);108      ok(`Page ${p}`, (await page.locator("main :is(h1, h2, h3)").count()) > 0);109    }110    for (const [from, to] of [["/courtiers", /\/agences/], ["/ville/gatineau", /\/a-vendre\/gatineau/], ["/bannieres", /\/agences/]]) {111      await page.goto(BASE + from, { waitUntil: "domcontentloaded" });112      await page.waitForTimeout(700);113      ok(`Ancienne adresse ${from}`, to.test(page.url()), new URL(page.url()).pathname);114    }115    ok("Aucune erreur JavaScript pendant le parcours", errors.length === 0, errors.slice(0, 3).join(" | "));116    await ctx.close();117  }118119  // accès direct : aucune animation imposée120  {121    const { ctx, page } = await context();122    await page.goto(BASE + "/recherche?city=Montr%C3%A9al", { waitUntil: "domcontentloaded" });123    await page.waitForSelector(CARD, { timeout: 30000 });124    const href = await card(page, 0).getAttribute("href");125    await page.goto(BASE + href, { waitUntil: "domcontentloaded" });126    let seen = false;127    for (let i = 0; i < 6; i++) {128      seen ||= await overlay(page);129      await page.waitForTimeout(60);130    }131    ok("Lien direct : aucune porte, le contenu s'affiche immédiatement", !seen);132    await page.waitForSelector("[data-door-target] img", { timeout: 15000 }).catch(() => undefined);133    ok("Lien direct : la fiche est rendue (adresse canonique avec titre)", (await page.locator("[data-door-target] img").count()) > 0, new URL(page.url()).pathname);134    await ctx.close();135  }136137  // mouvement réduit138  {139    const { ctx, page } = await context({ reducedMotion: "reduce" });140    await page.goto(BASE + "/recherche?city=Montr%C3%A9al", { waitUntil: "domcontentloaded" });141    await page.waitForSelector(CARD, { timeout: 30000 });142    await page.waitForTimeout(1500);143    await card(page, 0).click({ noWaitAfter: true });144    const panel = await page.evaluate(() => (document.querySelector(".ikd-root .ikd-panel") ? "présent" : "aucun"));145    await page.waitForURL(/\/propriete\//, { timeout: 5000 });146    ok("Mouvement réduit : pas de pivotement, navigation directe", panel === "aucun", `panneau ${panel}`);147    await ctx.close();148  }149150  // mobile : aucun débordement horizontal151  for (const w of [320, 375, 390, 430, 768]) {152    const { ctx, page } = await context({ viewport: { width: w, height: 800 }, isMobile: w < 700, hasTouch: w < 700 });153    const bad = [];154    for (const p of ["/", "/recherche?city=Gatineau", "/agences", "/villes", "/marche", "/taux", "/favoris"]) {155      await page.goto(BASE + p, { waitUntil: "domcontentloaded" });156      await page.waitForTimeout(1800);157      const over = await page.evaluate(() => document.documentElement.scrollWidth - document.documentElement.clientWidth);158      if (over > 1) bad.push(`${p} +${over}px`);159    }160    ok(`Largeur ${w} px : aucun débordement horizontal`, bad.length === 0, bad.join(", "));161    await ctx.close();162  }163} catch (e) {164  ok("Parcours interrompu par une erreur", false, String(e).slice(0, 300));165} finally {166  await browser.close();167}168169const failed = results.filter((r) => !r.pass);170console.log(`\n${results.length - failed.length} réussis, ${failed.length} en échec`);171process.exit(failed.length ? 1 : 0);172
Files main
Menu

Theme