// Rôle : valide l'ouverture, la reprise, l'album et l'administration de Sokko TCG.
import { readFile } from "node:fs/promises";
import { tmpdir } from "node:os";
import { join } from "node:path";
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/;
// 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 });
}
// 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.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?.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);
expect(await page.locator(".nebula-home").evaluate((element) => element.getBoundingClientRect().bottom <= element.ownerDocument.defaultView.innerHeight + 1)).toBe(true);
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();
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);
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();
const revealedNames = await revealedCards.evaluateAll((cards) => cards.map((card) => card.getAttribute("aria-label").replace(/ révélée$/, "")));
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 réserve occupe un tiers de la largeur et le meilleur tirage les deux tiers.
const homeReserveWidth = await page.locator(".nebula-home-grid .nebula-opening-reserve").evaluate((element) => element.getBoundingClientRect().width);
const homeRarestWidth = await page.locator(".nebula-home-rarest").evaluate((element) => element.getBoundingClientRect().width);
expect(homeRarestWidth / homeReserveWidth).toBeCloseTo(2, 0);
// 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);
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 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");
await expect(page.getByRole("navigation", { name: "Sections de Sokko TCG" }).getByRole("link", { name: "Collection", exact: true })).toHaveAttribute("aria-current", "page");
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);
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?.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"]);
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 3 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");
const navigation = page.getByRole("navigation", { name: "Sections de l’administration" });
await expect(navigation.getByRole("link")).toHaveText(["Vue d’ensemble", "Collections", "Codes cadeaux", "Boutique", "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");
await page.setViewportSize({ width: 768, height: 720 });
expect(await navigation.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true);
expect(await navigation.getByRole("link").evaluateAll((links) => new Set(links.map((link) => Math.round(link.getBoundingClientRect().top))).size)).toBe(1);
for (const link of await navigation.getByRole("link").all()) await expect(link).toBeInViewport();
await noOverflow();
await page.goto("/#/cards/admin/players");
await expect(navigation.getByRole("link", { name: "Vue d’ensemble" })).toHaveAttribute("aria-current", "page");
await expect(players).toBeVisible();
await page.goto("/#/cards/admin/collections");
await expect(navigation.getByRole("link", { name: "Collections" })).toHaveAttribute("aria-current", "page");
const collectionTiles = page.locator(".nebula-admin-collection-tile");
await expect(collectionTiles).toHaveCount(3);
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(["10cartes", "11variations", "1mythique tirable"]);
await expect(genesisTile.locator(".nebula-admin-rarity-counts b")).toHaveText(["4", "3", "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(navigation.getByRole("link", { name: "Collections" })).toHaveAttribute("aria-current", "page");
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.
await page.evaluate(() => new Promise((done) => globalThis.requestAnimationFrame(() => globalThis.requestAnimationFrame(done))));
expect(await 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 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"]);
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 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 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 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 expect(epicSurface.locator(".nebula-card-particles i")).toHaveCount(18);
await expect(epicSurface.locator(".nebula-card-particles i").first()).toHaveCSS("animation-name", "nebula-particle");
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 legendaryCard.click();
await expect(legendarySurface).toHaveAttribute("data-reveal-phase", "aura");
await expect(legendarySurface).toHaveCSS("--opening-aura", "#f6c453");
await expect(legendarySurface.locator(".nebula-card-particles i")).toHaveCount(32);
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 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");
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 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 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 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 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(navigation.getByRole("link", { name: "Collections" })).toHaveAttribute("aria-current", "page");
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");
await noOverflow();
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 (4 à 24 caractères)")).toHaveValue(/^[2-9A-HJKMNP-Z]{4}-[2-9A-HJKMNP-Z]{4}$/);
await campaignForm.getByLabel("Code à annoncer (4 à 24 caractères)").fill("dragon");
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, 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 Booster 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 (4 à 24 caractères)").fill("e2e live");
await expect(campaignForm.getByLabel("Code à annoncer (4 à 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 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 Booster 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();
});
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: "sokkog_cards_session", value: token, url: "http://127.0.0.1:4180" }]);
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 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");
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");
await page.locator(".nebula-privacy-details summary").click();
await expect(page.locator(".nebula-privacy-details").getByRole("link", { name: "privacy@example.invalid" })).toHaveAttribute("href", "mailto:privacy@example.invalid");
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: "sokkog_cards_session", value: token, url: "http://127.0.0.1:4180" }]);
const { traders } = await (await partnerContext.request.get("/api/cards/traders")).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);
});