// Rôle : valide l'ouverture, la reprise, l'album et l'administration de Sokko TCG. import { readFile, writeFile } from "node:fs/promises"; import { tmpdir } from "node:os"; import { join } from "node:path"; import { DatabaseSync } from "node:sqlite"; import { expect, test } from "@playwright/test"; // Sélecteurs à choix unique du design system (`SelectDropdown`). const selectTrigger = (scope, label) => scope.getByRole("button", { name: new RegExp(`^${label} : `) }); async function chooseOption(scope, label, option) { await selectTrigger(scope, label).click(); await scope.getByRole("option", typeof option === "string" ? { name: option, exact: true } : { name: option }).click(); } async function expectOptions(page, scope, label, options) { await selectTrigger(scope, label).click(); await expect(scope.getByRole("option")).toHaveText(options); await page.keyboard.press("Escape"); } const INHERITED = /hérité|défaut/; // En demi-écran, le menu de sections est replié derrière un bouton qui nomme la section courante : l'ouvrir avant d'y choisir une entrée. async function expandSections(page, name) { const toggle = selectTrigger(page, name); if (await toggle.isVisible() && await toggle.getAttribute("aria-expanded") === "false") await toggle.click(); } // Le menu ouvert reste entièrement visible et personne ne le recouvre, quel que soit le bord dont il est proche. async function expectOpenMenuVisible(page, selector) { const result = await page.locator(selector).evaluate((menu) => { const box = menu.getBoundingClientRect(); const clip = menu.ownerDocument.querySelector("main").getBoundingClientRect(); const points = [[box.left + 8, box.top + 8], [box.right - 8, box.top + 8], [box.left + 8, box.bottom - 8], [box.right - 8, box.bottom - 8]]; return { inside: box.left >= clip.left && box.right <= Math.min(clip.right, globalThis.innerWidth) && box.top >= 0 && box.bottom <= globalThis.innerHeight, covered: points.filter(([x, y]) => !menu.contains(menu.ownerDocument.elementFromPoint(x, y))).length }; }); expect(result).toEqual({ inside: true, covered: 0 }); } // Chaque option d'un menu ouvert est bien celle qu'on toucherait en son centre : aucun voisin ne la recouvre. async function expectOpenOptionsOnTop(page, selector) { const covered = await page.locator(selector).evaluate((menu) => [...menu.querySelectorAll("[role=option]")].filter((option) => { const box = option.getBoundingClientRect(); return !option.contains(menu.ownerDocument.elementFromPoint(box.left + box.width / 2, box.top + box.height / 2)); }).map((option) => option.textContent)); expect(covered).toEqual([]); } // Une phase d'aura dure de 300 à 450 ms, pilotées par setTimeout : sur une machine chargée, elle peut finir avant la lecture de ses styles. // Figer l'horloge de la page garde chaque phase affichée le temps des assertions ; `page.clock.runFor()` passe à la suivante et `resume()` relance le temps. const holdRevealTimers = async (page) => page.clock.pauseAt(await page.evaluate(() => Date.now()) + 1000); // Rend un anneau légendaire et un anneau mythique figés au même instant, avec une palette unie identique, // puis compare leurs profils de luminance radiaux : la silhouette (trait + lueur) doit être la même. async function expectMythicRingSilhouetteToMatchLegendary(page) { const color = "#f6c453"; await page.evaluate((probeColor) => { const style = globalThis.document.createElement("style"); style.dataset.ringProbe = ""; style.textContent = "[data-ring-probe] .nebula-card-particles::after, [data-ring-probe] .nebula-card-particles i { display: none !important; } [data-ring-probe] *, [data-ring-probe] *::before { animation-play-state: paused !important; animation-delay: -400ms !important; }"; globalThis.document.head.append(style); for (const [index, rarity] of ["legendary", "mythic"].entries()) { const probe = globalThis.document.createElement("div"); probe.className = "nebula-card"; probe.dataset.ringProbe = rarity; probe.dataset.rarity = rarity; probe.dataset.particleShape = "sparks"; probe.style.cssText = `position: fixed; z-index: 2147483647; top: 0; left: ${index * 320}px; width: 320px; height: 320px; max-width: none; aspect-ratio: auto; background: #000; --opening-aura: ${probeColor}; --particle-gradient: ${probeColor}; --opening-particle-duration: 1200ms;`; const particles = globalThis.document.createElement("span"); particles.className = "nebula-card-particles"; if (rarity === "mythic") particles.innerHTML = ''; probe.append(particles); globalThis.document.body.append(probe); } }, color); const shot = await page.screenshot({ clip: { x: 0, y: 0, width: 640, height: 320 } }); const profiles = await page.evaluate(async (base64) => { const image = new globalThis.Image(); image.src = `data:image/png;base64,${base64}`; await image.decode(); const canvas = globalThis.document.createElement("canvas"); canvas.width = image.width; canvas.height = image.height; const context = canvas.getContext("2d"); context.drawImage(image, 0, 0); const scale = image.width / 640; const directions = Array.from({ length: 8 }, (_, index) => [Math.cos(index * Math.PI / 4), Math.sin(index * Math.PI / 4)]); const profile = (centerX) => Array.from({ length: 50 }, (_, step) => { const radius = step * 3; const total = directions.reduce((sum, [dx, dy]) => { const [red, green, blue] = context.getImageData(Math.round((centerX + dx * radius) * scale), Math.round((160 + dy * radius) * scale), 1, 1).data; return sum + (red + green + blue) / 3; }, 0); return total / directions.length; }); globalThis.document.querySelectorAll("[data-ring-probe]").forEach((element) => element.remove()); return { legendary: profile(160), mythic: profile(480) }; }, shot.toString("base64")); expect(Math.max(...profiles.legendary)).toBeGreaterThan(100); const differences = profiles.legendary.map((value, index) => Math.abs(value - profiles.mythic[index])); expect(Math.max(...differences)).toBeLessThan(24); expect(differences.reduce((sum, value) => sum + value, 0) / differences.length).toBeLessThan(4); } async function expectArtworkFramed(card) { const layout = await card.evaluate((element) => { const bounds = (selector) => { const rect = element.querySelector(selector).getBoundingClientRect(); return { top: rect.top, right: rect.right, bottom: rect.bottom, left: rect.left, width: rect.width }; }; const artwork = element.querySelector(".nebula-card-art img, .nebula-card-placeholder-mark"); return { face: bounds(".nebula-card-face"), art: bounds(".nebula-card-art"), artwork: bounds(artwork.matches("img") ? ".nebula-card-art img" : ".nebula-card-placeholder-mark"), image: artwork.matches("img"), size: element.dataset.cardSize, title: bounds("h3") }; }); expect(layout.artwork.bottom).toBeLessThanOrEqual(layout.art.bottom + 0.5); expect(layout.artwork.left).toBeGreaterThanOrEqual(layout.art.left - 0.5); expect(layout.artwork.right).toBeLessThanOrEqual(layout.art.right + 0.5); if (layout.image) { expect(layout.artwork.width / layout.art.width).toBeGreaterThan(0.98); } else if (layout.size === "md") { expect(layout.artwork.bottom).toBeLessThanOrEqual(layout.title.top + 0.5); expect(layout.artwork.width / layout.face.width).toBeLessThan(0.46); } else { expect(layout.artwork.top).toBeGreaterThanOrEqual(layout.title.bottom - 0.5); expect(layout.artwork.width / layout.face.width).toBeLessThan(0.46); } } async function expectFixedTitleBand(card, position) { const layout = await card.evaluate((element) => { const title = element.querySelector("h3").getBoundingClientRect(); const art = element.querySelector(".nebula-card-art").getBoundingClientRect(); return { title: { top: title.top, bottom: title.bottom, height: title.height }, art: { top: art.top, bottom: art.bottom } }; }); expect(Math.abs(layout.title.height - 52)).toBeLessThan(0.6); if (position === "top") { expect(Math.abs(layout.title.bottom - layout.art.top)).toBeLessThan(0.6); } else { expect(Math.abs(layout.art.bottom - layout.title.top)).toBeLessThan(0.6); } } async function expectStandardCardFrame(card, size) { const layout = await card.evaluate((element) => { const face = element.querySelector(".nebula-card-face"); const art = element.querySelector(".nebula-card-art"); const title = element.querySelector("h3"); const copy = element.querySelector(".nebula-card-copy"); const rarity = element.querySelector(".nebula-card-rarity-symbol"); const faceBounds = face.getBoundingClientRect(); const artBounds = art.getBoundingClientRect(); const styles = element.ownerDocument.defaultView; const titleStyles = styles.getComputedStyle(title); const titleTextStyles = styles.getComputedStyle(title.querySelector("span")); const rarityStyles = styles.getComputedStyle(rarity); return { layout: face.dataset.cardLayout, facePattern: styles.getComputedStyle(face).backgroundImage, titleBackground: titleStyles.backgroundColor, titleDisplay: titleStyles.display, titleAlignItems: titleStyles.alignItems, titleJustifyItems: titleStyles.justifyItems, titleFontSize: Number.parseFloat(titleStyles.fontSize), titlePaddingRight: Number.parseFloat(titleStyles.paddingRight), titleTextAlign: titleTextStyles.textAlign, titleLineClamp: titleTextStyles.webkitLineClamp, copyBackground: copy ? styles.getComputedStyle(copy).backgroundColor : null, rarityPosition: rarityStyles.position, rarityWidth: Number.parseFloat(rarityStyles.width), leftInset: artBounds.left - faceBounds.left, rightInset: faceBounds.right - artBounds.right }; }); expect(layout.layout).toBe("standard"); expect(layout.facePattern).not.toBe("none"); expect(layout.facePattern).not.toContain("repeating-linear-gradient"); expect(layout.facePattern.match(/radial-gradient/g)).toHaveLength(4); expect(layout.titleBackground).toBe("rgba(0, 0, 0, 0)"); expect(layout.titleDisplay).toBe("grid"); expect(layout.titleAlignItems).toBe("center"); expect(layout.titleJustifyItems).toBe("center"); expect(layout.titleTextAlign).toBe("center"); expect(layout.titleLineClamp).toBe("2"); if (size === "lg") { expect(layout.copyBackground).toBe("rgba(0, 0, 0, 0)"); expect(layout.leftInset).toBeGreaterThan(10); expect(layout.rightInset).toBeGreaterThan(10); } else { expect(layout.leftInset).toBeLessThan(3); expect(layout.rightInset).toBeLessThan(3); expect(layout.titleFontSize).toBeLessThan(14); expect(layout.titlePaddingRight).toBeLessThan(12); expect(layout.rarityPosition).toBe("absolute"); expect(layout.rarityWidth).toBe(13); } } test("a failed Discord return explains the failure once on the login screen", async ({ page }) => { await page.goto("/?cardsAuth=denied#/cards/shop"); await expect(page.getByRole("alert")).toHaveText("Connexion annulée : vous n’avez pas autorisé l’accès depuis Discord."); await expect(page.getByRole("link", { name: "Se connecter avec Discord", exact: true })).toHaveAttribute("href", "/api/cards/auth/discord?returnTo=%2Fcards%2Fshop"); await expect(page).toHaveURL(/:\d+\/#\/cards\/shop$/); await page.reload(); await expect(page.getByRole("heading", { name: "Sokko TCG", exact: true })).toBeVisible(); await expect(page.getByRole("alert")).toHaveCount(0); }); test("player opens and reveals a three-card pack", async ({ page }) => { test.setTimeout(60_000); await page.goto("/#/cards"); await expect(page.locator(".nav-icon-cards")).toHaveCSS("mask-image", /tcg\.svg/); await expect(page.locator(".sidebar-note")).toContainText("Sokko TCG"); await expect(page.getByRole("heading", { name: "Sokko TCG", exact: true })).toBeVisible(); await expect(page.getByText("Trading Card Game", { exact: true })).toBeVisible(); const loginArt = page.locator('.nebula-login-art img[src="/static/img/cards/login.webp"]'); await expect(loginArt).toBeVisible(); await expect.poll(() => loginArt.evaluate((image) => image.naturalWidth)).toBeGreaterThan(0); const discordLogin = page.getByRole("link", { name: "Se connecter avec Discord", exact: true }); await expect(discordLogin).toHaveCSS("background-color", "rgb(88, 101, 242)"); await expect(discordLogin.locator("span")).toHaveCSS("color", "rgb(255, 255, 255)"); const discordIcon = discordLogin.locator('img[src="/static/icons/discord.svg"]'); await expect(discordIcon).toBeVisible(); await expect(discordIcon).toHaveCSS("width", "26px"); await expect(discordIcon).toHaveCSS("height", "26px"); await expect(page.getByRole("button", { name: "Test administrateur", exact: true })).toHaveCount(0); await page.getByRole("button", { name: "Version développement", exact: true }).click(); const administrationButton = page.getByRole("link", { name: "Administration", exact: true }); const logoutButton = page.getByRole("button", { name: "Déconnexion", exact: true }); await expect(administrationButton).toBeVisible(); await expect(administrationButton).toHaveAttribute("href", "#/cards/admin"); await expect(logoutButton).toHaveAttribute("data-variant", "secondary"); // Le lien de bascule précède le menu latéral collant et l'accompagne au défilement. expect(await administrationButton.evaluate((element) => element.nextElementSibling?.querySelector("nav")?.getAttribute("aria-label"))).toBe("Sections de Sokko TCG"); await expect(page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Accueil", exact: true })).toHaveAttribute("aria-current", "page"); await expect(page.locator(".nebula-player-hero.nds-page-hero")).toBeVisible(); await expect(page.getByRole("heading", { name: "Vue d’ensemble", exact: true })).toBeVisible(); await expect(page.locator('.nebula-opening-reserve[aria-label="Ouvertures disponibles"] .nebula-opening-reserve-value')).toContainText("3/ 5"); await expect(page.getByText("Probabilités", { exact: true })).toHaveCount(0); // En 1280 × 720, l'en-tête, la rangée Guilde / meilleur tirage et les chiffres clés tiennent sans défiler. // Comme sur Paquets, la réserve d'ouvertures se range sous le menu, avec un accès direct aux paquets. await expect(page.locator(".nebula-dashboard-aside-slot .nebula-opening-reserve")).toContainText("Voir les paquets"); expect(await page.locator(".nebula-home-stats").evaluate((element) => element.getBoundingClientRect().bottom <= element.ownerDocument.defaultView.innerHeight + 1)).toBe(true); await expandSections(page, "Sections de Sokko TCG"); await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Paquets", exact: true }).click(); await expect(page.getByRole("heading", { name: "Paquets permanents", exact: true })).toBeVisible(); await expect(page.getByRole("heading", { name: "Paquets événements", exact: true })).toBeVisible(); // Les ouvertures disponibles sont sous le menu, et non plus dans le titre de la page. await expect(page.locator(".nebula-dashboard-aside-slot .nebula-opening-reserve")).toBeVisible(); // Les deux catégories sont côte à côte : elles commencent à la même hauteur. const packCategoryBoxes = await page.locator(".nebula-pack-category").evaluateAll((sections) => sections.map((section) => section.getBoundingClientRect()).map(({ top, left }) => ({ top, left }))); expect(packCategoryBoxes[0].top).toBeCloseTo(packCategoryBoxes[1].top, 0); expect(packCategoryBoxes[1].left).toBeGreaterThan(packCategoryBoxes[0].left); // Titres et paquets restent alignés d'une section à l'autre, même si un sous-titre passe à la ligne. for (const selector of [".nebula-pack-category h3", ".nebula-pack-category .nebula-pack"]) { const [first, second] = await page.locator(selector).evaluateAll((elements) => elements.map((element) => element.getBoundingClientRect().top)); expect(first).toBeCloseTo(second, 0); } await expect(page.locator(".nebula-pack .nebula-collection-back")).toHaveCount(2); await expect(page.locator('.nebula-pack-back img[src="/static/img/cards/primordial-nebula/back.webp"]')).toBeVisible(); await expect(page.locator('.nebula-pack-back img[src="/static/img/cards/astral-genesis/back.webp"]')).toBeVisible(); await expect(page.locator('.nebula-pack-back[data-card-size="md"]')).toHaveCount(2); expect((await page.locator(".nebula-pack-back").first().boundingBox()).width).toBeCloseTo(180, 0); await expect(page.locator(".nebula-pack").filter({ hasText: "Genèse Astrale" })).toBeVisible(); const originsPack = page.locator(".nebula-pack").filter({ hasText: "La Nébuleuse Originelle" }); await expect(originsPack.locator(".nebula-collection-back-copy")).toHaveText("La Nébuleuse Originelle"); await expect(originsPack.locator(".nebula-collection-back-copy")).not.toContainText("Sokko TCG"); expect(await originsPack.locator(".nebula-collection-back").evaluate((back) => { const backBox = back.getBoundingClientRect(); const copyBox = back.querySelector(".nebula-collection-back-copy").getBoundingClientRect(); return (copyBox.top + copyBox.height / 2 - backBox.top) / backBox.height; })).toBeGreaterThan(0.68); // La tuile compacte se limite au dos de carte et à la description : elle est entièrement cliquable. expect((await originsPack.boundingBox()).width).toBeCloseTo(180, 0); await expect(originsPack).not.toHaveClass(/nds-card/); // Le survol illumine le dos sans peindre le bouton derrière la description. await originsPack.hover(); await expect(originsPack).toHaveCSS("background-image", "none"); await expect(originsPack).toHaveCSS("box-shadow", "none"); await expect(originsPack.locator(".nebula-pack-back")).toHaveCSS("box-shadow", /246, 196, 83/); await expect(originsPack.locator(".nebula-pack-copy")).toHaveCSS("-webkit-line-clamp", "3"); // Les descriptions actuelles tiennent sur ces trois lignes, sans points de suspension. expect(await page.locator(".nebula-pack-copy").evaluateAll((copies) => copies.every((copy) => copy.scrollHeight <= copy.clientHeight))).toBe(true); await expect(page.locator(".nebula-pack-categories > .nds-panel")).toHaveCount(2); await expect(page.getByText("Probabilités", { exact: true })).toHaveCount(0); await page.getByRole("button", { name: "Ouvrir ce paquet : La Nébuleuse Originelle", exact: true }).click(); // L'étape d'ouverture garde le hero, affiche les probabilités et ne propose le retour qu'une fois les cartes révélées. await expect(page.locator(".nebula-player-hero")).toBeVisible(); // Les particules passent sous la barre du haut : son flou serait recalculé à chaque image de l'animation. await expect(page.locator(".topbar")).toHaveCSS("backdrop-filter", "none"); const openingOdds = page.getByRole("list", { name: "Probabilités" }).getByRole("listitem"); await expect(openingOdds).toHaveCount(5); await expect(openingOdds.first()).toContainText(/Commun.*%/); await expect(page.getByRole("button", { name: "Retour", exact: true })).toHaveCount(0); await expect(page.getByRole("button", { name: "Révéler la carte" })).toHaveCount(3); await expect(page.locator('.nebula-card-back img[src="/static/img/cards/primordial-nebula/back.webp"]')).toHaveCount(3); await expect(page.locator(".nebula-card-back").first()).toHaveCSS("background-image", /primordial-nebula\/back\.webp/); await expect(page.locator(".nebula-card-back .nebula-collection-back-copy strong")).toHaveText(["La Nébuleuse Originelle", "La Nébuleuse Originelle", "La Nébuleuse Originelle"]); expect(await page.locator(".nebula-card-back .nebula-collection-back").first().evaluate((back) => { const backBox = back.getBoundingClientRect(); const copyBox = back.querySelector(".nebula-collection-back-copy").getBoundingClientRect(); return (copyBox.top + copyBox.height / 2 - backBox.top) / backBox.height; })).toBeLessThan(0.9); // L'adresse de section survit au rechargement : l'ouverture en attente réapparaît, et l'accueil propose aussi de la reprendre. await page.reload(); await expect(page.getByRole("button", { name: "Révéler la carte" })).toHaveCount(3); // Le journal ne dévoile pas les cartes d'une ouverture encore en attente. await page.goto("/#/cards/history"); await expect(page.getByText("Cartes à révéler", { exact: true })).toBeVisible(); await expect(page.getByRole("list", { name: "Cartes obtenues" })).toHaveCount(0); await page.goto("/#/cards"); // L'accueil ne dévoile pas non plus la meilleure carte d'un tirage encore caché. await expect(page.getByRole("button", { name: "Reprendre l’ouverture", exact: true })).toBeVisible(); await expect(page.locator(".nebula-home-rarest-card")).toHaveCount(0); await page.getByRole("button", { name: "Reprendre l’ouverture", exact: true }).click(); await expect(page.getByRole("button", { name: "Révéler la carte" })).toHaveCount(3); // Le badge « New » suit l'édition non possédée et n'apparaît qu'une fois la carte révélée : la première carte du tout premier paquet est forcément nouvelle. const newEditions = await page.evaluate(async () => (await globalThis.fetch("/api/cards/state")).json().then((state) => state.pendingOpening.cards.map((card) => card.isNewEdition))); expect(newEditions[0]).toBe(true); await expect(page.locator(".nebula-card-new-badge")).toHaveCount(0); await page.getByRole("button", { name: "Tout révéler" }).click(); const openingStage = page.locator(".nebula-opening-stage"); const revealedCards = page.locator('.nebula-opening-cards .nebula-card[data-card-size="lg"]'); await expect(revealedCards).toHaveCount(3); await expect(page.getByRole("button", { name: "Retour", exact: true })).toHaveCount(0); await expect(revealedCards.first()).toHaveAttribute("data-reveal-phase", /aura|revealing/); // L'ouverture montre le vrai format `lg`, 300 x 420 px, dès que les trois cartes tiennent. const revealedBox = await revealedCards.first().boundingBox(); expect([Math.round(revealedBox.width), Math.round(revealedBox.height)]).toEqual([300, 420]); expect(await revealedCards.evaluateAll((cards) => cards.map((card) => card.ownerDocument.defaultView.getComputedStyle(card).opacity))).toEqual(["1", "1", "1"]); await expect(revealedCards.first().locator(".nebula-card-face")).toHaveCSS("border-top-color", "rgb(103, 232, 249)"); await expect(revealedCards.first().locator(".nebula-card-rarity-symbol")).toHaveCSS("color", "rgb(103, 232, 249)"); await expect(revealedCards.first().locator(".nebula-card-particles i").first()).toHaveCSS("color", "rgb(255, 59, 48)"); await expect(page.getByRole("button", { name: "Retour", exact: true })).toBeVisible(); expect(await revealedCards.evaluateAll((cards) => cards.map((card) => card.querySelector(".nebula-card-new-badge")?.textContent === "New"))).toEqual(newEditions); expect(await revealedCards.evaluateAll((cards) => cards.map((card) => card.getAttribute("aria-label").endsWith(", nouvelle carte")))).toEqual(newEditions); const revealedNames = await revealedCards.evaluateAll((cards) => cards.map((card) => card.getAttribute("aria-label").replace(/ révélée(, nouvelle carte)?$/, ""))); await expect.poll(() => page.evaluate(async () => (await globalThis.fetch("/api/cards/state")).json().then((state) => state.pendingOpening))).toBeNull(); expect((await openingStage.boundingBox()).width).toBeLessThanOrEqual(1000); await expect(page.locator(".nebula-opening-summary")).toHaveCount(0); await page.setViewportSize({ width: 768, height: 900 }); await expect(page.getByRole("button", { name: "Retour", exact: true })).toBeVisible(); expect(await page.evaluate(() => globalThis.document.documentElement.scrollWidth <= globalThis.document.documentElement.clientWidth)).toBe(true); await page.setViewportSize({ width: 1280, height: 720 }); await page.getByRole("button", { name: "Retour", exact: true }).click(); await expect(page.getByRole("heading", { name: "Paquets permanents", exact: true })).toBeVisible(); await expect(page).toHaveURL(/#\/cards\/packs$/); // Une fois révélées, les cartes apparaissent en référence dans le journal. await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Historique", exact: true }).click(); const historyCards = page.getByRole("list", { name: "Cartes obtenues" }).getByRole("listitem"); await expect(historyCards).toHaveCount(3); await expect(historyCards.first().getByRole("img")).toHaveAttribute("aria-label", /^(Commun|Rare|Épique|Légendaire|Mythique)$/); await expect(historyCards.locator(".nds-badge").filter({ hasText: /· (Commun|Rare|Épique|Légendaire|Mythique)\b/ })).toHaveCount(0); // La pastille de chaque carte prend la couleur de sa rareté (une légendaire n'a pas la couleur d'une commune). expect(await historyCards.evaluateAll((items) => items.every((item) => { const color = item.ownerDocument.defaultView.getComputedStyle(item.querySelector(".nebula-history-rarity")).backgroundColor; return color === { common: "rgb(156, 163, 175)", rare: "rgb(59, 130, 246)", epic: "rgb(217, 70, 239)", legendary: "rgb(246, 196, 83)", mythic: "rgb(103, 232, 249)" }[item.dataset.rarity]; }))).toBe(true); for (const name of revealedNames) await expect(historyCards.filter({ hasText: name }).first()).toBeVisible(); await expect(page.getByText("Cartes à révéler", { exact: true })).toHaveCount(0); await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Accueil", exact: true }).click(); await expect(page.getByRole("heading", { name: "Carte la plus rare tirée", exact: true })).toBeVisible(); expect(revealedNames).toContain(await page.locator(".nebula-home-rarest-copy > strong").textContent()); const rarestCard = page.locator('.nebula-home-rarest-card .nebula-card[data-card-size="md"]'); await expect(rarestCard.locator(".nebula-card-art")).toBeVisible(); await expect(rarestCard.locator(".nebula-card-art img")).toBeVisible(); await expect(rarestCard.locator(".nebula-card-rarity-symbol")).toBeVisible(); await expect(rarestCard.locator("h3")).toBeVisible(); // La carte la plus rare ouvre la même fiche que l'album, en grand format. const rarestName = await page.locator(".nebula-home-rarest-copy > strong").textContent(); await page.getByRole("button", { name: `Voir ${rarestName}`, exact: true }).click(); const rarestDialog = page.getByRole("dialog", { name: rarestName, exact: true }); await expect(rarestDialog.locator('.nebula-card[data-card-size="lg"]')).toBeVisible(); await expect(rarestDialog.locator("dl > div").filter({ hasText: "Exemplaires possédés" }).locator("dd")).toHaveText(/^[1-9]\d*$/); await expect(rarestDialog.getByRole("button", { name: "Ajouter aux favoris" })).toBeVisible(); await rarestDialog.getByRole("button", { name: "Fermer" }).click(); await expect(rarestDialog).toHaveCount(0); await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Collection", exact: true }).click(); await expect(page.getByRole("heading", { name: /Album/ })).toHaveCount(0); await expect(page.getByRole("heading", { name: "Ma collection", exact: true, level: 2 })).toBeVisible(); // L'album sépare les cartes par collection, dans l'ordre du catalogue ; un filtre masque les groupes vides. await expect(page.locator(".nebula-album-group > h3")).toHaveText([/^La Nébuleuse Originelle \d+ \/ \d+$/, /^Genèse Astrale \d+ \/ \d+$/, /^Poussières d'étoiles \d+ \/ \d+$/]); // Le titre porte le badge des éditions différentes possédées et une fine barre de progression. const nebulaBadge = page.locator(".nebula-album-group > h3 .nds-badge").first(); await expect(page.locator(".nebula-progress-tile")).toHaveCount(0); await expect(page.locator(".nebula-album-group > .nds-progress")).toHaveCount(3); await expect(nebulaBadge).toHaveText(/^[1-9]\d* \/ \d+$/); await expect(page.locator(".nebula-album-group", { hasText: "Genèse Astrale" }).locator(".nebula-album-entry").first()).toBeVisible(); // Les filtres reprennent les menus à cases à cocher des pages de jeux, avec leurs badges actifs. await expect(page.locator(".nebula-album-filters")).toHaveAttribute("data-variant", "horizontal-menu"); const albumFilters = page.locator(".nebula-album-filters"); await albumFilters.getByRole("button", { name: "Collection", exact: true }).click(); await albumFilters.getByRole("checkbox", { name: "Genèse Astrale" }).check(); await page.keyboard.press("Escape"); // Le menu passe au-dessus des cartes : sa dernière option reste cliquable, et un badge permet de la retirer. await albumFilters.getByRole("button", { name: "Rareté", exact: true }).click(); await albumFilters.getByRole("checkbox", { name: "Mythique" }).check(); await page.keyboard.press("Escape"); await albumFilters.getByRole("button", { name: "Retirer le filtre Rareté : Mythique" }).click(); await expect(page.locator(".nebula-album-group > h3")).toHaveText([/^Genèse Astrale \d+ \/ \d+$/]); // Le bouton de réinitialisation vide la recherche et remet tous les filtres à zéro. await expect(albumFilters.getByRole("button", { name: "Retirer le filtre Collection : Genèse Astrale" })).toBeVisible(); await page.getByPlaceholder("Rechercher...").first().fill("aucune carte ne porte ce nom"); await expect(page.getByText("Aucune édition ne correspond à ces filtres.")).toBeVisible(); await page.getByRole("button", { name: "Réinitialiser les filtres" }).click(); await expect(page.getByPlaceholder("Rechercher...").first()).toHaveValue(""); await expect(albumFilters.locator(".nds-active-filter")).toHaveCount(0); await expect(page.locator(".nebula-album-group > h3")).toHaveCount(3); // Au défilement, le menu collant reste sous le header au lieu de passer derrière. await page.evaluate(() => globalThis.scrollTo(0, 900)); await expect.poll(() => page.evaluate(() => globalThis.scrollY)).toBeGreaterThan(0); const [topbarBottom, stickyNavTop] = await page.evaluate(() => [globalThis.document.querySelector(".topbar").getBoundingClientRect().bottom, globalThis.document.querySelector(".nebula-dashboard-nav").getBoundingClientRect().top]); expect(stickyNavTop).toBeGreaterThanOrEqual(topbarBottom); await page.evaluate(() => globalThis.scrollTo(0, 0)); await expect(page.locator(".nebula-album-entry:not([data-missing])").first()).toBeVisible(); await expect(page.locator(".nebula-card-concealed").first()).toBeVisible(); await expect(page.locator('.nebula-card-concealed[data-card-size="md"]').first()).toBeVisible(); await expect(page.locator(".nebula-card-concealed .nebula-card-face")).toHaveCount(0); const undiscoveredCard = page.locator(".nebula-album-entry[data-undiscovered] .nebula-card-concealed").first(); await expect(undiscoveredCard).toBeVisible(); await expect(undiscoveredCard.locator(".nebula-card-tilt-surface")).toHaveCSS("filter", "grayscale(0.6) brightness(0.72)"); await expect(undiscoveredCard.locator(".nebula-card-tilt-surface")).toHaveCSS("opacity", "0.7"); expect((await undiscoveredCard.boundingBox()).width).toBeLessThanOrEqual(181); const holographicCard = page.locator('.nebula-card[data-holo-effect="spectral-prism"][data-holo-palette="aurora"]').first(); const cosmicCard = page.locator('.nebula-card[data-holo-effect="spectral-prism"][data-holo-palette="cosmic"]').first(); await expect(holographicCard.locator(".nebula-card-holo-primary")).toBeAttached(); await expect(holographicCard.locator(".nebula-card-holo-secondary")).toBeAttached(); await expect(holographicCard).toHaveAttribute("data-card-size", "md"); await expect(holographicCard.locator("h3")).toBeVisible(); await expect(holographicCard.locator(".nebula-card-rarity-symbol")).toBeVisible(); await expect(holographicCard.locator(".nebula-card-quantity")).toBeVisible(); await expect(holographicCard.locator(".nebula-card-copy")).toHaveCount(0); await expect(cosmicCard).toBeAttached(); expect(await holographicCard.evaluate((element) => element.ownerDocument.defaultView.getComputedStyle(element).getPropertyValue("--holo-1").trim())).toBe("#0b5e4a"); expect(await cosmicCard.evaluate((element) => element.ownerDocument.defaultView.getComputedStyle(element).getPropertyValue("--holo-1").trim())).toBe("#1e1b6b"); const holographicGradient = await holographicCard.evaluate((element) => element.ownerDocument.defaultView.getComputedStyle(element).getPropertyValue("--holo-gradient").trim()); const renderedSpectrum = await holographicCard.locator(".nebula-card-holo-primary").evaluate((element) => element.ownerDocument.defaultView.getComputedStyle(element).backgroundImage); expect(holographicGradient).not.toMatch(/\d+%/); expect(holographicGradient.match(/#[0-9a-f]{6}/gi)).toHaveLength(21); expect(renderedSpectrum.match(/linear-gradient/g)).toHaveLength(1); await expectArtworkFramed(holographicCard); await expectFixedTitleBand(holographicCard, "bottom"); await expectStandardCardFrame(holographicCard, "md"); await expect.poll(() => holographicCard.locator(".nebula-card-art img").evaluate((image) => ({ width: image.naturalWidth, height: image.naturalHeight }))).toEqual({ width: 800, height: 800 }); await expect(holographicCard.locator(".nebula-card-holo-primary")).toHaveCSS("background-repeat", "no-repeat"); await holographicCard.scrollIntoViewIfNeeded(); const bounds = await holographicCard.boundingBox(); await page.mouse.move(bounds.x + bounds.width * 0.82, bounds.y + bounds.height * 0.24); await expect.poll(() => holographicCard.evaluate((element) => Number.parseFloat(element.ownerDocument.defaultView.getComputedStyle(element).getPropertyValue("--card-tilt-y")))).toBeGreaterThan(1); await expect(holographicCard.locator(".nebula-card-holo-primary")).toHaveCSS("opacity", "0.46"); await expect(holographicCard.locator(".nebula-card-holo-primary")).toHaveCSS("animation-name", "nebula-spectral-prism"); await expect(holographicCard.locator(".nebula-card-holo-secondary")).toHaveCSS("opacity", "0.28"); await page.mouse.move(bounds.x + bounds.width + 5, bounds.y + bounds.height * 0.5); await expect.poll(() => holographicCard.evaluate((element) => element.matches(":hover"))).toBe(true); await expect(holographicCard.locator(".nebula-card-holo-primary")).toHaveCSS("opacity", "0.46"); const tiltedHitbox = await holographicCard.boundingBox(); expect(Math.abs(tiltedHitbox.x - bounds.x)).toBeLessThan(0.1); expect(Math.abs(tiltedHitbox.y - bounds.y)).toBeLessThan(0.1); await page.mouse.move(0, 0); const tiltAfterLeave = await holographicCard.evaluate((element) => Math.abs(Number.parseFloat(element.ownerDocument.defaultView.getComputedStyle(element).getPropertyValue("--card-tilt-y")))); expect(tiltAfterLeave).toBeGreaterThan(0.2); await expect.poll(() => holographicCard.evaluate((element) => Math.abs(Number.parseFloat(element.ownerDocument.defaultView.getComputedStyle(element).getPropertyValue("--card-tilt-y"))))).toBeLessThan(0.1); await holographicCard.click(); const detailDialog = page.getByRole("dialog"); const largeCard = detailDialog.locator('.nebula-card[data-card-size="lg"][data-holo-palette="aurora"]'); await expect(detailDialog).toHaveCSS("overflow-x", "hidden"); expect((await detailDialog.boundingBox()).width).toBeGreaterThan(900); await expectArtworkFramed(largeCard); await expectFixedTitleBand(largeCard, "top"); await expectStandardCardFrame(largeCard, "lg"); await expect(largeCard.locator(".nebula-card-copy p")).toBeVisible(); await expect(largeCard.locator(".nebula-card-quantity")).toHaveCount(0); // Vérifié sur le build : le flou plein écran derrière une carte animée ruine sa fluidité. await expect(page.locator(".nds-modal-backdrop")).toHaveCSS("backdrop-filter", "none"); const ownedCopiesLabel = detailDialog.getByText("Exemplaires possédés", { exact: true }); await expect(ownedCopiesLabel).toBeVisible(); await expect(ownedCopiesLabel).toHaveCSS("white-space", "nowrap"); await expect(detailDialog.locator("dl > div").filter({ hasText: "Exemplaires possédés" }).locator("dd")).toHaveText(/^[1-9]\d*$/); expect(await largeCard.evaluate((element) => ({ holographicLayer: Number(element.ownerDocument.defaultView.getComputedStyle(element.querySelector(".nebula-card-holo-primary")).zIndex), copy: Number(element.ownerDocument.defaultView.getComputedStyle(element.querySelector(".nebula-card-copy")).zIndex) }))).toEqual({ holographicLayer: 2, copy: 3 }); expect(await detailDialog.evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(false); await page.setViewportSize({ width: 768, height: 900 }); expect(await detailDialog.evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(false); expect(await ownedCopiesLabel.evaluate((element) => { const styles = element.ownerDocument.defaultView.getComputedStyle(element); return element.getBoundingClientRect().height <= Number.parseFloat(styles.lineHeight) * 1.1; })).toBe(true); await detailDialog.getByRole("button", { name: "Fermer" }).click(); await page.emulateMedia({ reducedMotion: "reduce" }); await holographicCard.hover(); await expect(holographicCard.locator(".nebula-card-tilt-surface")).toHaveCSS("transform", "none"); await expect(holographicCard.locator(".nebula-card-holo-primary")).toHaveCSS("animation-name", "none"); await page.setViewportSize({ width: 768, height: 900 }); const overflow = await page .locator("html") .evaluate((element) => element.scrollWidth > element.clientWidth); expect(overflow).toBe(false); // Boutique : barème, recyclage et achat d'une ouverture (pas assez de poussière au départ). await expandSections(page, "Sections de Sokko TCG"); await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Boutique", exact: true }).click(); await expect(page.getByRole("heading", { name: "Boutique", exact: true })).toBeVisible(); const shopItem = page.locator('.nebula-shop-item:not([data-item="pack"])'); // Le paquet de la boutique se présente avec son dos et son prix, et reste hors de portée sans assez de poussière. const shopPackItem = page.locator('.nebula-shop-item[data-item="pack"]'); await expect(shopPackItem.getByRole("heading", { name: "Poussières d'étoiles" })).toBeVisible(); await expect(shopPackItem.locator('img[src="/static/img/cards/stardust/back.webp"]')).toBeVisible(); await expect(shopPackItem.getByRole("button", { name: "Acheter et ouvrir" })).toBeDisabled(); await expect(shopPackItem).toContainText("Il vous manque 60 poussières."); // Le solde ne met plus en avant les ouvertures achetées : la boutique est une grille d'articles illustrés. await expect(page.locator(".nebula-shop-wallet")).not.toContainText("Ouvertures achetées"); // Le solde est sous le menu, et la page se limite à son en-tête et à ses articles. await expect(page.locator(".nebula-dashboard-aside-slot .nebula-shop-wallet")).toBeVisible(); await expect(page.getByRole("heading", { name: "À échanger", exact: true })).toHaveCount(0); await expect(shopItem.getByRole("button", { name: /Utiliser/ })).toHaveCount(0); await expect(page.locator(".nebula-shop")).not.toContainText("doublon"); const shopItemImage = shopItem.locator('.nds-card-cover img[src="/static/img/cards/shop/pack.webp"]'); await expect(shopItemImage).toBeVisible(); await expect.poll(() => shopItemImage.evaluate((image) => image.complete && image.naturalWidth)).toBeGreaterThan(0); await expect(shopItem.getByRole("heading", { name: "Ouverture de paquet" })).toBeVisible(); await expect(shopItem.getByRole("button", { name: "Acheter" })).toBeDisabled(); await expect(shopItem).toContainText("Il vous manque 30 poussières."); expect(await page.locator("html").evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(false); await expect(page).toHaveURL(/#\/cards\/shop$/); // Le recyclage vit dans la Collection : plus d'entrée de menu, et l'ancienne adresse y mène. await expect(page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Recyclage", exact: true })).toHaveCount(0); await page.goto("/#/cards/recycling"); // Le bouton du menu replié nomme la section courante ; la pastille des quêtes en attente le suit. await expect(selectTrigger(page, "Sections de Sokko TCG").locator(".nebula-dashboard-menu-current")).toHaveText("Sections de Sokko TCG : Collection"); await expect(page.locator(".nebula-album-group").first()).toBeVisible(); await expect(page.locator(".nebula-recycle-box")).toHaveCount(0); expect(await page.locator("html").evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(false); // En demi-écran, le hero empile le texte et le compte au lieu d'écraser le titre. await page.setViewportSize({ width: 768, height: 900 }); expect(await page.locator(".nebula-player-hero > div").first().evaluate((element) => element.getBoundingClientRect().width)).toBeGreaterThan(400); expect(await page.locator("html").evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(false); await page.setViewportSize({ width: 1280, height: 720 }); // Échanges et dons : le type se choisit avec le groupe NDS et l'adresse de la section se recharge. await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Échanges et dons", exact: true }).click(); await expect(page.getByRole("heading", { name: "Échanges et dons", exact: true })).toBeVisible(); await page.reload(); await expect(page.getByRole("heading", { name: "Échanges et dons", exact: true })).toBeVisible(); await expect(page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Échanges et dons", exact: true })).toHaveAttribute("aria-current", "page"); }); test("administrator navigates sections, manages mythic content and previews visuals", async ({ page }) => { test.setTimeout(90_000); await page.clock.install(); const noOverflow = async () => expect(await page.locator("html").evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(false); await page.goto("/#/cards/admin"); await page.getByRole("button", { name: "Version développement", exact: true }).click(); await expect(page).toHaveURL(/#\/cards\/admin$/); const backToGame = page.getByRole("link", { name: "Retour au jeu", exact: true }); await expect(backToGame).toHaveAttribute("href", "#/cards"); expect(await backToGame.evaluate((element) => element.nextElementSibling?.querySelector("nav")?.getAttribute("aria-label"))).toBe("Sections de l’administration"); await expect(page.getByRole("navigation", { name: "Sections de Sokko TCG" })).toHaveCount(0); await expect(page.getByRole("heading", { name: "Tableau de bord Sokko TCG", exact: true })).toBeVisible(); const playersStat = page.locator(".nebula-dashboard-stat").filter({ has: page.getByText("Joueurs", { exact: true }) }); await expect(playersStat.locator("strong")).toHaveText("2"); await expect(playersStat.locator("small")).toHaveText(/^[0-9]+ actifs? sur 7 jours$/); await expect(page.locator(".nebula-admin-alerts")).toContainText("Rien à signaler."); await expect(page.locator(".nebula-dashboard-stat .nebula-dashboard-stat-label")).toHaveText(["Joueurs", "Collections actives", "Cartes différentes", /^Carte du jour n° \d+$/]); const collectionsStat = page.locator(".nebula-dashboard-stat").filter({ has: page.getByText("Collections actives", { exact: true }) }); await expect(collectionsStat.locator("strong")).toHaveText("3"); await expect(collectionsStat.locator("small")).toHaveText("sur 6 collections au total"); await expect(page.locator(".nebula-dashboard-stat").filter({ has: page.getByText("Cartes différentes", { exact: true }) }).locator("small")).toHaveText(/^dont [0-9]+ variantes? mythiques?$/); // Les joueurs sont dans la vue d'ensemble : l'ancienne adresse y redirige. const players = page.locator(".nebula-admin-player-list"); await expect(players.getByRole("columnheader")).toHaveText(["Joueur", "Paquets", "Dernier", "Cartes", "Échanges", "Réserve", "Poussière"]); const devRow = players.getByRole("row", { name: /Version développement/ }); await expect(devRow).toContainText(/[0-5] \/ 5/); await expect(devRow.locator(".nebula-stardust")).toHaveText("0"); await expect(devRow.locator(".nebula-stardust .nebula-currency-icon")).toHaveAttribute("src", "/static/icons/stardust.svg"); const navigation = page.getByRole("navigation", { name: "Sections de l’administration" }); await expect(navigation.getByRole("link")).toHaveText(["Vue d’ensemble", "Collections", "Codes cadeaux", "Boutique", "Guilde", "Atelier visuel", "Historique"]); await expect(navigation.getByRole("link", { name: "Vue d’ensemble" })).toHaveAttribute("aria-current", "page"); await page.setViewportSize({ width: 1440, height: 900 }); expect(await page.locator(".nebula-dashboard-aside").evaluate((element) => globalThis.getComputedStyle(element).position)).toBe("sticky"); // En demi-écran, le menu se replie derrière un bouton qui nomme la section courante et l'ouvre par-dessus le contenu. await page.setViewportSize({ width: 768, height: 720 }); const sectionsToggle = selectTrigger(page, "Sections de l’administration"); await expect(sectionsToggle).toHaveText("Sections de l’administration : Vue d’ensemble"); await expect(navigation).toBeHidden(); await sectionsToggle.click(); await expect(sectionsToggle).toHaveAttribute("aria-expanded", "true"); expect(await navigation.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true); for (const link of await navigation.getByRole("link").all()) await expect(link).toBeInViewport(); await page.keyboard.press("Escape"); await expect(navigation).toBeHidden(); await expect(sectionsToggle).toBeFocused(); await sectionsToggle.click(); await page.locator("#nebula-admin-title").click(); await expect(navigation).toBeHidden(); await noOverflow(); await page.goto("/#/cards/admin/players"); await expect(selectTrigger(page, "Sections de l’administration")).toHaveText("Sections de l’administration : Vue d’ensemble"); await expect(players).toBeVisible(); await page.goto("/#/cards/admin/collections"); await expect(selectTrigger(page, "Sections de l’administration")).toHaveText("Sections de l’administration : Collections"); const collectionTiles = page.locator(".nebula-admin-collection-tile"); await expect(collectionTiles).toHaveCount(6); const genesisTile = page.getByRole("link", { name: "Ouvrir la collection Genèse Astrale" }); await expect(genesisTile).toContainText("Événement"); await expect(genesisTile.locator(".nebula-admin-collection-counts > span")).toHaveText(["11cartes", "12variations", "1mythique tirable"]); await expect(genesisTile.locator(".nebula-admin-rarity-counts b")).toHaveText(["4", "4", "2", "1", "1"]); await expect(genesisTile).not.toContainText("Ouverture mythique"); await expect(genesisTile.locator(".nebula-collection-back")).toBeVisible(); const tileBackWidth = async () => Math.round((await genesisTile.locator(".nebula-admin-collection-back").boundingBox()).width); expect(await tileBackWidth()).toBe(140); await page.setViewportSize({ width: 1440, height: 900 }); expect(await tileBackWidth()).toBe(180); await page.setViewportSize({ width: 768, height: 720 }); await expect(page.locator(".nebula-admin-catalog-card")).toHaveCount(0); await noOverflow(); await page.getByRole("link", { name: "Ouvrir la collection La Nébuleuse Originelle" }).click(); await expect(page).toHaveURL(/#\/cards\/admin\/collections\/primordial-nebula$/); await expect(selectTrigger(page, "Sections de l’administration")).toHaveText("Sections de l’administration : Collections"); await expect(page.locator(".nebula-admin-collection-card")).toContainText("Primordial Nebula"); const dragonCatalogCard = page.locator(".nebula-admin-catalog-card").filter({ hasText: "Dragon du Néant Étoilé" }).filter({ hasText: "Prisme spectral — Aurore" }); await expect(dragonCatalogCard.locator('.nebula-card[data-card-size="sm"]')).toBeVisible(); await dragonCatalogCard.getByRole("button", { name: "Voir Dragon du Néant Étoilé" }).click(); const dragonDialog = page.getByRole("dialog", { name: "Dragon du Néant Étoilé" }); await expect(dragonDialog.locator('.nebula-card[data-card-size="lg"]')).toBeVisible(); await expect(dragonDialog).toContainText("Prisme spectral — Aurore"); await dragonDialog.getByRole("button", { name: "Configurer la version mythique" }).click(); await expect(dragonDialog).toHaveCount(0); const dragonMythic = page.locator("#nebula-admin-mythic-starvoid-dragon"); const mythicEditorPanel = page.locator("#nebula-admin-mythic-editor-panel"); await expect(page.locator(".nebula-admin-mythic-tile")).toHaveCount(6); await expect(dragonMythic.locator('.nebula-card[data-card-size="md"]')).toHaveCount(1); await expect(dragonMythic.locator(".nebula-admin-mythic-hint")).toHaveText("2 mythiques"); await expect(page.locator(".nebula-admin-catalog-card code")).toHaveCount(0); const dragonTileButton = dragonMythic.getByRole("button", { name: "Configurer la version mythique de Dragon du Néant Étoilé" }); await expect(dragonTileButton).toHaveAttribute("aria-pressed", "true"); await expect(mythicEditorPanel.getByRole("heading", { name: "Version mythique · Dragon du Néant Étoilé" })).toBeVisible(); await expect(mythicEditorPanel.getByRole("heading", { name: "Ouverture mythique de la carte" })).toBeVisible(); await expect(mythicEditorPanel.locator(".nebula-admin-card-opening-block .nebula-card")).toHaveAttribute("data-card-size", "md"); const trashButton = mythicEditorPanel.getByRole("button", { name: "Supprimer la variation Prisme spectral — Cosmique" }); await expect(trashButton).toHaveAttribute("data-variant", "danger"); await expect(trashButton).toHaveClass(/nds-icon-button/); await expect(trashButton).not.toHaveText(/./); await expect(mythicEditorPanel.getByRole("button", { name: "Retirer Prisme spectral — Aurore des tirages" })).toHaveClass(/ui-tooltip-anchor/); const dragonVariations = mythicEditorPanel.locator(".nebula-admin-mythic-variation"); await expect(dragonVariations).toHaveCount(2); await expect(dragonVariations.locator("strong")).toHaveText(["Aurore", "Cosmique"]); await expect(dragonVariations.locator('.nebula-card[data-card-size="sm"]')).toHaveCount(2); await expect(mythicEditorPanel.getByRole("button", { name: "Ajouter une variation" })).toBeVisible(); await dragonVariations.nth(1).getByRole("button", { name: "Prévisualiser Prisme spectral — Cosmique" }).click(); await expect(dragonVariations.nth(1)).toHaveAttribute("data-selected", "true"); await expect(mythicEditorPanel.locator(".nebula-admin-card-opening-block")).toContainText("Prisme spectral — Cosmique"); await mythicEditorPanel.getByRole("button", { name: "Fermer" }).click(); await expect(mythicEditorPanel).toHaveCount(0); await expect(dragonTileButton).toHaveAttribute("aria-pressed", "false"); await noOverflow(); await page.getByRole("navigation", { name: "Fil d’Ariane" }).getByRole("link", { name: "Collections" }).click(); await expect(page).toHaveURL(/#\/cards\/admin\/collections$/); await genesisTile.click(); await expect(page).toHaveURL(/#\/cards\/admin\/collections\/astral-genesis$/); const genesisOpening = page.getByRole("region", { name: "Ouverture mythique de la collection" }); await expectOptions(page, genesisOpening, "Forme de particules", ["Étincelles (défaut)", "Flocons de neige"]); await expectOptions(page, genesisOpening, "Palette de particules", ["Violet épique", "Or légendaire", "Arc-en-ciel (défaut)", "Comme la palette holo"]); await page.setViewportSize({ width: 1440, height: 900 }); // En grand, taux de tirage et ouverture mythique côte à côte (50:50), de même hauteur, sans défilement du tableau. const openingBox = await genesisOpening.boundingBox(); const ratesBox = await page.getByRole("region", { name: "Taux de tirage" }).boundingBox(); expect(Math.abs(openingBox.width - ratesBox.width)).toBeLessThanOrEqual(1); expect(Math.abs(openingBox.height - ratesBox.height)).toBeLessThanOrEqual(1); expect(await page.locator(".nebula-admin-drop-scroll").evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true); expect(openingBox.x).toBeGreaterThan(ratesBox.x + ratesBox.width); expect(Math.abs(openingBox.y - ratesBox.y)).toBeLessThanOrEqual(1); await page.setViewportSize({ width: 900, height: 900 }); const [stackedOpening, stackedRates] = await Promise.all([genesisOpening.boundingBox(), page.getByRole("region", { name: "Taux de tirage" }).boundingBox()]); expect(stackedOpening.y).toBeGreaterThan(stackedRates.y + stackedRates.height); expect(Math.abs(stackedOpening.width - stackedRates.width)).toBeLessThanOrEqual(1); await page.setViewportSize({ width: 1440, height: 900 }); await chooseOption(genesisOpening, "Forme de particules", "Flocons de neige"); await expect(selectTrigger(genesisOpening, "Forme de particules")).toHaveText("Flocons de neige"); await expect(genesisOpening).toHaveCSS("overflow", "visible"); // Les deux menus côte à côte, à la même hauteur. const [shapeBox, paletteBox] = await Promise.all([selectTrigger(genesisOpening, "Forme de particules").boundingBox(), selectTrigger(genesisOpening, "Palette de particules").boundingBox()]); expect(Math.abs(shapeBox.y - paletteBox.y)).toBeLessThanOrEqual(1); expect(shapeBox.x + shapeBox.width).toBeLessThan(paletteBox.x); await genesisOpening.getByRole("button", { name: "Révéler la carte mythique de la collection" }).click(); await expect(genesisOpening.locator(".nebula-card-reveal")).toHaveAttribute("data-particle-shape", "snowflakes"); await expect(genesisOpening.locator(".nebula-card-particles i").first()).toBeAttached(); await noOverflow(); const mythicPullEditions = page.locator(".nebula-admin-catalog-card").filter({ hasText: "La Pioche Mythique" }); await expect(mythicPullEditions).toHaveCount(2); const pullItem = page.locator("#nebula-admin-mythic-mythic-card-pull"); await pullItem.getByRole("button", { name: "Configurer la version mythique de La Pioche Mythique" }).click(); const editor = page.locator("#nebula-admin-mythic-editor-panel .nebula-admin-mythic-editor"); const variations = editor.locator(".nebula-admin-mythic-variation"); await expect(variations).toHaveCount(1); await expect(variations.first().locator("strong")).toHaveText("Solaire"); await expect(variations.first().locator(".nebula-admin-mythic-variation-specs dd")).toHaveText(["Standard", "Prisme spectral", "À venir"]); await expect(editor.getByRole("button", { name: "Enregistrer" })).toHaveCount(0); const cardOpening = editor.getByRole("group", { name: "Ouverture mythique de la carte" }); await expectOptions(page, cardOpening, "Forme de particules", ["Étincelles", "Flocons de neige (hérité de la collection)"]); await expect(selectTrigger(cardOpening, "Forme de particules")).toHaveText("Flocons de neige (hérité de la collection)"); await selectTrigger(cardOpening, "Palette de particules").click(); await expect(cardOpening.getByRole("option", { name: /Arc-en-ciel/ })).toHaveText(["Arc-en-ciel (défaut)"]); await page.keyboard.press("Escape"); await editor.getByRole("button", { name: "Ajouter une variation" }).click(); await expect(variations).toHaveCount(2); await expect(variations.nth(1).getByRole("button", { name: "Palette holographique : Arc-en-ciel" })).toBeVisible(); await expect(selectTrigger(variations.nth(1), "Particules")).toBeDisabled(); await expect(variations.nth(1)).toHaveAttribute("data-selected", "true"); await expect(editor.getByRole("button", { name: "Ajouter une variation" })).toHaveCount(0); const draftActions = variations.nth(1).locator(".nebula-admin-mythic-variation-actions .nds-icon-button"); await expect(draftActions).toHaveCount(2); await expect(draftActions.first()).toHaveAccessibleName("Valider la nouvelle variation"); await expect(draftActions.first()).toHaveAttribute("data-variant", "primary"); await expect(draftActions.nth(1)).toHaveAccessibleName("Annuler la nouvelle variation"); await variations.nth(1).getByLabel("Palette holographique").click(); await variations.nth(1).getByRole("button", { name: "Solaire", exact: true }).click(); await expect(variations.nth(1).getByRole("status")).toHaveText("Cette combinaison existe déjà."); await expect(draftActions.first()).toBeDisabled(); await draftActions.nth(1).click(); await expect(variations).toHaveCount(1); await editor.getByRole("button", { name: "Ajouter une variation" }).click(); await expect(variations).toHaveCount(2); const variationColumns = () => editor.locator(".nebula-admin-mythic-variations").evaluate((element) => globalThis.getComputedStyle(element).gridTemplateColumns.trim().split(/\s+/).length); await page.setViewportSize({ width: 2560, height: 1080 }); expect(await variationColumns()).toBe(3); const copyBesideCard = async () => { const [cardBox, copyBox] = await Promise.all([variations.first().locator(".nebula-card").boundingBox(), variations.first().locator(".nebula-admin-mythic-variation-copy").boundingBox()]); return copyBox.x >= cardBox.x + cardBox.width - 1; }; expect(await copyBesideCard()).toBe(true); await page.setViewportSize({ width: 1440, height: 900 }); expect(await variationColumns()).toBe(3); expect(await copyBesideCard()).toBe(false); await page.setViewportSize({ width: 768, height: 720 }); expect(await variationColumns()).toBe(3); // En demi-écran comme en grand, le menu de palette de la dernière colonne se recale au lieu d'être coupé. await page.setViewportSize({ width: 1440, height: 900 }); await variations.nth(1).scrollIntoViewIfNeeded(); await variations.nth(1).getByRole("button", { name: "Palette holographique : Arc-en-ciel" }).click(); await expectOpenMenuVisible(page, ".nebula-admin-palette-menu.is-open"); await page.keyboard.press("Escape"); await page.evaluate(() => globalThis.scrollTo(0, globalThis.document.documentElement.scrollHeight)); await variations.nth(1).getByRole("button", { name: "Palette holographique : Arc-en-ciel" }).click(); await expectOpenMenuVisible(page, ".nebula-admin-palette-menu.is-open"); await page.keyboard.press("Escape"); await page.setViewportSize({ width: 768, height: 720 }); await variations.nth(1).getByRole("button", { name: "Palette holographique : Arc-en-ciel" }).click(); const lastPaletteOption = variations.nth(1).getByRole("button", { name: "Ténèbres", exact: true }); await expect(lastPaletteOption).toBeVisible(); await lastPaletteOption.scrollIntoViewIfNeeded(); // L'événement de défilement part à la frame suivante : le menu doit rester défilé après son traitement. // Le menu se recale après le défilement : on attend sa position stable, et un vrai recouvrement échoue à l'expiration. await expect.poll(() => lastPaletteOption.evaluate((element) => { const box = element.getBoundingClientRect(); return element.contains(element.ownerDocument.elementFromPoint(box.left + box.width / 2, box.bottom - 4)); })).toBe(true); await page.keyboard.press("Escape"); await chooseOption(cardOpening, "Palette de particules", "Comme la palette holo"); await expect(selectTrigger(cardOpening, "Palette de particules")).toHaveText("Comme la palette holo"); await expect(variations).toHaveCount(2); await editor.getByRole("button", { name: "Révéler la variation mythique" }).click(); const editorSurface = editor.locator(".nebula-card-reveal"); await expect(editorSurface).toHaveAttribute("data-particle-shape", "snowflakes"); await expect(editorSurface).toHaveAttribute("data-particle-palette", "match-holo"); await expect(editorSurface).toHaveCSS("--opening-aura", "#ff0000"); await editor.getByRole("button", { name: "Valider la nouvelle variation" }).click(); await expect(editor.locator(".nebula-admin-mythic-variation[data-new]")).toHaveCount(0); await expect(editor.locator(".nebula-admin-mythic-variation")).toHaveCount(2); await expect(editor.locator(".nebula-admin-mythic-variation strong")).toHaveText(["Arc-en-ciel", "Solaire"]); await expect(editor.getByRole("button", { name: "Ajouter une variation" })).toBeVisible(); await expect(selectTrigger(editor.getByRole("group", { name: "Ouverture mythique de la carte" }), "Palette de particules")).toHaveText("Comme la palette holo"); await expect(mythicPullEditions).toHaveCount(3); await noOverflow(); const config = await page.evaluate(() => globalThis.fetch("/api/cards/config").then((response) => response.json())); expect(config.catalog.editions.some((edition) => edition.id === "mythic-card-pull-spectral-prism-rainbow")).toBe(true); expect(config.catalog.mythicOpeningSettings).toEqual(expect.arrayContaining([ { scope: "card", targetId: "mythic-card-pull", particleShapeId: null, particlePaletteId: "match-holo" }, { scope: "collection", targetId: "astral-genesis", particleShapeId: "snowflakes", particlePaletteId: null } ])); await editor.getByRole("button", { name: "Supprimer la variation Prisme spectral — Arc-en-ciel" }).click(); const removalDialog = page.getByRole("dialog", { name: "Supprimer Prisme spectral — Arc-en-ciel ?" }); await removalDialog.getByRole("button", { name: "Annuler" }).click(); await expect(editor.locator(".nebula-admin-mythic-variation")).toHaveCount(2); await editor.getByRole("button", { name: "Supprimer la variation Prisme spectral — Arc-en-ciel" }).click(); await removalDialog.getByRole("button", { name: "Supprimer" }).click(); await expect(editor.locator(".nebula-admin-mythic-variation")).toHaveCount(1); await chooseOption(editor.getByRole("group", { name: "Ouverture mythique de la carte" }), "Palette de particules", INHERITED); await expect(selectTrigger(editor.getByRole("group", { name: "Ouverture mythique de la carte" }), "Palette de particules")).toHaveText(INHERITED); await chooseOption(genesisOpening, "Forme de particules", INHERITED); await expect(selectTrigger(genesisOpening, "Forme de particules")).toHaveText(INHERITED); await expect(mythicPullEditions).toHaveCount(2); await page.goto("/#/cards/admin/catalog/inconnue"); await expect(page.getByText("Cette collection n’existe pas.", { exact: true })).toBeVisible(); await expandSections(page, "Sections de l’administration"); await navigation.getByRole("link", { name: "Atelier visuel" }).click(); await expect(page).toHaveURL(/#\/cards\/admin\/visual-lab$/); const openingEffects = page.locator(".nebula-admin-opening-effect-card"); await expect(openingEffects).toHaveCount(4); await expect(openingEffects.locator(".eyebrow")).toHaveText(["Effet de rareté", "Effet de rareté", "Effet de rareté", "Effet de rareté"]); await expect(openingEffects.locator("h4")).toHaveText(["Mythique", "Rare", "Épique", "Légendaire"]); await expect(openingEffects.first().locator(".nebula-admin-style-preview > span")).toHaveText(/^Aperçu · .+ — Prisme spectral — /); const holoSectionBox = await page.getByRole("heading", { name: /Effets holographiques mythiques/ }).boundingBox(); const openingSectionBox = await page.getByRole("heading", { name: /Effets d’ouverture/ }).boundingBox(); expect(holoSectionBox.y).toBeLessThan(openingSectionBox.y); const openingColumns = () => page.locator('[data-opening-group="rarities"]').evaluate((element) => element.ownerDocument.defaultView.getComputedStyle(element).gridTemplateColumns.trim().split(/\s+/).length); expect(await openingColumns()).toBe(2); await noOverflow(); await page.setViewportSize({ width: 1440, height: 900 }); expect(await openingColumns()).toBe(3); const mythicOpeningCard = openingEffects.filter({ has: page.getByRole("heading", { name: "Mythique", exact: true }) }); const legendaryOpeningCard = openingEffects.filter({ has: page.getByRole("heading", { name: "Légendaire", exact: true }) }); const [mythicBox, legendaryBox, gridBox] = await Promise.all([mythicOpeningCard.boundingBox(), legendaryOpeningCard.boundingBox(), page.locator('[data-opening-group="rarities"]').boundingBox()]); expect(mythicBox.y + mythicBox.height).toBeLessThan(legendaryBox.y + 1); expect(Math.round(mythicBox.width)).toBe(760); expect(Math.abs((mythicBox.x - gridBox.x) - (gridBox.x + gridBox.width - mythicBox.x - mythicBox.width))).toBeLessThanOrEqual(1); const effectStyles = page.locator(".nebula-admin-effect-grid .nebula-admin-style-card"); await expect(effectStyles.locator("h4")).toHaveText(["Prisme spectral", "Reflet diffractif", "Écrin prismatique"]); // L'Écrin prismatique affiche la version à zones vides de chaque format : sa sous-couche se voit à travers. const backdropStyle = effectStyles.filter({ has: page.getByRole("heading", { name: "Écrin prismatique", exact: true }) }); const backdropCard = backdropStyle.locator('.nebula-card[data-holo-effect="prismatic-backdrop"]'); await expect(backdropCard.locator('.nebula-card-art img[src$="/mythic_card_pull__cutout.webp"]')).toBeVisible(); await expect(backdropCard.locator(".nebula-card-art .nebula-card-holo-underlay")).toHaveCSS("display", "block"); await chooseOption(backdropStyle, "Format", "Pleine illustration"); await expect(backdropCard.locator('.nebula-card-art img[src$="/mythic_card_pull__full__cutout.webp"]')).toBeVisible(); await chooseOption(backdropStyle, "Format", "Standard"); await expect(effectStyles.filter({ has: page.getByRole("heading", { name: "Prisme spectral", exact: true }) }).locator(".nebula-card-holo-underlay")).toHaveCount(0); const spectralStyle = effectStyles.filter({ has: page.getByRole("heading", { name: "Prisme spectral", exact: true }) }); // Les aperçus holographiques gardent le vrai format `lg`, 300 x 420 px. const holoPreviewBox = await spectralStyle.locator(".nebula-admin-style-preview > .nebula-card").boundingBox(); expect([Math.round(holoPreviewBox.width), Math.round(holoPreviewBox.height)]).toEqual([300, 420]); // Pleine illustration : l'image remplit la carte, la description disparaît et le nom reste, avec son effet métallique. await chooseOption(spectralStyle, "Format", "Pleine illustration"); const fullArtCard = spectralStyle.locator('.nebula-card[data-card-layout="full-art"][data-holo-effect="spectral-prism"]'); await expect(fullArtCard.locator('.nebula-card-art img[src$="/astral-genesis/legendary/mythic_card_pull__full.webp"]')).toBeVisible(); await expect(fullArtCard.locator(".nebula-card-copy")).toHaveCount(0); await expect(fullArtCard.locator("h3")).toBeVisible(); await expect(fullArtCard.locator("h3 > span")).toHaveCSS("color", "rgba(0, 0, 0, 0)"); // Une ombre de texte se peindrait par-dessus le dégradé et ternirait le nom. await expect(fullArtCard.locator("h3 > span")).toHaveCSS("text-shadow", "none"); const fullArtBounds = await fullArtCard.evaluate((element) => { const face = element.querySelector(".nebula-card-face").getBoundingClientRect(); const art = element.querySelector(".nebula-card-art").getBoundingClientRect(); return { widthGap: face.width - art.width, heightGap: face.height - art.height }; }); expect(fullArtBounds.widthGap).toBeLessThanOrEqual(5); expect(fullArtBounds.heightGap).toBeLessThanOrEqual(5); await chooseOption(spectralStyle, "Format", "Standard"); await expect(spectralStyle).toHaveCount(1); await expect(spectralStyle.locator('.nebula-card[data-card-size="lg"]')).toHaveCount(1); await expect(spectralStyle.locator('.nebula-card-art img[src$="/astral-genesis/legendary/mythic_card_pull.webp"]')).toHaveCount(1); await expect(spectralStyle.getByRole("heading", { name: "Prisme spectral", exact: true })).toBeVisible(); await expect(selectTrigger(spectralStyle, "Particules au survol")).toBeDisabled(); await expect(selectTrigger(spectralStyle, "Particules au survol")).toHaveText("À venir"); const paletteTrigger = spectralStyle.getByRole("button", { name: "Palette de couleurs : Arc-en-ciel" }); const paletteTriggerLabel = paletteTrigger.getByText("Arc-en-ciel", { exact: true }); await expect(paletteTriggerLabel).toBeVisible(); expect(await paletteTriggerLabel.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true); await expect(paletteTrigger.locator('.nebula-admin-palette[data-compact="true"] i').first()).toHaveCSS("width", "12px"); await paletteTrigger.click(); await expect(spectralStyle).toHaveCSS("overflow", "visible"); const solarPaletteOption = spectralStyle.getByRole("button", { name: "Solaire", exact: true }); await expect(solarPaletteOption.locator('.nebula-admin-palette[data-compact="true"] i')).toHaveCount(7); await solarPaletteOption.click(); await expect(spectralStyle.getByRole("button", { name: "Palette de couleurs : Solaire" })).toBeVisible(); await expect(spectralStyle.locator('.nebula-card[data-holo-palette="solar"], .nebula-card-face[data-holo-palette="solar"]').first()).toBeVisible(); // Reflet diffractif : mêmes réglages que le prisme, mais tout découle du tilt, sans animation automatique. const diffractionStyle = effectStyles.filter({ has: page.getByRole("heading", { name: "Reflet diffractif", exact: true }) }); const diffractionCard = diffractionStyle.locator(".nebula-admin-style-preview > .nebula-card"); const diffractionLayer = diffractionCard.locator(".nebula-card-holo-primary"); await chooseOption(diffractionStyle, "Format", "Pleine illustration"); await expect(diffractionCard).toHaveAttribute("data-card-layout", "full-art"); await chooseOption(diffractionStyle, "Format", "Standard"); await diffractionStyle.getByRole("button", { name: "Palette de couleurs : Arc-en-ciel" }).click(); await diffractionStyle.getByRole("button", { name: "Solaire", exact: true }).click(); await expect(diffractionCard).toHaveAttribute("data-holo-palette", "solar"); await expect(selectTrigger(diffractionStyle, "Particules au survol")).toHaveText("À venir"); await diffractionCard.scrollIntoViewIfNeeded(); await expect(diffractionLayer).toHaveCSS("opacity", "0.05"); const diffractionBox = await diffractionCard.boundingBox(); const tiltTo = async (ratioX, ratioY) => { await page.mouse.move(diffractionBox.x + diffractionBox.width * ratioX, diffractionBox.y + diffractionBox.height * ratioY); await expect.poll(() => diffractionCard.evaluate((element, expected) => Math.abs(Number.parseFloat(element.style.getPropertyValue("--card-pointer-x")) - expected), ratioX * 100)).toBeLessThan(1); return diffractionLayer.evaluate((element) => { const style = element.ownerDocument.defaultView.getComputedStyle(element); return { opacity: Number(style.opacity), position: style.backgroundPosition, animation: style.animationName }; }); }; const flat = await tiltTo(0.5, 0.5); const tilted = await tiltTo(0.95, 0.9); expect(flat.animation).toBe("none"); expect(tilted.animation).toBe("none"); expect(tilted.opacity).toBeGreaterThan(flat.opacity + 0.2); expect(tilted.position).not.toBe(flat.position); await page.mouse.move(0, 0); await expect.poll(() => diffractionLayer.evaluate((element) => Number(element.ownerDocument.defaultView.getComputedStyle(element).opacity))).toBeLessThan(0.07); const rarePreview = openingEffects.filter({ has: page.locator('[data-opening-effect="rare-opening"]') }); const rareCard = rarePreview.getByRole("button", { name: "Révéler la carte Rare", exact: true }); const rareSurface = rarePreview.locator(".nebula-card-reveal"); await rareCard.focus(); await holdRevealTimers(page); await rareCard.press("Enter"); await expect(rareSurface).toHaveAttribute("data-reveal-phase", "aura"); await expect(rareSurface).not.toHaveAttribute("disabled", ""); await expect(rareSurface).toHaveCSS("opacity", "1"); await expect(rareSurface).toHaveCSS("--card-rarity", "#3b82f6"); await expect(rareSurface).toHaveCSS("--opening-aura", "#3b82f6"); expect(await rareSurface.evaluate((element) => element.ownerDocument.defaultView.getComputedStyle(element, "::after").animationName)).toBe("nebula-opening-aura"); await expect(rareSurface.locator(".nebula-card-particles i")).toHaveCount(0); await page.clock.resume(); await expect(rarePreview.getByRole("button", { name: "Remettre la carte Rare face cachée", exact: true })).toHaveAttribute("data-reveal-phase", "revealed"); await rarePreview.getByRole("button", { name: "Remettre la carte Rare face cachée", exact: true }).click(); await expect(rarePreview.getByRole("button", { name: "Révéler la carte Rare", exact: true })).toHaveAttribute("data-reveal-phase", "concealed"); const epicPreview = openingEffects.filter({ has: page.locator('[data-opening-effect="epic-opening"]') }); const epicCard = epicPreview.getByRole("button", { name: "Révéler la carte Épique", exact: true }); const epicSurface = epicPreview.locator(".nebula-card-reveal"); await holdRevealTimers(page); await epicCard.click(); await expect(epicSurface).toHaveAttribute("data-reveal-phase", "aura"); await expect(epicSurface).toHaveCSS("--card-rarity", "#d946ef"); await expect(epicSurface).toHaveCSS("--opening-aura", "#d946ef"); await page.clock.runFor(350); await expect(epicSurface.locator(".nebula-card-particles i")).toHaveCount(18); await expect(epicSurface.locator(".nebula-card-particles i").first()).toHaveCSS("animation-name", "nebula-particle"); await page.clock.resume(); await expect(epicPreview.getByRole("button", { name: "Remettre la carte Épique face cachée", exact: true })).toHaveAttribute("data-reveal-phase", "revealed"); const legendaryPreview = openingEffects.filter({ has: page.locator('[data-opening-effect="legendary-opening"]') }); const legendaryCard = legendaryPreview.getByRole("button", { name: "Révéler la carte Légendaire", exact: true }); const legendarySurface = legendaryPreview.locator(".nebula-card-reveal"); await holdRevealTimers(page); await legendaryCard.click(); await expect(legendarySurface).toHaveAttribute("data-reveal-phase", "aura"); await expect(legendarySurface).toHaveCSS("--opening-aura", "#f6c453"); await page.clock.runFor(450); await expect(legendarySurface.locator(".nebula-card-particles i")).toHaveCount(32); await page.clock.resume(); await expect(legendaryPreview.getByRole("button", { name: "Remettre la carte Légendaire face cachée", exact: true })).toHaveAttribute("data-reveal-phase", "revealed"); await legendaryPreview.getByRole("button", { name: "Remettre la carte Légendaire face cachée", exact: true }).click(); await expect(legendaryPreview.getByRole("button", { name: "Révéler la carte Légendaire", exact: true })).toHaveAttribute("data-reveal-phase", "concealed"); await page.emulateMedia({ reducedMotion: "reduce" }); await legendaryPreview.getByRole("button", { name: "Révéler la carte Légendaire", exact: true }).click(); await expect(legendaryPreview.getByRole("button", { name: "Remettre la carte Légendaire face cachée", exact: true })).toHaveAttribute("data-reveal-phase", "revealed"); await expect(legendarySurface.locator(".nebula-card-particles")).toHaveCSS("display", "none"); await page.emulateMedia({ reducedMotion: "no-preference" }); const legendaryBurstVisual = await legendarySurface.locator(".nebula-card-particles").evaluate((element) => { const styles = element.ownerDocument.defaultView; const normalizeColors = (value) => value.replace(/(?:rgba?|color)\([^)]*\)/g, ""); const before = styles.getComputedStyle(element, "::before"); const after = styles.getComputedStyle(element, "::after"); const particle = styles.getComputedStyle(element.querySelector("i")); return { geometry: { ring: { width: before.width, height: before.height, border: before.borderWidth, radius: before.borderRadius, shadow: normalizeColors(before.boxShadow), animation: before.animationName, duration: before.animationDuration, easing: before.animationTimingFunction }, rays: { width: after.width, height: after.height, radius: after.borderRadius, filter: normalizeColors(after.filter), animation: after.animationName, duration: after.animationDuration, easing: after.animationTimingFunction }, particle: { width: particle.width, height: particle.height, radius: particle.borderRadius, clipPath: particle.clipPath, animation: particle.animationName, duration: particle.animationDuration, easing: particle.animationTimingFunction, x: particle.getPropertyValue("--x"), y: particle.getPropertyValue("--y") }, particleSizes: [...element.querySelectorAll("i")].map((item) => `${styles.getComputedStyle(item).width}x${styles.getComputedStyle(item).height}`).join(" ") }, paint: { ringBackground: before.backgroundImage, ringMask: before.maskImage || before.webkitMaskImage, rayBackground: after.backgroundImage, rayMask: after.maskImage || after.webkitMaskImage } }; }); expect(legendaryBurstVisual.geometry.ring.width).toBe("92px"); expect(legendaryBurstVisual.geometry.ring.height).toBe("92px"); expect(legendaryBurstVisual.geometry.ring.border).toBe("6px"); expect(legendaryBurstVisual.paint.ringBackground).toBe("none"); expect(legendaryBurstVisual.paint.ringMask).toBe("none"); expect(legendaryBurstVisual.geometry.rays.width).toBe("260px"); expect(legendaryBurstVisual.geometry.rays.height).toBe("260px"); expect(legendaryBurstVisual.paint.rayBackground).toContain("repeating-conic-gradient"); expect(legendaryBurstVisual.paint.rayMask).toContain("radial-gradient"); expect(legendaryBurstVisual.paint.rayMask).not.toContain("repeating-conic-gradient"); expect(legendaryBurstVisual.geometry.rays.filter).toContain("drop-shadow"); expect(legendaryBurstVisual.geometry.rays.animation).toBe("nebula-particle-flash"); expect(legendaryBurstVisual.geometry.rays.duration).toBe("0.68s"); await expect(legendarySurface.locator(".nebula-card-particle-ring-glow")).toHaveCount(0); const legendaryAuraBase = await legendarySurface.evaluate((element) => { const style = globalThis.getComputedStyle(element, "::after"); const normalizeColors = (value) => value.replace(/(?:rgba?|color)\([^)]*\)/g, ""); return { inset: style.inset, border: style.borderWidth, radius: style.borderRadius, background: normalizeColors(style.backgroundImage), shadow: normalizeColors(style.boxShadow), filter: normalizeColors(style.filter), mask: style.maskImage || style.webkitMaskImage }; }); await expect(legendarySurface).not.toHaveAttribute("data-aura-palette"); await expect(legendarySurface.locator(".nebula-card-glow-palette, .nebula-card-opening-glow-palette")).toHaveCount(0); const mythicPreview = openingEffects.filter({ has: page.locator('[data-opening-effect="mythic-default-opening"]') }); const mythicSurface = mythicPreview.locator(".nebula-card-reveal"); await expect(mythicPreview).not.toContainText("Effet personnalisé"); await expect(mythicSurface).toHaveCSS("--card-rarity", "#67e8f9"); await expect(mythicSurface).toHaveAttribute("data-particle-shape", "sparks"); await expect(mythicSurface).toHaveAttribute("data-particle-palette", "rainbow"); await expect(mythicPreview.getByRole("button", { name: "Forme de particules : Étincelles" })).toBeVisible(); const particlePaletteTrigger = mythicPreview.getByRole("button", { name: "Palette de particules : Arc-en-ciel" }); await expect(particlePaletteTrigger.locator('.nebula-admin-palette[data-compact="true"] i')).toHaveCount(7); await particlePaletteTrigger.click(); await mythicPreview.getByRole("button", { name: "Violet épique", exact: true }).click(); await expect(mythicSurface).toHaveAttribute("data-particle-palette", "epic-violet"); await expect(mythicSurface).toHaveCSS("--opening-aura-secondary", "#f0abfc"); expect(await mythicSurface.evaluate((element) => element.style.getPropertyValue("--opening-aura-gradient"))).toBe("conic-gradient(from 15deg, #ffffff, #f0abfc, #d946ef, #a21caf, #ffffff)"); const violetRayVisual = await mythicSurface.evaluate((element) => { const particles = element.ownerDocument.createElement("span"); particles.className = "nebula-card-particles"; element.append(particles); const style = globalThis.getComputedStyle(particles, "::after"); const visual = { background: style.backgroundImage, mask: style.maskImage || style.webkitMaskImage }; particles.remove(); return visual; }); await mythicPreview.getByRole("button", { name: "Palette de particules : Violet épique" }).click(); await mythicPreview.getByRole("button", { name: "Arc-en-ciel", exact: true }).click(); const rainbowRayVisual = await mythicSurface.evaluate((element) => { const particles = element.ownerDocument.createElement("span"); particles.className = "nebula-card-particles"; element.append(particles); const style = globalThis.getComputedStyle(particles, "::after"); const visual = { background: style.backgroundImage, mask: style.maskImage || style.webkitMaskImage }; particles.remove(); return visual; }); expect(violetRayVisual.mask).toBe(rainbowRayVisual.mask); expect(rainbowRayVisual.mask).toContain("repeating-conic-gradient"); expect(rainbowRayVisual.mask).toContain("18deg"); expect(violetRayVisual.background).toContain("rgb(217, 70, 239)"); expect(rainbowRayVisual.background).toContain("rgb(52, 199, 89)"); const mythicCard = mythicPreview.getByRole("button", { name: "Révéler la carte Mythique", exact: true }); await mythicPreview.getByRole("button", { name: "Forme de particules : Étincelles" }).click(); await expect(mythicPreview.getByRole("button", { name: "Flocons de neige", exact: true })).toBeVisible(); await mythicPreview.getByRole("button", { name: "Flocons de neige", exact: true }).click(); await expect(mythicSurface).toHaveAttribute("data-particle-shape", "snowflakes"); await mythicCard.click(); await expect(mythicSurface.locator(".nebula-card-particles i")).toHaveCount(48); const snowflakeVisual = await mythicSurface.locator(".nebula-card-particles").evaluate((element) => { const styles = element.ownerDocument.defaultView; const before = styles.getComputedStyle(element, "::before"); const after = styles.getComputedStyle(element, "::after"); const particle = element.querySelectorAll("i"); const flake = styles.getComputedStyle(particle[0], "::before"); return { ring: { width: before.width, border: before.borderWidth, mask: before.maskImage || before.webkitMaskImage }, rays: { width: after.width, animation: after.animationName }, sizes: [particle[0], particle[2]].map((item) => styles.getComputedStyle(item).width), particleAnimation: styles.getComputedStyle(particle[0]).animationName, flakeMask: flake.maskImage || flake.webkitMaskImage, clipPath: styles.getComputedStyle(particle[0]).clipPath }; }); expect(snowflakeVisual.ring).toEqual({ width: "92px", border: "6px", mask: expect.stringContaining("radial-gradient") }); expect(snowflakeVisual.rays).toEqual({ width: "260px", animation: "nebula-particle-flash" }); expect(snowflakeVisual.sizes).toEqual(["24px", "14px"]); expect(snowflakeVisual.particleAnimation).toBe("nebula-particle-snowflake"); expect(snowflakeVisual.flakeMask).toContain("svg"); expect(snowflakeVisual.clipPath).toBe("none"); await expect(mythicPreview.getByRole("button", { name: "Remettre la carte Mythique face cachée", exact: true })).toHaveAttribute("data-reveal-phase", "revealed"); await mythicPreview.getByRole("button", { name: "Remettre la carte Mythique face cachée", exact: true }).click(); await expect(mythicCard).toHaveAttribute("data-reveal-phase", "concealed"); await mythicPreview.getByRole("button", { name: "Forme de particules : Flocons de neige" }).click(); await mythicPreview.getByRole("button", { name: "Étincelles", exact: true }).click(); await expect(mythicSurface).toHaveAttribute("data-particle-shape", "sparks"); await holdRevealTimers(page); await mythicCard.click(); await expect(mythicSurface).toHaveAttribute("data-reveal-phase", "aura"); await expect(mythicSurface).toHaveCSS("--opening-aura", "#ff3b30"); await expect(mythicSurface).toHaveCSS("--opening-aura-duration", "450ms"); await expect(mythicSurface).toHaveCSS("--opening-particle-duration", "1200ms"); await expect(mythicSurface).toHaveCSS("--opening-aura-secondary", "#ff9500"); await expect(mythicSurface).toHaveCSS("--opening-aura-tertiary", "#ffcc00"); expect(await mythicSurface.evaluate((element) => element.style.getPropertyValue("--opening-aura-gradient"))).toBe("conic-gradient(from 15deg, #ff3b30, #ff9500, #ffcc00, #34c759, #00c7be, #3b82f6, #d946ef, #ff3b30)"); const mythicAuraBase = await mythicSurface.evaluate((element) => { const style = globalThis.getComputedStyle(element, "::after"); const normalizeColors = (value) => value.replace(/(?:rgba?|color)\([^)]*\)/g, ""); return { inset: style.inset, border: style.borderWidth, radius: style.borderRadius, background: normalizeColors(style.backgroundImage), shadow: normalizeColors(style.boxShadow), filter: normalizeColors(style.filter), mask: style.maskImage || style.webkitMaskImage }; }); const { shadow: mythicAuraShadow, ...mythicAuraBaseShape } = mythicAuraBase; const { shadow: legendaryAuraShadow, ...legendaryAuraBaseShape } = legendaryAuraBase; expect(mythicAuraBaseShape).toEqual(legendaryAuraBaseShape); expect(legendaryAuraShadow).toContain("28px"); expect(mythicAuraShadow).toBe("none"); await expect(mythicSurface).toHaveAttribute("data-aura-palette", "true"); await expect(mythicSurface.locator(".nebula-card-tilt-surface")).toHaveCSS("filter", "none"); const crownGlowVisual = await mythicSurface.locator(":scope > .nebula-card-opening-glow-palette").evaluate((element) => { const style = globalThis.getComputedStyle(element); const inner = element.firstElementChild; const near = globalThis.getComputedStyle(inner, "::before"); const far = globalThis.getComputedStyle(inner, "::after"); return { display: style.display, animation: style.animationName, duration: style.animationDuration, mask: style.maskImage || style.webkitMaskImage, nearBackground: near.backgroundImage, nearFilter: near.filter, nearOpacity: near.opacity, farFilter: far.filter, farOpacity: far.opacity }; }); expect(crownGlowVisual).toMatchObject({ display: "block", animation: "nebula-opening-aura", duration: "0.45s", nearOpacity: "0.78", farOpacity: "0.48" }); expect(crownGlowVisual.mask).toContain("svg"); expect(crownGlowVisual.nearBackground).toContain("conic-gradient"); expect(crownGlowVisual.nearFilter).toContain("blur(14px)"); expect(crownGlowVisual.farFilter).toContain("blur(32px)"); const cardGlowVisual = await mythicSurface.locator(".nebula-card-glow-palette").evaluateAll((elements) => elements.map((element) => { const style = globalThis.getComputedStyle(element); return { side: element.dataset.side, display: style.display, backface: style.backfaceVisibility, background: globalThis.getComputedStyle(element, "::before").backgroundImage, animation: style.animationName }; })); expect(cardGlowVisual.map(({ side }) => side)).toEqual(["back", "face"]); for (const glow of cardGlowVisual) expect(glow).toMatchObject({ display: "block", backface: "hidden", animation: "nebula-opening-card-glow-palette-in" }); for (const glow of cardGlowVisual) expect(glow.background).toContain("conic-gradient"); // La couronne et la lueur ne colorent que le contour : sans cette exclusion, qu'un minifieur peut retirer, l'aura remplit toute la zone. const maskComposites = await mythicSurface.locator(":scope > .nebula-card-opening-crown-palette, :scope > .nebula-card-opening-glow-palette").evaluateAll((elements) => elements.map((element) => globalThis.getComputedStyle(element).maskComposite)); expect(maskComposites).toHaveLength(2); for (const composite of maskComposites) expect(composite).toMatch(/^exclude\b/); const mythicAuraPalettes = mythicSurface.locator(":scope > .nebula-card-opening-aura-palette, :scope > .nebula-card-opening-crown-palette"); await expect(mythicAuraPalettes).toHaveCount(2); const auraPaletteVisual = await mythicSurface.locator(":scope > .nebula-card-opening-aura-palette").evaluate((element) => { const style = globalThis.getComputedStyle(element); return { background: style.backgroundImage, mask: style.maskImage || style.webkitMaskImage, animation: style.animationName, duration: style.animationDuration, filter: style.filter, zIndex: style.zIndex }; }); const crownPaletteVisual = await mythicSurface.locator(":scope > .nebula-card-opening-crown-palette").evaluate((element) => { const style = globalThis.getComputedStyle(element); return { background: style.backgroundImage, mask: style.maskImage || style.webkitMaskImage, animation: style.animationName, duration: style.animationDuration, filter: style.filter, zIndex: style.zIndex }; }); expect(auraPaletteVisual.background).toContain("conic-gradient"); expect(auraPaletteVisual.mask).toContain("radial-gradient"); expect(crownPaletteVisual.background).toContain("conic-gradient"); expect(crownPaletteVisual.mask).toContain("linear-gradient"); expect(auraPaletteVisual.animation).toBe("nebula-opening-aura"); expect(crownPaletteVisual.animation).toBe("nebula-opening-aura"); expect(auraPaletteVisual.duration).toBe("0.45s"); expect(crownPaletteVisual.duration).toBe("0.45s"); expect(auraPaletteVisual.filter).toBe(crownPaletteVisual.filter); expect(auraPaletteVisual.zIndex).toBe("1"); expect(crownPaletteVisual.zIndex).toBe("1"); await expect(mythicSurface.locator(".nebula-card-tilt-surface")).toHaveCSS("z-index", "2"); await page.clock.runFor(450); await expect(mythicSurface.locator(".nebula-card-particles i")).toHaveCount(48); const mythicBurstGeometry = await mythicSurface.locator(".nebula-card-particles").evaluate((element) => { const styles = element.ownerDocument.defaultView; const normalizeColors = (value) => value.replace(/rgba?\([^)]*\)/g, ""); const before = styles.getComputedStyle(element, "::before"); const after = styles.getComputedStyle(element, "::after"); const particle = styles.getComputedStyle(element.querySelector("i")); return { ring: { width: before.width, height: before.height, border: before.borderWidth, radius: before.borderRadius, shadow: normalizeColors(before.boxShadow), animation: before.animationName, duration: before.animationDuration, easing: before.animationTimingFunction }, rays: { width: after.width, height: after.height, radius: after.borderRadius, filter: normalizeColors(after.filter), animation: after.animationName, duration: after.animationDuration, easing: after.animationTimingFunction }, particle: { width: particle.width, height: particle.height, radius: particle.borderRadius, clipPath: particle.clipPath, animation: particle.animationName, duration: particle.animationDuration, easing: particle.animationTimingFunction, x: particle.getPropertyValue("--x"), y: particle.getPropertyValue("--y") }, particleSizes: [...element.querySelectorAll("i")].map((item) => `${styles.getComputedStyle(item).width}x${styles.getComputedStyle(item).height}`).join(" ") }; }); const { shadow: mythicRingShadow, ...mythicRingGeometry } = mythicBurstGeometry.ring; const { shadow: legendaryRingShadow, ...legendaryRingGeometry } = legendaryBurstVisual.geometry.ring; expect(legendaryRingShadow).not.toBe("none"); expect(mythicRingShadow).toBe("none"); const { width: mythicParticleWidth, height: mythicParticleHeight, ...mythicParticleMotion } = mythicBurstGeometry.particle; const { width: legendaryParticleWidth, height: legendaryParticleHeight, ...legendaryParticleMotion } = legendaryBurstVisual.geometry.particle; const { particleSizes: mythicParticleSizes, ...mythicBurstShared } = mythicBurstGeometry; const { particleSizes: legendaryParticleSizes, ...legendaryBurstShared } = legendaryBurstVisual.geometry; expect({ ...mythicBurstShared, ring: mythicRingGeometry, particle: mythicParticleMotion }).toEqual({ ...legendaryBurstShared, ring: legendaryRingGeometry, particle: legendaryParticleMotion }); expect([legendaryParticleWidth, legendaryParticleHeight]).toEqual(["12px", "12px"]); expect([mythicParticleWidth, mythicParticleHeight]).toEqual(["16px", "16px"]); expect(legendaryParticleSizes.split(" ").slice(0, 3)).toEqual(["12pxx12px", "12pxx12px", "7pxx18px"]); expect(mythicParticleSizes.split(" ").slice(0, 3)).toEqual(["16pxx16px", "16pxx16px", "9pxx24px"]); expect(mythicParticleSizes.split(" ")).toHaveLength(48); const mythicRingBackground = await mythicSurface.locator(".nebula-card-particles").evaluate((element) => globalThis.getComputedStyle(element, "::before").backgroundImage); expect(mythicRingBackground).toContain("conic-gradient"); expect(mythicRingBackground).toContain("rgb(255, 59, 48)"); const mythicRingGlow = await mythicSurface.locator(".nebula-card-particle-ring-glow").evaluateAll((elements) => elements.map((element) => { const style = globalThis.getComputedStyle(element); return { glow: element.dataset.glow, background: globalThis.getComputedStyle(element.firstElementChild.firstElementChild).backgroundImage, filter: globalThis.getComputedStyle(element.firstElementChild).filter, animation: style.animationName, duration: style.animationDuration }; })); expect(mythicRingGlow.map(({ glow }) => glow)).toEqual(["outer", "inner"]); for (const glow of mythicRingGlow) { expect(glow.background).toContain("conic-gradient"); expect(glow.filter).toBe("blur(9px)"); expect(glow.animation).toBe("nebula-particle-ring"); expect(glow.duration).toBe("1.2s"); } await expectMythicRingSilhouetteToMatchLegendary(page); const mythicRayBackground = await mythicSurface.locator(".nebula-card-particles").evaluate((element) => globalThis.getComputedStyle(element, "::after").backgroundImage); expect(mythicRayBackground).toContain("conic-gradient"); expect(mythicRayBackground).toContain("rgb(255, 59, 48)"); expect(mythicRayBackground).toContain("rgb(52, 199, 89)"); const mythicParticleColors = await mythicSurface.locator(".nebula-card-particles i").evaluateAll((particles) => [...new Set(particles.map((particle) => globalThis.getComputedStyle(particle).color))]); expect(mythicParticleColors.length).toBe(7); await page.clock.resume(); await expect(mythicPreview.getByRole("button", { name: "Remettre la carte Mythique face cachée", exact: true })).toHaveAttribute("data-reveal-phase", "revealed"); await page.setViewportSize({ width: 768, height: 900 }); await noOverflow(); await expandSections(page, "Sections de l’administration"); await navigation.getByRole("link", { name: "Collections" }).click(); await expect(page).toHaveURL(/#\/cards\/admin\/collections$/); const recharge = page.getByRole("complementary", { name: "Recharge des ouvertures" }); await expect(recharge.locator(".nebula-admin-recharge-current")).toHaveText("1 ouverture toutes les heures · réserve de 5"); await expect(recharge.getByLabel("Délai en minutes")).toHaveValue("60"); await expect(recharge.getByRole("status")).toHaveText("1 h · 24 ouvertures par jour · réserve vide remplie en 5 h"); await expect(recharge.getByRole("combobox")).toHaveCount(0); const applyRecharge = recharge.getByRole("button", { name: "Appliquer", exact: true }); await expect(applyRecharge).toBeDisabled(); await recharge.getByLabel("Délai en minutes").fill("30"); await expect(recharge.getByRole("status")).toHaveText("30 min · 48 ouvertures par jour · réserve vide remplie en 2 h 30 min"); await applyRecharge.click(); await page.getByRole("dialog", { name: "Passer à 1 ouverture toutes les 30 min ?" }).getByRole("button", { name: "Appliquer le délai" }).click(); await expect(recharge.locator(".nebula-admin-recharge-current")).toHaveText("1 ouverture toutes les 30 min · réserve de 5"); await expect(recharge.getByRole("button", { name: "Appliquer", exact: true })).toBeDisabled(); // L'historique d'administration garde cette modification, lisible et attribuée, et s'actualise sans recharger la page. await expandSections(page, "Sections de l’administration"); await page.getByRole("navigation", { name: "Sections de l’administration" }).getByRole("link", { name: "Historique", exact: true }).click(); await expect(page).toHaveURL(/#\/cards\/admin\/history$/); const latestAdminAction = page.locator(".nebula-history-list > li").first(); await expect(latestAdminAction).toContainText("Recharge modifiée"); await expect(latestAdminAction).toContainText(/1\s*h → 30\s*min/); await expect(latestAdminAction).toContainText("par Version développement"); await page.goBack(); // Ouverture aux joueurs et taux de tirage se règlent sur la page de la collection. await page.getByRole("link", { name: "Ouvrir la collection Genèse Astrale" }).click(); await expect(page).toHaveURL(/#\/cards\/admin\/collections\/astral-genesis$/); const genesisCard = page.locator(".nebula-admin-collection-card"); const packSwitch = genesisCard.getByRole("button", { name: "Ouvrir Genèse Astrale aux joueurs" }); await expect(packSwitch).toHaveAttribute("aria-pressed", "true"); const genesisPack = page.locator(".nebula-admin-drop-rates"); await expect(genesisPack.getByRole("heading", { name: "Taux de tirage" })).toBeVisible(); await expect(genesisPack.locator("tbody tr td strong")).toHaveText(["64 %", "24 %", "8 %", "3 %", "1 %"]); await expect(genesisPack.locator('tbody tr[data-rarity="mythic"] td').nth(2)).toHaveText("1"); await expect(genesisPack.locator('tbody tr[data-rarity="mythic"] td').nth(3)).toHaveText("1 %"); const applyButton = genesisPack.getByRole("button", { name: "Appliquer", exact: true }); const recommendedButton = genesisPack.getByRole("button", { name: "Taux recommandés" }); await expect(recommendedButton).toBeDisabled(); await expect(applyButton).toBeDisabled(); await genesisPack.getByLabel("Poids Commun").fill("63"); await genesisPack.getByLabel("Poids Mythique").fill("2"); await expect(genesisPack.locator('tbody tr[data-rarity="mythic"] td strong')).toHaveText("2 %"); await expect(genesisPack.locator('tbody tr[data-rarity="mythic"] td small')).toHaveText("avant 1 %"); await genesisPack.getByLabel("Poids Rare").fill("-1"); await expect(genesisPack.getByRole("alert")).toContainText("entier positif ou nul"); await expect(applyButton).toBeDisabled(); await genesisPack.getByLabel("Poids Rare").fill("24"); await applyButton.click(); await page.getByRole("dialog", { name: "Appliquer les nouveaux taux de Genèse Astrale ?" }).getByRole("button", { name: "Appliquer les taux" }).click(); await expect(applyButton).toBeDisabled(); await expect(genesisPack.locator('tbody tr[data-rarity="mythic"] td strong')).toHaveText("2 %"); // « Taux recommandés » préremplit le tableau sans rien enregistrer. await recommendedButton.click(); await expect(genesisPack.getByLabel("Poids Mythique")).toHaveValue("1"); await expect(genesisPack.getByLabel("Poids Commun")).toHaveValue("64"); await expect(recommendedButton).toBeDisabled(); await expect(applyButton).toBeEnabled(); await genesisPack.getByRole("button", { name: "Annuler les modifications" }).click(); await expect(genesisPack.getByLabel("Poids Mythique")).toHaveValue("2"); await packSwitch.click(); await page.getByRole("dialog", { name: "Fermer Genèse Astrale ?" }).getByRole("button", { name: "Fermer le paquet" }).click(); await expect(packSwitch).toHaveAttribute("aria-pressed", "false"); await expect(genesisCard).toContainText("Fermé aux joueurs"); // Une collection temporaire fermée sans carte possédée disparaît de la page Collection du joueur. const closedCollectionAdminUrl = page.url(); await page.goto("/#/cards/collection"); await expect(page.locator(".nebula-album-group").first()).toBeVisible(); await expect(page.locator(".nebula-album-group", { hasText: "Genèse Astrale" })).toHaveCount(0); await page.locator(".nebula-album-filters").getByRole("button", { name: "Collection", exact: true }).click(); await expect(page.locator(".nebula-album-filters").getByRole("checkbox", { name: "Genèse Astrale" })).toHaveCount(0); await page.keyboard.press("Escape"); await page.goto(closedCollectionAdminUrl); await expect(genesisCard).toContainText("Fermé aux joueurs"); await expect(genesisCard.locator(".nebula-admin-collection-badges .nds-badge").nth(1)).toHaveText("Fermée"); await packSwitch.click(); await expect(packSwitch).toHaveAttribute("aria-pressed", "true"); await noOverflow(); await page.goto("/#/cards/admin/packs"); await expect(selectTrigger(page, "Sections de l’administration")).toHaveText("Sections de l’administration : Collections"); await expandSections(page, "Sections de l’administration"); await navigation.getByRole("link", { name: "Boutique" }).click(); await expect(page).toHaveURL(/#\/cards\/admin\/shop$/); const recyclingForm = page.getByRole("region", { name: "Recyclage des doublons" }); const articlesForm = page.getByRole("region", { name: "Articles de la boutique" }); await expect(recyclingForm.getByLabel("Mythique", { exact: true })).toHaveValue("150"); await expect(recyclingForm.getByRole("button", { name: "Appliquer" })).toBeDisabled(); await expect(articlesForm.getByRole("button", { name: "Appliquer" })).toBeDisabled(); // Mêmes illustrations que la boutique des joueurs. await expect(articlesForm.locator('.nebula-shop-item[data-item="pack"] .nebula-collection-back')).toBeVisible(); await expect(articlesForm.locator('.nebula-shop-item[data-item="opening"] img')).toHaveAttribute("src", "/static/img/cards/shop/pack.webp"); // Appliquer les prix conserve le brouillon du barème, et ne l'envoie pas. await recyclingForm.getByLabel("Commun", { exact: true }).fill("2"); await articlesForm.getByLabel("Prix d’une ouverture de paquet").fill("45"); await expect(articlesForm.getByRole("status")).toHaveText("Une ouverture = 45 doublons communs recyclés."); await articlesForm.getByRole("button", { name: "Appliquer" }).click(); await page.getByRole("dialog").getByRole("button", { name: "Appliquer" }).click(); await expect(articlesForm.getByLabel("Prix d’une ouverture de paquet")).toHaveValue("45"); await expect(articlesForm.getByRole("button", { name: "Appliquer" })).toBeDisabled(); await expect(recyclingForm.getByLabel("Commun", { exact: true })).toHaveValue("2"); await recyclingForm.getByRole("button", { name: "Annuler les modifications" }).click(); await expect(recyclingForm.getByLabel("Commun", { exact: true })).toHaveValue("1"); // Le prix d'un Éclat (Pont des Veilleurs) se règle avec les autres articles, même Expéditions fermées. const eclatsArticle = articlesForm.locator('.nebula-shop-item[data-item="eclats"]'); await expect(eclatsArticle).toContainText("Fermé aux joueurs"); const eclatPrice = eclatsArticle.getByLabel("Prix d’un Éclat d’étoile"); await expect(eclatPrice).toHaveValue("3"); for (const price of ["4", "3"]) { await eclatPrice.fill(price); await articlesForm.getByRole("button", { name: "Appliquer" }).click(); await page.getByRole("dialog").getByRole("button", { name: "Appliquer" }).click(); await expect(eclatPrice).toHaveValue(price); await expect(articlesForm.getByRole("button", { name: "Appliquer" })).toBeDisabled(); } await expect(eclatsArticle).toContainText("Premier niveau d’une légendaire (70 Éclats) = 210 poussières."); await noOverflow(); await expandSections(page, "Sections de l’administration"); await navigation.getByRole("link", { name: "Codes cadeaux" }).click(); // La liste d'abord : le formulaire s'ouvre à la demande. await expect(page.getByText("Aucune campagne pour l’instant.", { exact: true })).toBeVisible(); const campaignForm = page.locator(".nebula-admin-campaign-form"); await expect(campaignForm).toHaveCount(0); const newCampaign = page.getByRole("button", { name: "+ Nouvelle campagne" }); await newCampaign.click(); await campaignForm.getByRole("button", { name: "Annuler" }).click(); await expect(campaignForm).toHaveCount(0); await newCampaign.click(); await expect(page.getByRole("heading", { name: "Nouvelle campagne" })).toBeVisible(); const createButton = campaignForm.getByRole("button", { name: "Créer la campagne" }); await expect(createButton).toBeDisabled(); await expect(campaignForm.locator(".nebula-admin-reward-item")).toHaveCount(0); await expect(campaignForm.locator(".nebula-admin-campaign-summary")).toHaveText("Ajoutez des cartes ou un paquet pour voir le récapitulatif."); await expect(campaignForm.getByRole("group", { name: "Cartes à offrir" })).toHaveCount(0); await expect(campaignForm.locator(".nebula-admin-campaign-missing")).toHaveText("Pour créer la campagne, il manque : le nom de la campagne ; au moins une carte ou un paquet ; un code de 4 à 24 caractères (lettres, chiffres, tirets)."); // Carte offerte, codes uniques. await campaignForm.getByLabel("Nom de la campagne, visible par les joueurs").fill("Cadeau dragon"); await campaignForm.getByRole("button", { name: "+ Ajouter des cartes" }).click(); const cardPicker = campaignForm.getByRole("group", { name: "Cartes à offrir" }); await expect(cardPicker.getByRole("status")).toHaveText("Aucune carte cochée."); await expect(cardPicker.locator('.nebula-card[data-card-size="sm"]').first()).toBeVisible(); await cardPicker.getByRole("radio", { name: "Mythique" }).click(); await cardPicker.getByRole("searchbox").fill("dragon"); await expect(cardPicker.locator(".nebula-admin-card-picker-item")).toHaveCount(2); const auroraDragon = cardPicker.getByRole("button", { name: "Sélectionner Dragon du Néant Étoilé — Mythique · Prisme spectral — Aurore" }); const otherDragon = cardPicker.locator(".nebula-admin-card-picker-item button").nth(1); await auroraDragon.click(); await otherDragon.click(); await expect(auroraDragon).toHaveAttribute("aria-pressed", "true"); await expect(cardPicker.getByRole("status")).toHaveText("2 cartes cochées"); // Un second clic décoche la carte. await otherDragon.click(); await expect(otherDragon).toHaveAttribute("aria-pressed", "false"); const checkedCards = campaignForm.getByRole("list", { name: "Cartes cochées" }); await expect(checkedCards.getByRole("listitem")).toHaveCount(1); await expect(checkedCards).toContainText("Dragon du Néant Étoilé — Mythique · Prisme spectral — Aurore"); // Par défaut : sans limite d'utilisations, sans date d'expiration. await expect(campaignForm.getByLabel("Sans limite d’utilisations")).toBeChecked(); await expect(campaignForm.getByLabel("Utilisations maximum")).toHaveCount(0); await expect(campaignForm.getByLabel("Sans date d’expiration")).toBeChecked(); await expect(campaignForm.getByLabel("Valable jusqu’au")).toHaveCount(0); await campaignForm.getByRole("button", { name: "Générer" }).click(); await expect(campaignForm.getByLabel("Code à annoncer (8 à 24 caractères)")).toHaveValue(/^[2-9A-HJKMNP-Z]{4}-[2-9A-HJKMNP-Z]{4}$/); await campaignForm.getByLabel("Code à annoncer (8 à 24 caractères)").fill("dragon-01"); await campaignForm.getByLabel("Sans limite d’utilisations").uncheck(); await campaignForm.getByLabel("Utilisations maximum").fill("1"); await campaignForm.getByLabel("Sans date d’expiration").uncheck(); await expect(campaignForm.getByLabel("Valable jusqu’au")).toBeVisible(); await expect(campaignForm.locator(".nebula-admin-campaign-summary")).toContainText("Carte Dragon du Néant Étoilé (Mythique · Prisme spectral — Aurore)"); await expect(campaignForm.locator(".nebula-admin-campaign-summary")).toContainText("Le code DRAGON-01, utilisable 1 fois, jusqu’au"); await createButton.click(); const generated = page.locator(".nebula-admin-generated"); await expect(generated.getByRole("heading", { name: "Campagne « Cadeau dragon » créée" })).toBeVisible(); await expect(generated).toContainText("Code à annoncer : DRAGON"); await expect(campaignForm).toHaveCount(0); await generated.getByRole("button", { name: "Fermer" }).click(); await newCampaign.click(); // Récompense composée : une carte et deux paquets avec garantie, code partagé sans limite. await campaignForm.getByLabel("Nom de la campagne, visible par les joueurs").fill("Live de lancement"); await expect(campaignForm.locator(".nebula-admin-reward-item")).toHaveCount(0); await expect(cardPicker).toHaveCount(0); await campaignForm.getByRole("button", { name: "+ Ajouter des cartes" }).click(); await chooseOption(campaignForm, "Collection affichée", "Genèse Astrale"); await cardPicker.getByRole("button", { name: "Sélectionner Paquet Astral — Commun" }).click(); await campaignForm.getByRole("button", { name: "+ Ajouter un paquet" }).click(); const packItem = campaignForm.getByRole("group", { name: "Paquet 1" }); await chooseOption(packItem, "Collection", "Genèse Astrale"); await packItem.getByLabel("Quantité").fill("2"); await packItem.getByRole("radio", { name: "Une rareté minimum" }).click(); await chooseOption(packItem, "Rareté garantie", "Légendaire"); await campaignForm.getByLabel("Code à annoncer (8 à 24 caractères)").fill("e2e live"); await expect(campaignForm.getByLabel("Code à annoncer (8 à 24 caractères)")).toHaveValue("E2E-LIVE"); await expect(campaignForm.locator(".nebula-admin-campaign-missing")).toHaveCount(0); await expect(campaignForm.locator(".nebula-admin-campaign-summary")).toContainText("+ 2 × Paquet Genèse Astrale · au moins 1 carte légendaire ou mieux garantie"); await expect(campaignForm.locator(".nebula-admin-campaign-summary")).toContainText("Le code E2E-LIVE, utilisable sans limite, sans date d’expiration."); await createButton.click(); await expect(generated).toContainText("E2E-LIVE"); const campaigns = page.locator(".nebula-campaign-card"); await expect(campaigns).toHaveCount(2); const dragonCampaign = page.getByRole("article", { name: "Cadeau dragon" }); await dragonCampaign.getByRole("button", { name: "Détails" }).click(); await expect(dragonCampaign).toContainText("Code DRAGON"); await expect(dragonCampaign).toContainText("0 / 1 utilisés"); await expect(dragonCampaign).toContainText("Personne n’a encore utilisé ce code."); await noOverflow(); // Le joueur utilise le code partagé dans l'onglet Paquets et ouvre le paquet offert. await page.goto("/#/cards"); await expandSections(page, "Sections de Sokko TCG"); await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Paquets", exact: true }).click(); await page.getByRole("textbox", { name: "Utiliser un code" }).fill("e2e-live"); await page.getByRole("button", { name: "Utiliser le code" }).click(); await expect(page.locator(".nebula-redeem [role=\"status\"]")).toContainText("Code utilisé, vous recevez : Carte Paquet Astral"); await expect(page.locator(".nebula-redeem [role=\"status\"]")).toContainText("2 × Paquet Genèse Astrale · au moins 1 carte légendaire ou mieux garantie"); const giftPack = page.locator(".nebula-gift-pack"); await expect(giftPack).toHaveCount(2); await expect(giftPack.first()).toContainText("Live de lancement"); await giftPack.first().click(); await expect(page.getByRole("heading", { name: "Révélez vos trois cartes" })).toBeVisible(); await expect(page.locator(".nebula-opening-odds")).toContainText("au moins 1 carte légendaire ou mieux garantie"); await page.getByRole("button", { name: "Tout révéler" }).click(); await expect(page.locator(".nebula-opening-cards .nebula-card[data-rarity=\"legendary\"], .nebula-opening-cards .nebula-card[data-rarity=\"mythic\"]").first()).toBeAttached(); // Le paquet offert n'a consommé aucune ouverture : il ne propose pas d'en dépenser une pour continuer. await expect(page.getByRole("button", { name: "Retour", exact: true })).toBeVisible({ timeout: 30_000 }); await expect(page.getByRole("button", { name: "Ouvrir un autre paquet de la même collection", exact: true })).toHaveCount(0); }); test("administration stays within a phone screen", async ({ page }) => { await page.setViewportSize({ width: 390, height: 844 }); await page.goto("/#/cards/admin/history"); await page.getByRole("button", { name: "Version développement", exact: true }).click(); await expect(page.getByRole("heading", { name: "Historique", exact: true })).toBeVisible(); // Un ancêtre masque ce qui dépasse : scrollWidth ne le voit pas, seule la position des éléments le révèle. const clipped = await page.locator(".nebula-dashboard :is(a, button, h1)").evaluateAll((elements) => elements .filter((element) => element.getBoundingClientRect().right > element.ownerDocument.defaultView.innerWidth + 0.5) .map((element) => element.textContent)); expect(clipped).toEqual([]); }); test("players give cards and answer trade proposals from two accounts", async ({ browser, page }) => { test.setTimeout(90_000); const nav = (scope) => scope.getByRole("navigation", { name: "Sections de Sokko TCG" }); const noOverflow = async (scope) => expect(await scope.locator("html").evaluate((element) => element.scrollWidth > element.clientWidth)).toBe(false); await page.goto("/#/cards/transfers"); await page.getByRole("button", { name: "Version développement", exact: true }).click(); await expect(page.getByRole("heading", { name: "Échanges et dons", exact: true })).toBeVisible(); const { token } = JSON.parse(await readFile(join(tmpdir(), "sokkog-cards-e2e-partner.json"), "utf8")); const partnerContext = await browser.newContext({ baseURL: "http://127.0.0.1:4180" }); await partnerContext.addCookies([{ name: "__Host-sokkog_cards_session", value: token, domain: "127.0.0.1", path: "/", secure: true, httpOnly: true, sameSite: "Lax" }]); const partner = await partnerContext.newPage(); await partner.goto("/#/cards/transfers"); // Don : deux envois du même doublon, sans code ni confirmation du destinataire. async function give() { await partner.getByRole("button", { name: "Faire un don", exact: true }).click(); const dialog = partner.getByRole("dialog"); await chooseOption(dialog, "Joueur", /Version développement/); await dialog.getByRole("button", { name: /Vous donnez : Loup des Aurores/ }).click(); await dialog.getByRole("button", { name: /^Donner Loup des Aurores à Version développement/ }).click(); await expect(partner.getByRole("status")).toContainText("Loup des Aurores a été donnée à Version développement."); } await give(); await give(); await page.reload(); await nav(page).getByRole("link", { name: "Collection", exact: true }).waitFor(); await expect(nav(page).getByRole("link", { name: "Échanges et dons", exact: true })).toBeVisible(); await page.getByRole("button", { name: /Terminées \(\d+\)/ }).click(); await expect(page.locator(".nebula-transfers-finished .nebula-transfer-card").first()).toContainText("Don de Partenaire E2E"); await expect(page.locator(".nebula-transfers-finished .nebula-transfer-card").first()).toContainText("Loup des Aurores"); // Échange : le partenaire voit le doublon de l'autre joueur et demande une carte précise. async function propose() { await partner.reload(); await partner.getByRole("button", { name: "Proposer un échange", exact: true }).click(); const dialog = partner.getByRole("dialog"); await expect(dialog.getByRole("button", { name: "Envoyer la proposition" })).toBeDisabled(); await chooseOption(dialog, "Joueur", /Version développement/); await dialog.getByRole("button", { name: /Vous donnez : Dragon du Néant Étoilé/ }).click(); await dialog.getByRole("button", { name: /Vous recevez : Loup des Aurores/ }).click(); await noOverflow(partner); // Dans le groupe Échange / Don, le texte ne touche pas les bords de son option. expect(await dialog.locator(".nds-radio-button-group button").evaluateAll((buttons) => buttons.every((button) => { const range = button.ownerDocument.createRange(); range.selectNodeContents(button); const text = range.getBoundingClientRect(); const box = button.getBoundingClientRect(); return text.left - box.left >= 6 && box.right - text.right >= 6; }))).toBe(true); await dialog.getByRole("button", { name: "Envoyer la proposition" }).click(); await expect(partner.getByRole("status")).toContainText("Proposition envoyée à Version développement."); } await propose(); await expect(partner.getByRole("heading", { name: /Envoyées/ })).toBeVisible(); await expect(partner.locator(".nebula-transfer-card").first()).toContainText(/Expire dans/); // Le compteur du menu apparaît au retour sur la page, sans recharger. await page.evaluate(() => globalThis.dispatchEvent(new globalThis.Event("focus"))); await expect(nav(page).getByRole("link", { name: /Échanges et dons/ }).locator(".nds-badge")).toHaveText("1"); const inbox = page.locator(".nebula-transfer-card", { hasText: "Échange avec Partenaire E2E" }).first(); await expect(inbox.locator(".nebula-card")).toHaveCount(2); await inbox.getByRole("button", { name: "Refuser" }).click(); await expect(page.getByRole("status")).toContainText("Proposition refusée."); await expect(nav(page).getByRole("link", { name: "Échanges et dons", exact: true })).toBeVisible(); // Le partenaire propose de nouveau, annule, puis propose encore : l'autre joueur accepte. await propose(); await partner.getByRole("button", { name: "Annuler", exact: true }).click(); await expect(partner.getByRole("status")).toContainText("Proposition annulée"); await propose(); await page.evaluate(() => globalThis.dispatchEvent(new globalThis.Event("focus"))); await page.locator(".nebula-transfer-card", { hasText: "Échange avec Partenaire E2E" }).first().getByRole("button", { name: "Accepter" }).click(); await expect(page.getByRole("status")).toContainText("Échange terminé"); await page.goto("/#/cards/history"); await expect(page.locator(".nebula-history-list")).toContainText("Reçue : Dragon du Néant Étoilé"); // La fiche d'une carte en double ouvre directement le formulaire. await partner.goto("/#/cards/collection"); await partner.locator(".nebula-album-entry:not([data-missing]) button").first().click(); await partner.getByRole("dialog").getByRole("button", { name: "Donner", exact: true }).click(); await expect(partner.getByRole("dialog").getByRole("heading", { name: "Faire un don" })).toBeVisible(); await expect(partner.getByRole("dialog").locator('[data-selected]')).toHaveCount(1); await partner.getByRole("dialog").getByRole("button", { name: "Fermer", exact: true }).click(); // Le paquet de la boutique s'achète en poussière, s'ouvre aussitôt et n'est jamais proposé dans Paquets. await partner.goto("/#/cards/packs"); await expect(partner.locator(".nebula-pack")).toHaveCount(2); await partner.goto("/#/cards/shop"); const packItem = partner.locator('.nebula-shop-item[data-item="pack"]'); await packItem.getByRole("button", { name: "Acheter et ouvrir" }).click(); await expect(partner).toHaveURL(/#\/cards\/packs$/); await expect(partner.getByRole("heading", { name: "Révélez vos trois cartes" })).toBeVisible(); await expect(partner.locator(".nebula-card-back img").first()).toHaveAttribute("src", "/static/img/cards/stardust/back.webp"); await expect(partner.locator(".nebula-opening-odds")).toContainText("50 % des légendaires et mythiques tirées viennent de Poussières d'étoiles"); await partner.getByRole("button", { name: "Tout révéler" }).click(); await expect(partner.getByRole("button", { name: "Retour", exact: true })).toBeVisible({ timeout: 30_000 }); // Ce paquet se paie en poussière : il ne propose pas de continuer sur une ouverture. await expect(partner.getByRole("button", { name: "Ouvrir un autre paquet de la même collection", exact: true })).toHaveCount(0); await partner.getByRole("button", { name: "Retour", exact: true }).click({ timeout: 30_000 }); await partner.goto("/#/cards/shop"); await expect(partner.locator(".nebula-shop-wallet")).toContainText("440"); // Plusieurs ouvertures d'un coup : le maximum suit la poussière (440 au prix affiché), la saisie y est ramenée. const openingItem = partner.locator('.nebula-shop-item[data-item="opening"]'); const openingPrice = Number((await openingItem.locator(".nebula-shop-item-rate .nebula-stardust").textContent()).replace(/\D/g, "")); const openingMax = Math.floor(440 / openingPrice); expect(openingMax).toBeGreaterThan(2); const openingCount = openingItem.getByRole("spinbutton", { name: "Ouvertures à acheter", exact: true }); // Vide au départ, le maximum en indication ; vide, il vaut un seul achat. await expect(openingCount).toHaveValue(""); await expect(openingCount).toHaveAttribute("placeholder", `max. ${openingMax}`); await expect(openingItem.getByRole("button", { name: `Acheter · ${openingPrice} poussières`, exact: true })).toBeVisible(); await openingCount.fill("500"); await expect(openingCount).toHaveValue(String(openingMax)); await openingCount.fill("2"); await openingItem.getByRole("button", { name: `Acheter · ${2 * openingPrice} poussières`, exact: true }).click(); await expect(partner.getByRole("status").filter({ hasText: "2 ouvertures achetées" })).toBeVisible(); await expect(partner.locator(".nebula-shop-wallet")).toContainText(String(440 - 2 * openingPrice)); await expect(openingCount).toHaveAttribute("placeholder", `max. ${Math.floor((440 - 2 * openingPrice) / openingPrice)}`); await expect(openingCount).toHaveValue(""); await partnerContext.close(); }); test("administrator previews the mythic opening from a base without any mythic variation", async ({ page }) => { await page.route("**/api/cards/config*", async (route) => { const response = await route.fetch(); const json = await response.json(); json.catalog.editions = json.catalog.editions.filter((edition) => edition.rarity !== "mythic"); await route.fulfill({ response, json }); }); await page.goto("/#/cards/admin"); await page.getByRole("button", { name: "Version développement", exact: true }).click(); await page.getByRole("link", { name: "Atelier visuel" }).click(); const mythicPreview = page.locator(".nebula-admin-opening-effect-card").filter({ has: page.getByRole("heading", { name: "Mythique", exact: true }) }); await expect(mythicPreview.locator(".nebula-admin-style-preview > span")).toHaveText(/^Aperçu · .+ — Prisme spectral — /); await mythicPreview.getByRole("button", { name: "Révéler la carte Mythique", exact: true }).click(); await expect(mythicPreview.locator(".nebula-card-particles i").first()).toBeAttached(); }); test("a player reads the privacy notice and deletes the account for good", async ({ browser, page }) => { test.setTimeout(60_000); const cachedSnapshots = () => page.evaluate(() => new Promise((resolve, reject) => { const request = globalThis.indexedDB.open("sokkog-nebula-cards", 1); request.onerror = () => reject(request.error); request.onsuccess = () => { const count = request.result.transaction("snapshots").objectStore("snapshots").count(); count.onsuccess = () => { request.result.close(); resolve(count.result); }; count.onerror = () => reject(count.error); }; })); const login = page.getByRole("button", { name: "Version développement", exact: true }); await page.goto("/#/cards"); // Le lien est hors du panneau de connexion, centré sous lui ; déplié, la notice a son propre panneau en dessous. const privacyToggle = page.getByRole("button", { name: "Confidentialité de Sokko TCG", exact: true }); await expect(page.locator(".nebula-login .nebula-privacy-toggle")).toHaveCount(0); const loginBox = await page.locator(".nebula-login").boundingBox(); const toggleBox = await privacyToggle.boundingBox(); expect(toggleBox.y).toBeGreaterThanOrEqual(loginBox.y + loginBox.height); expect(toggleBox.x + toggleBox.width / 2).toBeCloseTo(loginBox.x + loginBox.width / 2, 0); const privacyPanel = page.locator(".nebula-login-privacy"); await expect(privacyToggle).toHaveAttribute("aria-expanded", "false"); await expect(privacyPanel).toHaveCount(0); // Au survol, seul le texte s'éclaircit : il ne reprend pas le fond des boutons du site. await privacyToggle.hover(); await expect(privacyToggle).toHaveCSS("background-image", "none"); await expect(privacyToggle).toHaveCSS("box-shadow", "none"); await privacyToggle.click(); await expect(privacyToggle).toHaveAttribute("aria-expanded", "true"); await expect(page.locator(".nebula-login .nebula-privacy-notice")).toHaveCount(0); await expect(privacyPanel.getByRole("link", { name: "privacy@example.invalid" })).toHaveAttribute("href", "mailto:privacy@example.invalid"); await expect(privacyPanel).toContainText("Exploitant E2E"); await expect(privacyPanel).toContainText("24 mois"); // Le panneau suit le lien et ne passe pas sous la barre du haut quand la page défile jusqu'à lui. const panelBox = await privacyPanel.boundingBox(); const openToggleBox = await privacyToggle.boundingBox(); expect(panelBox.y).toBeGreaterThan(openToggleBox.y); expect(panelBox.y).toBeGreaterThanOrEqual((await page.locator(".topbar").boundingBox()).height); await privacyToggle.click(); await expect(privacyPanel).toHaveCount(0); await login.click(); await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Compte", exact: true }).click(); await expect(page.getByRole("heading", { name: "Compte", exact: true })).toBeVisible(); await expect(page.locator(".nebula-account-summary dd").first()).toHaveText("Version développement"); await expect(page.locator(".nebula-account").getByRole("link", { name: "privacy@example.invalid" })).toBeVisible(); await expect.poll(cachedSnapshots).toBe(1); const deleteButton = page.getByRole("button", { name: "Supprimer mon compte", exact: true }); await deleteButton.click(); await page.getByRole("dialog").getByRole("button", { name: "Annuler", exact: true }).click(); await expect(page.getByRole("dialog")).toHaveCount(0); await expect(page.getByRole("heading", { name: "Compte", exact: true })).toBeVisible(); await deleteButton.click(); await page.getByRole("dialog").getByRole("button", { name: "Supprimer définitivement", exact: true }).click(); await expect(page.getByRole("status")).toContainText("Votre compte a bien été supprimé."); await expect(page).toHaveURL(/#\/cards$/); await expect(login).toBeVisible(); expect(await cachedSnapshots()).toBe(0); const { token } = JSON.parse(await readFile(join(tmpdir(), "sokkog-cards-e2e-partner.json"), "utf8")); const partnerContext = await browser.newContext({ baseURL: "http://127.0.0.1:4180" }); await partnerContext.addCookies([{ name: "__Host-sokkog_cards_session", value: token, domain: "127.0.0.1", path: "/", secure: true, httpOnly: true, sameSite: "Lax" }]); const partnerPage = await partnerContext.newPage(); await partnerPage.goto("http://127.0.0.1:4180/"); const { traders } = await partnerPage.evaluate(() => globalThis.fetch("/api/cards/traders").then((response) => response.json())); expect(traders.map((trader) => trader.displayName)).not.toContain("Version développement"); await partnerContext.close(); // Une nouvelle connexion repart d'un compte neuf, et la déconnexion ne laisse aucune copie dans le navigateur. await login.click(); await expect(page.locator('.nebula-opening-reserve[aria-label="Ouvertures disponibles"] .nebula-opening-reserve-value')).toContainText("3/ 5"); await expect.poll(cachedSnapshots).toBe(1); await page.getByRole("button", { name: "Déconnexion", exact: true }).click(); await expect(login).toBeVisible(); expect(await cachedSnapshots()).toBe(0); }); test("the about page mentions the game while it is enabled", async ({ page }) => { await page.goto("/#/about"); await expect(page.locator(".about-page .nds-page-hero")).toContainText("Seul le mini-jeu Sokko TCG utilise un compte Discord"); }); test("the shop pack rates count the cards it draws from the other collections", async ({ page }) => { await page.goto("/#/cards/admin/collections/stardust"); await page.getByRole("button", { name: "Version développement", exact: true }).click(); const rates = page.locator(".nebula-admin-drop-table"); await expect(rates).toBeVisible(); await expect(rates.locator("[role=status]")).toHaveCount(0); const commonRow = rates.locator('tr[data-rarity="common"]'); await expect(commonRow.locator("td").nth(2)).not.toHaveText("0"); await expect(commonRow.locator("td").nth(3)).toHaveText("—"); // Sa page rappelle d'où il tire ses cartes et règle la part de ses propres légendaires et mythiques. const content = page.getByRole("region", { name: "Contenu du paquet", exact: true }); await expect(content).toContainText("Collections ouvertes"); await expect(content).toContainText(/\d+ légendaires? et \d+ mythiques?/); await expect(content.getByRole("spinbutton", { name: "Part de ses cartes parmi les légendaires et mythiques (%)" })).toHaveValue("50"); }); test("a player chains packs of the same collection while openings remain", async ({ page }) => { test.setTimeout(60_000); const openAnother = page.getByRole("button", { name: "Ouvrir un autre paquet de la même collection", exact: true }); const revealAll = page.getByRole("button", { name: "Tout révéler" }); const back = page.getByRole("button", { name: "Retour", exact: true }); const pendingCollection = () => page.evaluate(async () => (await globalThis.fetch("/api/cards/state")).json().then((state) => state.pendingOpening?.collectionId ?? null)); // Fait croire au client que le solde a changé à la fin de l'ouverture : le compte de développement a une réserve figée. const stubBalance = (openingsBalance, purchasedOpenings) => page.route("**/api/cards/openings/*/complete", async (route) => { const response = await route.fetch(); const state = await response.json(); await route.fulfill({ response, json: { ...state, recharge: { ...state.recharge, openingsBalance }, wallet: { ...state.wallet, purchasedOpenings } } }); }); await page.goto("/#/cards/packs"); await page.getByRole("button", { name: "Version développement", exact: true }).click(); await page.getByRole("button", { name: "Ouvrir ce paquet : Genèse Astrale", exact: true }).click(); await expect(revealAll).toBeVisible(); await expect(openAnother).toHaveCount(0); // L'étape rappelle ce qu'il reste à ouvrir, en séparant la recharge automatique des ouvertures achetées. const balances = await page.evaluate(async () => (await globalThis.fetch("/api/cards/state")).json().then((state) => [state.recharge.openingsBalance, state.wallet.purchasedOpenings])); const remaining = page.getByRole("definition"); await expect(page.getByRole("term")).toHaveText(["Recharge auto", "À l’unité"]); await expect(remaining).toHaveText(balances.map(String)); await revealAll.click(); await expect(openAnother).toBeEnabled(); await expect.poll(pendingCollection).toBeNull(); // Le libellé long tient à la largeur minimale, à côté de « Retour ». await page.setViewportSize({ width: 768, height: 900 }); await expect(openAnother).toBeVisible(); expect(await page.evaluate(() => globalThis.document.documentElement.scrollWidth <= globalThis.document.documentElement.clientWidth)).toBe(true); await page.setViewportSize({ width: 1280, height: 720 }); // Le nouveau paquet vient de la même collection, et le clavier reprend sur « Tout révéler ». await openAnother.click(); await expect(page.getByRole("button", { name: "Révéler la carte" })).toHaveCount(3); await expect(page.locator('.nebula-card-back img[src="/static/img/cards/astral-genesis/back.webp"]')).toHaveCount(3); await expect.poll(pendingCollection).toBe("astral-genesis"); await expect(revealAll).toBeFocused(); // Réserve vide mais ouverture achetée : l'enchaînement utilise l'achetée ; le refus du serveur laisse les cartes et l'action en place. await stubBalance(0, 1); const openRequest = page.waitForRequest((request) => request.method() === "POST" && request.url().endsWith("/api/cards/openings")); await revealAll.click(); await expect(openAnother).toBeEnabled(); await expect(remaining).toHaveText(["0", "1"]); await openAnother.click(); expect((await openRequest).postDataJSON()).toEqual({ collectionId: "astral-genesis", purchased: true }); await expect(page.getByRole("alert")).toContainText("aucune ouverture achetée"); await expect(page.locator('.nebula-opening-cards .nebula-card[data-card-size="lg"]')).toHaveCount(3); await expect(openAnother).toBeEnabled(); // Plus aucune ouverture : seul le retour reste proposé. await page.unroute("**/api/cards/openings/*/complete"); await back.click(); await page.reload(); await page.getByRole("button", { name: "Ouvrir ce paquet : Genèse Astrale", exact: true }).click(); await stubBalance(0, 0); await revealAll.click(); await expect(back).toBeEnabled(); await expect(openAnother).toHaveCount(0); }); test("the Sokko TCG menu entry shows a count while the opening reserve is full", async ({ page }) => { const cardsLink = page.getByRole("navigation", { name: "Navigation principale" }).getByRole("link", { name: /^Sokko TCG/ }); const count = cardsLink.locator(".nav-icon-count"); // Visiteur sans compte : aucune pastille. await page.goto("/#/toolboxes"); await expect(cardsLink).toHaveAccessibleName("Sokko TCG"); await expect(count).toHaveCount(0); await page.goto("/#/cards"); await page.getByRole("button", { name: "Version développement", exact: true }).click(); await expect(page.getByRole("heading", { name: "Sokko TCG", exact: true })).toBeVisible(); // Le compte de développement garde une réserve juste sous le maximum : la route est simulée pleine. await page.route("**/api/cards/reserve", (route) => route.fulfill({ json: { recharge: { openingsBalance: 5, rechargeAnchor: null, nextOpeningAt: null } } })); await page.goto("/#/toolboxes"); await page.reload(); await expect(count).toHaveText("5"); await expect(cardsLink).toHaveAccessibleName("Sokko TCG (réserve d’ouvertures pleine)"); const [icon, badge] = await Promise.all([cardsLink.locator(".nav-icon").boundingBox(), count.boundingBox()]); expect(badge.x).toBeGreaterThan(icon.x + icon.width / 2); expect(badge.y).toBeLessThan(icon.y + icon.height / 2); // En sidebar compacte, la pastille reste sur l'icône seule. await page.setViewportSize({ width: 900, height: 800 }); await expect(count).toBeVisible(); await page.setViewportSize({ width: 1280, height: 720 }); // Sur la page de jeu, l'état réel (réserve non pleine) remplace aussitôt la valeur relue par le menu. await page.getByRole("navigation", { name: "Navigation principale" }).getByRole("link", { name: /^Sokko TCG/ }).click(); await expect(page.locator(".nebula-opening-reserve")).toBeVisible(); await expect(count).toHaveCount(0); await expect(cardsLink).toHaveAccessibleName("Sokko TCG"); }); // En dernier : une victoire crédite la poussière du compte de développement, dont les parcours précédents vérifient le solde. test("a player finds the daily card with hints and copies the result", async ({ context, page }) => { await context.grantPermissions(["clipboard-read", "clipboard-write"]); await page.goto("/#/cards"); await page.getByRole("button", { name: "Version développement", exact: true }).click(); // La Guilde des Veilleurs a son entrée de menu, avec le nombre de quêtes en attente, et son bandeau sur l'Accueil, entièrement visible en 1280 × 720. const sections = page.getByRole("navigation", { name: "Sections de Sokko TCG" }); await expect(sections.getByRole("link")).toHaveText(["Accueil", "Guilde1", "Paquets", "Collection", "Boutique", "Échanges et dons", "Historique", "Compte"]); await expect(sections.getByRole("link", { name: /^Guilde/ })).toHaveAttribute("href", "#/cards/guild"); await expect(sections.locator('a[href="#/cards/daily"]')).toHaveCount(0); const guildBanner = page.getByRole("region", { name: "Guilde des Veilleurs", exact: true }); await expect(guildBanner).toBeInViewport({ ratio: 1 }); await expect(guildBanner).toContainText("1 quête vous attend."); await guildBanner.getByRole("link", { name: "Accéder aux missions", exact: true }).click(); await expect(page).toHaveURL(/#\/cards\/guild$/); await expect(page.getByRole("heading", { name: "Guilde des Veilleurs", exact: true })).toBeVisible(); await expect(sections.getByRole("link", { name: /^Guilde/ })).toHaveAttribute("aria-current", "page"); const quest = page.getByRole("article", { name: "Carte du jour" }); await expect(quest).toContainText("Une nouvelle carte vous attend."); await quest.getByRole("link", { name: "Jouer", exact: true }).click(); await expect(page).toHaveURL(/#\/cards\/daily$/); await expect(sections.getByRole("link", { name: /^Guilde/ })).toHaveAttribute("aria-current", "page"); await expect(page.getByRole("link", { name: "Retour à la Guilde", exact: true })).toHaveAttribute("href", "#/cards/guild"); // L'illustration arrive en blob, sans adresse qui nommerait la carte : seulement la zone visible, recadrée et agrandie par // le serveur (720 px de large), sans agrandissement CSS à défaire. const image = page.getByRole("img", { name: "Illustration de la Carte du jour, agrandie" }); await expect(image).toHaveAttribute("src", /^blob:/); await expect.poll(() => image.evaluate((element) => element.naturalWidth)).toBe(720); await expect(image).toHaveCSS("transform", "none"); const firstCrop = await image.getAttribute("src"); // Chaque joueur a sa propre carte, que l'API ne donne qu'en fin de partie : le parcours la lit dans la base du serveur E2E. const { path: databasePath } = JSON.parse(await readFile(join(tmpdir(), "sokkog-cards-e2e-db.json"), "utf8")); const database = new DatabaseSync(databasePath, { readOnly: true }); const { card_id: answerId } = database.prepare("SELECT attempt.card_id FROM daily_attempts AS attempt JOIN players ON players.id = attempt.player_id WHERE players.discord_id = 'dev-admin' ORDER BY attempt.day DESC LIMIT 1").get(); database.close(); const { answer, wrong, sameCollection } = await page.evaluate(async (answerCardId) => { const [config, daily] = await Promise.all(["/api/cards/config", "/api/cards/daily"].map(async (path) => (await globalThis.fetch(path)).json())); const cards = config.catalog.cards; const answerCard = cards.find((card) => card.id === answerCardId); // Une carte de la même collection si elle en a d'autres (la collection de la boutique n'en compte qu'une). const others = cards.filter((card) => card.id !== answerCard.id && daily.collectionIds.includes(card.collectionId)); const wrongCard = others.find((card) => card.collectionId === answerCard.collectionId) || others[0]; return { answer: answerCard.name, wrong: wrongCard.name, sameCollection: wrongCard.collectionId === answerCard.collectionId }; }, answerId); const input = page.getByRole("combobox", { name: /^Votre proposition/ }); // La recherche ignore les accents et la casse. await input.fill(wrong.normalize("NFD").replace(/\p{Diacritic}/gu, "").toLowerCase()); // Les suggestions dépassent du panneau sans être coupées ni recouvertes. await expectOpenMenuVisible(page, ".nebula-daily-form .nds-autocomplete-menu"); await page.getByRole("option", { name: wrong, exact: true }).click(); await page.getByRole("button", { name: "Proposer", exact: true }).click(); const guesses = page.locator(".nebula-daily-guess"); await expect(guesses).toHaveCount(1); await expect(guesses.first()).toContainText(wrong); await expect(guesses.first()).toContainText(sameCollection ? "Même collection" : "Pas dans"); // Un essai raté fait venir un morceau plus large de l'illustration. await expect(image).not.toHaveAttribute("src", firstCrop); await expect.poll(() => image.evaluate((element) => element.naturalWidth)).toBe(720); await expect(page.locator(`.nebula-daily-steps li[data-result="${sameCollection ? "close" : "miss"}"]`)).toHaveCount(1); await input.fill(answer); await page.getByRole("button", { name: "Proposer", exact: true }).click(); const result = page.locator(".nebula-daily-result"); await expect(result.getByRole("heading", { name: "Trouvée en 2/6 !" })).toBeVisible(); await expect(result).toContainText("+10 poussières gagnées"); await expect(result.locator(".nebula-daily-answer strong")).toHaveText(answer); await expect(result.locator(".nebula-card")).toBeVisible(); // La partie finie, l'illustration entière arrive à sa taille d'origine, à la place des morceaux de 720 px. await expect.poll(() => image.evaluate((element) => element.naturalWidth)).not.toBe(720); await expect(page.getByRole("combobox", { name: /^Votre proposition/ })).toHaveCount(0); await result.getByRole("button", { name: "Copier le résultat", exact: true }).click(); await expect(result.getByRole("button", { name: "Résultat copié", exact: true })).toBeVisible(); const copied = await page.evaluate(() => globalThis.navigator.clipboard.readText()); expect(copied).toBe(`Sokko TCG · Carte du jour #1 · 2/6\n${sameCollection ? "🟨" : "⬛"}🟩\nhttp://127.0.0.1:4180/#/cards/daily`); // En demi-écran, la page passe sur une colonne sans défilement horizontal ; le menu replié nomme la Guilde, la quête étant terminée. await page.setViewportSize({ width: 768, height: 900 }); await expect(selectTrigger(page, "Sections de Sokko TCG")).toHaveText("Sections de Sokko TCG : Guilde"); const overflow = await page.evaluate(() => [".nebula-dashboard-menu", ".nebula-daily"].map((selector) => { const element = globalThis.document.querySelector(selector); return element.scrollWidth - element.clientWidth; })); expect(overflow).toEqual([0, 0]); await page.setViewportSize({ width: 1280, height: 720 }); // L'administration règle la récompense dans sa section Guilde, avec la partie du jour. await page.goto("/#/cards/admin/guild"); const dailySettings = page.getByRole("region", { name: "Carte du jour", exact: true }); await expect(dailySettings).toContainText("1 gagnant sur 1 joueur aujourd’hui."); await expect(dailySettings.getByRole("spinbutton", { name: "Récompense d’une victoire" })).toHaveValue("10"); await page.goto("/#/cards"); await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Historique", exact: true }).click(); await expect(page.locator(".nebula-history-list li").filter({ hasText: "Carte du jour trouvée" })).toContainText("· 2/6 · +10 poussières d’étoiles"); // La quête terminée n'attend plus : le bandeau l'annonce, et la tuile de la Guilde donne le résultat. await page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Accueil", exact: true }).click(); await expect(guildBanner).toContainText("Aucune quête ne vous attend pour le moment."); await guildBanner.getByRole("link", { name: "Accéder aux missions", exact: true }).click(); await expect(quest.locator(".nebula-quest-status")).toHaveText("Trouvée en 2/6."); await expect(quest.locator(".nebula-quest-media .nds-badge")).toHaveText("Série : 1 jour"); await expect(quest.getByRole("link", { name: "Voir le résultat", exact: true })).toBeVisible(); }); // Dernier parcours : il ouvre les Expéditions et décale l'horloge du serveur, deux réglages globaux qu'il remet en place à la fin. test("an administrator opens expeditions and a player leaves alone, follows the journey, then claims its loot", async ({ browser, page }) => { // Le suivi d'un groupe depuis un second écran attend les relectures périodiques de la vue (jusqu'à 20 s). test.setTimeout(120_000); const clockFile = join(tmpdir(), "sokkog-cards-e2e-clock.json"); const setServerClock = (offsetMs) => writeFile(clockFile, JSON.stringify({ offsetMs })); await setServerClock(0); await page.goto("/#/cards"); await page.getByRole("button", { name: "Version développement", exact: true }).click(); // La Guilde range ses quêtes en onglets ; les Expéditions s'ouvrent depuis leur bandeau d'état, sans passer par le brouillon. await page.goto("/#/cards/admin/guild"); await page.getByRole("tab", { name: "Expéditions", exact: true }).click(); await expect(page).toHaveURL(/#\/cards\/admin\/guild\/expeditions$/); const status = page.getByRole("region", { name: /^Expéditions (Ouvertes|Fermées) aux joueurs$/ }); await expect(status).toContainText("Fermées aux joueurs"); await status.getByRole("button", { name: "Ouvrir les Expéditions", exact: true }).click(); await page.getByRole("dialog").getByRole("button", { name: "Ouvrir", exact: true }).click(); await expect(status).toContainText("Ouvertes aux joueurs"); const adminDestinations = page.getByRole("region", { name: "Destinations", exact: true }); await expect(adminDestinations.getByRole("listitem")).toHaveCount(17); await expect(adminDestinations.getByText("Le Grand Salon Astral", { exact: true })).toBeVisible(); // Le prix d'un Éclat n'est plus dans les réglages des Expéditions : il se règle dans la Boutique. await page.getByRole("tab", { name: "Cartes", exact: true }).click(); await expect(page.getByRole("region", { name: "Améliorations", exact: true })).not.toContainText("Éclat d’étoile en boutique"); await page.getByRole("tab", { name: "Déroulement", exact: true }).click(); // Un réglage touché s'annonce dans son onglet et dans la barre commune, qui l'annule. const perDay = page.getByRole("region", { name: "Général", exact: true }).getByRole("spinbutton", { name: "Destinations proposées par jour", exact: true }); await perDay.fill("5"); await expect(page.getByRole("tab", { name: "Déroulement (1)", exact: true })).toBeVisible(); const applyBar = page.getByRole("region", { name: "Modifications en attente", exact: true }); await expect(applyBar).toContainText("1 réglage modifié"); await applyBar.getByRole("button", { name: "Annuler les modifications", exact: true }).click(); await expect(applyBar).toHaveCount(0); await expect(perDay).toHaveValue("4"); // Le partenaire possède deux légendaires distinctes : une suffit pour partir. const { token } = JSON.parse(await readFile(join(tmpdir(), "sokkog-cards-e2e-partner.json"), "utf8")); const partnerContext = await browser.newContext({ baseURL: "http://127.0.0.1:4180", viewport: { width: 1280, height: 900 } }); await partnerContext.addCookies([{ name: "__Host-sokkog_cards_session", value: token, domain: "127.0.0.1", path: "/", secure: true, httpOnly: true, sameSite: "Lax" }]); const partner = await partnerContext.newPage(); await partner.goto("/#/cards/guild"); const quest = partner.getByRole("article", { name: "Expéditions" }); await expect(quest).toContainText("De nouvelles destinations vous attendent."); await quest.getByRole("link", { name: "Préparer", exact: true }).click(); await expect(partner).toHaveURL(/#\/cards\/expeditions$/); await expect(partner.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: /^Guilde/ })).toHaveAttribute("aria-current", "page"); const destinations = partner.getByRole("region", { name: "1. Destination du jour" }).getByRole("button"); await expect(destinations).toHaveCount(4); await expect(destinations.first()).toHaveAttribute("aria-pressed", "true"); // La difficulté est tirée avec les destinations : une de chaque niveau, 1 à 4 étoiles, seul ou en groupe. On prend la plus facile. for (const stars of ["1 étoile", "2 étoiles", "3 étoiles", "4 étoiles"]) await expect(destinations.filter({ has: partner.getByRole("img", { name: `Difficulté : ${stars}`, exact: true }) })).toHaveCount(1); const easiest = destinations.filter({ has: partner.getByRole("img", { name: "Difficulté : 1 étoile", exact: true }) }); await easiest.click(); // Chaque destination montre ses exigences pour une carte seule, une étoile sur la stat principale. await expect(easiest.locator(".nebula-destination-requirement[data-main] .nebula-main-stat-mark")).toHaveCount(1); await expect(easiest.locator(".nebula-destination-requirement[data-met]")).toHaveCount(0); // Une seule carte, avec son rôle ; plus de choix entre solo et groupe. await expect(partner.getByRole("group", { name: "Mode" })).toHaveCount(0); const team = partner.getByRole("region", { name: "2. Votre carte" }); // La carte se choisit dans une fenêtre, depuis l'emplacement vide du cadre. await team.getByRole("button", { name: "Choisir une carte", exact: true }).click(); const picker = partner.getByRole("dialog", { name: "Choisir la carte envoyée" }); await picker.getByRole("group", { name: "Trier par" }).getByRole("button", { name: "Puissance", exact: true }).click(); await picker.getByRole("button", { name: /^Choisir Loup des Aurores$/ }).click(); await expect(picker).toHaveCount(0); // La carte choisie : ses stats pour l'expédition et son équipement ; les exigences se colorent selon elle. await expect(team.locator(".nebula-expedition-loadout")).toContainText("Loup des Aurores"); await expect(team.locator(".nebula-expedition-loadout").getByRole("list", { name: "Équipements", exact: true }).getByRole("listitem")).toHaveCount(3); await expect(easiest.locator(".nebula-destination-requirement[data-met]")).toHaveCount(1); const settings = partner.getByRole("region", { name: "3. Durée et départ" }); await settings.getByRole("button", { name: "2 h", exact: true }).click(); await expect(settings.locator(".nebula-expected-loot")).toContainText(/≈ [\d,]+ Éclats/); await expect(settings.locator(".nebula-expedition-preview .nds-badge").first()).toHaveText(/^(Retour difficile|Réussite|Triomphe)$/); await settings.getByRole("button", { name: "Partir seul maintenant", exact: true }).click(); await expect(partner.getByRole("status").filter({ hasText: "Expédition partie !" })).toBeVisible(); // En route : la préparation laisse place au voyage, avec sa barre de progression et les cartes parties. const journey = partner.locator(".nebula-expedition-journey"); await expect(journey).toContainText(/En route, retour dans (1 h|2 h)/); await expect(journey.getByRole("progressbar", { name: "Progression du voyage" })).toBeVisible(); await expect(journey.locator(".nebula-expedition-caravan li")).toHaveCount(1); await expect(partner.getByRole("region", { name: "1. Destination du jour" })).toHaveCount(0); // En demi-écran, la page reste sans défilement horizontal. await partner.setViewportSize({ width: 768, height: 900 }); expect(await partner.locator(".nebula-expeditions").evaluate((element) => element.scrollWidth - element.clientWidth)).toBe(0); await partner.setViewportSize({ width: 1280, height: 900 }); // Trois heures plus tard pour le serveur : l'expédition est revenue, son butin s'affiche sur place, sans rappel du résultat ; il se // récupère d'un clic, qui retire la carte et confirme par un avis. await setServerClock(3 * 3_600_000); await partner.reload(); const report = partner.locator(".nebula-expedition-return").first(); await expect(report).toContainText("De retour ! Le butin vous attend."); await expect(report.getByRole("definition")).toHaveCount(0); const loot = report.getByRole("region", { name: "Butin rapporté", exact: true }); await expect(loot.getByRole("listitem").filter({ hasText: /^\+[\d\s]+ Éclats$/ })).toBeVisible(); await report.getByRole("button", { name: "Récupérer le butin", exact: true }).click(); await expect(partner.locator(".nebula-expeditions > .nds-inline-notice[role=status]")).toHaveText("Butin récupéré : il est dans votre collection."); await expect(partner.locator(".nebula-expedition-return")).toHaveCount(0); await expect(partner.locator(".nebula-expeditions .nds-section-heading .nds-badge")).not.toHaveText("0 Éclats d’étoile"); // L'expédition terminée passe au Journal. await partner.getByRole("tab", { name: "Journal (1)", exact: true }).click(); await expect(partner.getByRole("region", { name: "Expéditions terminées", exact: true }).locator(".nebula-expedition-report")).toContainText("Butin récupéré."); await expect(partner.getByRole("region", { name: /^Grimoire/ })).toHaveCount(0); await partner.getByRole("tab", { name: "Préparer", exact: true }).click(); // Ouverte au groupe, l'expédition attend d'autres joueurs, avec son lien d'invitation ; son créateur peut l'annuler. await partner.getByRole("region", { name: "2. Votre carte" }).getByRole("button", { name: "Choisir une carte", exact: true }).click(); await partner.getByRole("dialog", { name: "Choisir la carte envoyée" }).getByRole("button", { name: /^Choisir Loup des Aurores$/ }).click(); await expect(partner.getByRole("region", { name: "3. Durée et départ" })).toContainText(/≈ [\d,]+ Éclats/); await partner.getByRole("button", { name: "Ouvrir au groupe", exact: true }).click(); await expect(partner.getByRole("status").filter({ hasText: "Expédition ouverte !" })).toBeVisible(); const mine = partner.getByRole("region", { name: "Votre expédition en préparation" }); const groupCard = mine.locator(".nebula-expedition-group"); await expect(groupCard).toContainText("ouvert par vous"); await expect(groupCard.locator(".nebula-expedition-group-free")).toHaveCount(3); await expect(groupCard.getByRole("textbox", { name: /^Lien d’invitation/ })).toHaveValue(/#\/cards\/expeditions\/[\w-]+$/); // Un second écran sur la même page suit le groupe sans être rechargé : il voit l'annulation, puis un nouveau groupe et son départ. // Son premier chargement échoue : l'erreur propose « Réessayer », qui rétablit la page. const watcher = await partnerContext.newPage(); let failures = 1; await watcher.route("**/api/cards/expeditions", (route) => (route.request().method() === "GET" && failures-- > 0 ? route.fulfill({ status: 503, contentType: "application/json", body: JSON.stringify({ error: { code: "UNAVAILABLE", message: "Service indisponible." } }) }) : route.continue())); await watcher.goto("/#/cards/expeditions"); await expect(watcher.getByRole("alert")).toContainText("Service indisponible."); await watcher.getByRole("button", { name: "Réessayer", exact: true }).click(); const watched = watcher.getByRole("region", { name: "Votre expédition en préparation" }); await expect(watched).toBeVisible(); await groupCard.getByRole("button", { name: "Annuler l’expédition", exact: true }).click(); await expect(mine).toHaveCount(0); await expect(partner.getByRole("region", { name: "1. Destination du jour" })).toBeVisible(); await expect(watched).toHaveCount(0, { timeout: 15_000 }); await partner.getByRole("region", { name: "2. Votre carte" }).getByRole("button", { name: "Choisir une carte", exact: true }).click(); await partner.getByRole("dialog", { name: "Choisir la carte envoyée" }).getByRole("button", { name: /^Choisir Loup des Aurores$/ }).click(); await partner.getByRole("button", { name: "Ouvrir au groupe", exact: true }).click(); await expect(watched).toBeVisible({ timeout: 30_000 }); await mine.getByRole("button", { name: "Partir maintenant", exact: true }).click(); await expect(watcher.locator(".nebula-expedition-journey")).toBeVisible({ timeout: 15_000 }); await expect(watched).toHaveCount(0); await watcher.close(); // Pont des Veilleurs, en boutique : 3 poussières pour 1 Éclat ; la fiche de carte montre le niveau, la Puissance et l'expérience gagnée au retour. // Le Sac du Veilleur n'apparaît que s'il contient des objets. const bag = partner.getByRole("region", { name: "Sac du Veilleur", exact: true }); if (await bag.count()) await expect(bag.getByRole("listitem").first()).toBeVisible(); await expect(partner.getByRole("form", { name: "Éclats d’étoile" })).toHaveCount(0); await partner.goto("/#/cards/shop"); const bridge = partner.getByRole("form", { name: "Éclats d’étoile" }); await expect(bridge).toContainText("L’échange est définitif."); await bridge.getByRole("spinbutton", { name: "Éclats à obtenir" }).fill("2"); // Le bouton pleine largeur porte le coût total. await bridge.getByRole("button", { name: "Convertir · 6 poussières", exact: true }).click(); await expect(partner.getByRole("status").filter({ hasText: "+2 Éclats d’étoile !" })).toBeVisible(); await expect(partner.locator(".nebula-shop-wallet")).toContainText("Vos Éclats d’étoile"); // Un achat d'un autre article fait baisser le maximum : la quantité d'Éclats saisie y est ramenée. const eclatsItem = partner.locator('.nebula-shop-item[data-item="eclats"]'); const eclatsCount = eclatsItem.getByRole("spinbutton", { name: "Éclats à obtenir", exact: true }); const maxOf = async (item) => Number((await item.getByRole("spinbutton").getAttribute("placeholder")).replace(/\D/g, "")); await eclatsCount.fill("100000"); const eclatsMax = await maxOf(eclatsItem); await expect(eclatsCount).toHaveValue(String(eclatsMax)); await partner.locator('.nebula-shop-item[data-item="opening"]').getByRole("button", { name: /^Acheter · / }).click(); await expect(partner.getByRole("status").filter({ hasText: "Ouverture achetée" })).toBeVisible(); const eclatsMaxAfter = await maxOf(eclatsItem); expect(eclatsMaxAfter).toBeLessThan(eclatsMax); await expect(eclatsCount).toHaveValue(String(eclatsMaxAfter)); await partner.goto("/#/cards/collection"); await partner.getByRole("button", { name: "Voir Loup des Aurores", exact: true }).first().click(); // La fiche résume la carte pour les Expéditions (Puissance, niveau, expérience, stats), puis l'amélioration et le plan ; // l'équipement se règle depuis les Expéditions. // Depuis la collection, la fiche s'ouvre sur « La carte » ; l'amélioration est dans son second onglet. const sheet = partner.getByRole("dialog"); await expect(sheet.getByRole("tab", { name: "La carte", exact: true })).toHaveAttribute("aria-selected", "true"); await expect(sheet.getByRole("tabpanel")).toContainText("Exemplaires possédés"); await sheet.getByRole("tab", { name: "Amélioration", exact: true }).click(); const summary = sheet.getByRole("region", { name: "Récapitulatif pour les Expéditions", exact: true }); await expect(summary).toContainText("Niveau 0 / 6"); await expect(summary.locator(".nebula-card-summary-power strong")).toHaveText("70"); await expect(summary.getByRole("progressbar", { name: "Expérience", exact: true })).toHaveAttribute("aria-valuenow", "10"); await expect(summary.getByRole("list", { name: "Stats", exact: true }).getByRole("listitem")).toHaveCount(4); await expect(sheet.getByRole("region", { name: "Améliorer", exact: true }).getByRole("button", { name: /^Améliorer · 70 Éclats$/ })).toBeVisible(); await expect(sheet.getByRole("heading", { name: "Équipements", exact: true })).toHaveCount(0); // Une légendaire franchit ses paliers d'Éveil à 85 puis 100 : l'amélioration annonce le prochain. await expect(sheet.getByRole("region", { name: "Améliorer", exact: true })).toContainText("Améliorez de préférence avec les Éclats : vos doublons pourront servir à l’Éveil de votre carte (prochain Éveil : Puissance\u00a085)."); await sheet.getByRole("region", { name: "Améliorer", exact: true }).screenshot({ path: join(tmpdir(), "sokkog-cards-upgrade-tip.png") }); await partner.keyboard.press("Escape"); // Devant le palier (Puissance 80), l'Éveil remplace l'amélioration aux Éclats : le joueur a un doublon du Loup, qui l'éveillerait. const { path: progressDatabasePath } = JSON.parse(await readFile(join(tmpdir(), "sokkog-cards-e2e-db.json"), "utf8")); const setWolfLevel = (level) => { const progressDatabase = new DatabaseSync(progressDatabasePath); progressDatabase.prepare("UPDATE card_progress SET level = ? WHERE edition_id = 'aurora-wolf-standard' AND player_id = (SELECT id FROM players WHERE discord_id = 'e2e-partner')").run(level); progressDatabase.close(); }; setWolfLevel(2); await partner.reload(); await partner.getByRole("button", { name: "Voir Loup des Aurores", exact: true }).first().click(); await sheet.getByRole("tab", { name: "Amélioration", exact: true }).click(); await expect(summary).toContainText("Éveil nécessaire pour atteindre la Puissance\u00a085"); const awakening = sheet.getByRole("region", { name: "Éveil · Puissance\u00a085", exact: true }); await expect(awakening.getByRole("button", { name: "Éveiller avec un doublon", exact: true })).toBeEnabled(); await expect(awakening).toContainText(/Doublons légendaires de .+ disponibles : 1 sur 1\./); await expect(sheet.getByRole("region", { name: "Améliorer", exact: true })).toHaveCount(0); await awakening.screenshot({ path: join(tmpdir(), "sokkog-cards-awakening.png") }); // Les doublons de la collection se choisissent en cartes illustrées, comme à l'atelier ; rien n'est utilisé avant « Éveiller ». await awakening.getByRole("button", { name: "Choisir 1 doublon légendaire", exact: true }).click(); const awakeningPicker = partner.getByRole("dialog", { name: /^Éveil de Loup des Aurores/ }); const awakenButton = awakeningPicker.getByRole("button", { name: "Éveiller", exact: true }); await expect(awakeningPicker.getByRole("heading", { name: "Votre sélection (0/1)", exact: true })).toBeVisible(); await expect(awakenButton).toBeDisabled(); const candidates = awakeningPicker.getByRole("list", { name: "Vos doublons utilisables", exact: true }).getByRole("listitem"); await expect(candidates).toHaveCount(1); await candidates.first().getByRole("button", { name: /^Ajouter .+ à la sélection$/ }).click(); await expect(awakeningPicker.getByRole("heading", { name: "Votre sélection (1/1)", exact: true })).toBeVisible(); await expect(awakenButton).toBeEnabled(); await awakeningPicker.screenshot({ path: join(tmpdir(), "sokkog-cards-awakening-picker.png") }); await awakeningPicker.getByRole("button", { name: "Annuler", exact: true }).click(); await expect(awakeningPicker).toHaveCount(0); await partner.keyboard.press("Escape"); // La suite du parcours reprend le Loup au niveau 0. setWolfLevel(0); await partner.reload(); // Le recyclage en masse s'arrête à une rareté choisie : son menu, sous l'intitulé, s'ouvre en entier au-dessus de l'album. const recycleBox = partner.getByRole("region", { name: "Recyclage des doublons", exact: true }); const rarityTrigger = selectTrigger(recycleBox, "Jusqu’à la rareté"); await expect(rarityTrigger).toHaveText("Commun"); const [labelBox, triggerBox] = await Promise.all([recycleBox.locator(".nds-select-field > span").boundingBox(), rarityTrigger.boundingBox()]); expect(triggerBox.y).toBeGreaterThan(labelBox.y + labelBox.height - 1); await rarityTrigger.click(); await expectOpenMenuVisible(partner, ".nebula-recycle-box .nds-select-menu"); // Ouvert vers le bas, sur le texte et les boutons de l'encart : chaque option reste devant eux. await partner.keyboard.press("Escape"); await partner.setViewportSize({ width: 1280, height: 1500 }); await rarityTrigger.click(); await expectOpenOptionsOnTop(partner, ".nebula-recycle-box .nds-select-menu"); await partner.screenshot({ path: join(tmpdir(), "sokkog-cards-recycle-rarity.png") }); await recycleBox.getByRole("option", { name: "Légendaire", exact: true }).click(); await expect(rarityTrigger).toHaveText("Légendaire"); // La confirmation nomme les raretés recyclées et ne montre que leur valeur. await recycleBox.getByRole("button", { name: "Recycler", exact: true }).click(); const recycleConfirm = partner.getByRole("dialog", { name: /^Recycler \d+ doublons? \?$/ }); await expect(recycleConfirm).toContainText(/Vos doublons communs, rares, épiques et légendaires deviennent \d+ poussières? d’étoiles\./); await expect(recycleConfirm.locator(".nds-inline-notice[data-variant=warning]")).toHaveText("Vos doublons rares, épiques et légendaires servent aussi à éveiller vos cartes : gardez ceux dont vous aurez besoin."); await expect(recycleConfirm.getByRole("list", { name: "Poussière gagnée par doublon", exact: true }).getByRole("listitem")).toHaveText([/^Commun/, /^Rare/, /^Épique/, /^Légendaire/]); await recycleConfirm.screenshot({ path: join(tmpdir(), "sokkog-cards-recycle-confirm.png") }); await recycleConfirm.getByRole("button", { name: "Annuler", exact: true }).click(); await partner.setViewportSize({ width: 1280, height: 720 }); await partner.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Historique", exact: true }).click(); await expect(partner.locator(".nebula-history-list li").filter({ hasText: "Expédition terminée" })).toContainText("★ · 2 h"); // Alertes Discord : désactivées tant que le joueur ne les active pas, une par une. await partner.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Compte", exact: true }).click(); const alerts = partner.getByRole("region", { name: "Alertes Discord", exact: true }); const returnAlert = alerts.getByRole("button", { name: "Une de mes expéditions est de retour", exact: true }); await expect(returnAlert).toHaveAttribute("aria-pressed", "false"); await returnAlert.click(); await expect(returnAlert).toHaveAttribute("aria-pressed", "true"); await expect(alerts.getByRole("button", { name: "Un joueur ouvre un groupe d’expédition", exact: true })).toHaveAttribute("aria-pressed", "false"); await partnerContext.close(); // L'historique d'administration détaille le réglage ; on referme les Expéditions et on remet l'horloge. await page.goto("/#/cards/admin/history"); await expect(page.locator(".nds-list-row").filter({ hasText: "Expéditions modifiées" }).first()).toContainText("Expéditions ouvertes aux joueurs : non → oui"); await page.goto("/#/cards/admin/guild/expeditions"); await status.getByRole("button", { name: "Fermer les Expéditions", exact: true }).click(); await page.getByRole("dialog").getByRole("button", { name: "Fermer", exact: true }).click(); await expect(status).toContainText("Fermées aux joueurs"); await setServerClock(0); });