Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : UQO Éval — Le Grand Défi Immobilier8 * File : tests/e2e/partie-complete.spec.ts9 * Module : tests10 * Repository : https://git.spboucher.ai/uqo-eval-jeux11 * Project Website : https://jeux.uqo-eval.app12 * Created : 2026-11-2513 * Last Modified : 2026-11-2514 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { expect, test, type Page } from "@playwright/test";4445/** Répond à la propriété courante en choisissant le prix d'indice donné, puis passe à la suivante. */46async function repondre(page: Page, choix: number): Promise<{ correct: boolean }> {47 await page.locator(".choice:not([disabled])").first().waitFor();48 const numero = await page.locator(".hud-count .num").innerText();49 await page.locator(".choice").nth(choix).click();50 await page.locator(".answer-submit").click();51 await page.locator(".feedback-foot button").waitFor();52 const correct = (await page.locator(".feedback").getAttribute("data-verdict")) === "correct";53 await page.locator(".feedback-foot button").click();54 // Un jalon peut s'intercaler (10, 25, 50, 75, 90).55 const jalon = page.locator(".milestone button");56 if (await jalon.isVisible().catch(() => false)) await jalon.click();57 await expect(page.locator(".hud-count .num")).not.toHaveText(numero, { timeout: 20_000 }).catch(() => undefined);58 return { correct };59}6061test("partie complète de 100 propriétés, fermeture à la 37e, reprise, résultats et rapport", async ({ browser }) => {62 const contexte = await browser.newContext();63 let page = await contexte.newPage();64 const erreurs: string[] = [];65 page.on("pageerror", (e) => erreurs.push(e.message));6667 await page.goto("/");68 await page.getByRole("radio", { name: "100", exact: true }).click();69 await page.getByRole("button", { name: /S'entraîner sur 100 propriétés/ }).click();70 await page.waitForURL(/\/jouer\//);71 const adresse = page.url();72 await page.locator(".intro button").click();7374 let bonnes = 0;75 for (let i = 0; i < 36; i++) bonnes += (await repondre(page, i % 4)).correct ? 1 : 0;76 await expect(page.locator(".hud-count .num")).toHaveText("37");7778 // Le code de reprise est offert dans le menu Pause.79 await page.getByRole("button", { name: "Pause et paramètres" }).click();80 const code = (await page.locator(".resume-code").innerText()).trim();81 expect(code).toMatch(/^[A-Z0-9]{4}-[A-Z0-9]{4}-[A-Z0-9]{4}$/);8283 // Fermeture du navigateur à la propriété 37, puis retour sur le même appareil (mêmes témoins).84 const etat = await contexte.storageState();85 await contexte.close();86 const retour = await browser.newContext({ storageState: etat });87 page = await retour.newPage();88 page.on("pageerror", (e) => erreurs.push(e.message));89 await page.goto(adresse);90 await expect(page.locator(".hud-count .num")).toHaveText("37");91 await expect(page.locator(".hud-score")).toContainText(String(bonnes));9293 // Double clic sur un prix puis double clic sur « Valider » : une seule réponse comptée.94 await page.locator(".choice").nth(0).dblclick();95 await page.locator(".feedback-foot button").waitFor();96 bonnes += (await page.locator(".feedback").getAttribute("data-verdict")) === "correct" ? 1 : 0;97 await page.locator(".feedback-foot button").click();98 await expect(page.locator(".hud-count .num")).toHaveText("38");99100 // Un autre appareil, sans témoin : la partie est inaccessible par son adresse, mais reprise par le code.101 const autre = await browser.newContext();102 const pageAutre = await autre.newPage();103 await pageAutre.goto(adresse);104 await expect(pageAutre.getByRole("heading", { name: "Partie introuvable sur cet appareil" })).toBeVisible();105 await pageAutre.goto("/reprendre");106 await pageAutre.locator("#code").fill(code.toLowerCase());107 await pageAutre.getByRole("button", { name: /Reprendre/ }).click();108 await pageAutre.waitForURL(/\/jouer\//);109 await expect(pageAutre.locator(".hud-count .num")).toHaveText("38");110 await autre.close();111112 // La reprise par code émet un nouveau jeton : l'ancien appareil perd l'accès, on poursuit donc par le code.113 await page.goto("/reprendre");114 await page.locator("#code").fill(code);115 await page.getByRole("button", { name: /Reprendre/ }).click();116 await page.waitForURL(/\/jouer\//);117118 for (let i = 37; i < 99; i++) bonnes += (await repondre(page, (i * 3) % 4)).correct ? 1 : 0;119120 // Dernière propriété : le bouton mène aux résultats.121 await page.locator(".choice:not([disabled])").first().waitFor();122 await page.locator(".choice").nth(1).click();123 await page.locator(".answer-submit").click();124 await page.locator(".feedback-foot button").waitFor();125 bonnes += (await page.locator(".feedback").getAttribute("data-verdict")) === "correct" ? 1 : 0;126 await expect(page.locator(".feedback-foot button")).toContainText("Voir mes résultats");127 await page.locator(".feedback-foot button").click();128 await page.waitForURL(/\/resultats\//);129130 // Le score affiché est celui que le serveur a compté, égal au nombre de bonnes réponses observées.131 await expect(page.locator(".finale-score")).toHaveAttribute("aria-label", `${bonnes} bonnes réponses sur 100`);132 await expect(page.getByRole("heading", { name: /Comprendre vos/ })).toBeVisible();133 await expect(page.locator(".chart-card")).toHaveCount(12);134 await expect(page.locator(".review-item").first()).toBeVisible();135136 // Une partie terminée ne se rejoue pas : l'adresse de jeu renvoie aux résultats.137 await page.goto(adresse);138 await page.waitForURL(/\/resultats\//);139140 expect(erreurs).toEqual([]);141 await retour.close();142});143144test("le score ne peut pas être modifié depuis le navigateur", async ({ page }) => {145 await page.goto("/");146 await page.locator(".entry-alt").click();147 await page.waitForURL(/\/jouer\//);148 const id = page.url().split("/").pop()!;149 await page.locator(".intro button").click();150 await page.locator(".choice:not([disabled])").first().waitFor();151 // Tentative : envoyer un score et un indicateur de bonne réponse avec la soumission.152 const reponse = await page.evaluate(async (game) => {153 const etat = await (await fetch("/api/v1/game/current", { headers: { "x-game": game, "x-requested-with": "gdi" } })).json();154 const res = await fetch("/api/v1/game/answer", {155 method: "POST",156 headers: { "content-type": "application/json", "x-game": game, "x-requested-with": "gdi" },157 body: JSON.stringify({ questionId: etat.question.id, choiceId: etat.question.choices[0].id, idempotencyKey: crypto.randomUUID(), isCorrect: true, score: 100, correct: 100 }),158 });159 return res.json();160 }, id);161 expect(reponse.session.answered).toBe(1);162 expect(reponse.session.correct).toBe(reponse.isCorrect ? 1 : 0);163 expect(reponse.session.correct).toBeLessThanOrEqual(1);164});165166test("accueil : menu des noms, essai libre et prix @mobile", async ({ page }) => {167 await page.goto("/");168 await expect(page.getByRole("heading", { level: 1 })).toContainText("Connaissez-vous");169 await expect(page.locator("#nom-liste")).toBeVisible();170 expect(await page.locator("#nom-liste option").count()).toBeGreaterThan(1);171 await expect(page.getByRole("button", { name: /Essayer 30 propriétés, sans nom/ })).toBeVisible();172 // Aucun défilement horizontal de la page.173 expect(await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth + 1)).toBe(true);174});175