sokko-g/e2e/aniimo-elements.spec.js
Shinuwa 9a4de4a23d Hide the redundant Aniimo skill heading for a single selection
The skill heading only helps tell two selected elements apart, so it now shows
for double selections alone.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 19:26:49 +01:00

97 lines
6.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Rôle : vérifie les groupes d'affinités Aniimo, leurs libellés et la sélection au clavier aux largeurs bureau.
import { test, expect } from "@playwright/test";
for (const width of [768, 1440]) {
test(`element guide supports single and dual types at ${width}px`, async ({ page }) => {
// Le premier parcours comprend la compilation à froid des pages de jeu par Vite.
test.setTimeout(60000);
await page.setViewportSize({ width, height: 1000 });
await page.goto("/#/games/aniimo");
const homeIcon = page.locator('a[href="#/games/aniimo/elements"] .aniimo-elements-home-icon');
await expect(homeIcon.locator("img")).toHaveCount(3);
const homeIconPositions = await homeIcon.locator("img").evaluateAll((images) => images.map((image) => ({ x: image.offsetLeft, y: image.offsetTop })));
expect(homeIconPositions).toEqual([{ x: 34, y: 0 }, { x: 68, y: 42 }, { x: 0, y: 42 }]);
await page.getByRole("link", { name: /Faiblesses et résistances/ }).click();
const picker = page.getByRole("group", { name: "Éléments de l’Aniimo" });
await expect(picker.getByRole("button")).toHaveCount(9);
await expect(picker).toHaveCSS("column-gap", "12px");
await expect(page.getByText("Sélectionnez un élément pour afficher ses affinités.")).toBeVisible();
const water = picker.getByRole("button", { name: "Eau", exact: true });
await water.focus();
await page.keyboard.press("Enter");
await expect(water).toHaveAttribute("aria-pressed", "true");
const attack = page.getByRole("region", { name: "En attaque" });
const defense = page.getByRole("region", { name: "En défense" });
await expect(attack).toHaveClass(/nds-panel/);
await expect(defense).toHaveClass(/nds-panel/);
const group = (panel, name) => panel.getByRole("region", { name, exact: true });
const waterAttack = attack.getByRole("region", { name: /Compétence.*Eau/ });
await expect(waterAttack.locator(".aniimo-skill-heading")).toHaveCount(0);
await expect(group(waterAttack, "Efficace")).toContainText("×1,6");
await expect(group(waterAttack, "Efficace").getByRole("listitem")).toHaveText(["Feu", "Roche"]);
await expect(group(defense, "Résistant")).toContainText("×0,625");
await expect(group(defense, "Résistant").getByRole("listitem")).toContainText(["Feu", "Eau", "Roche", "Ténèbres"]);
await expect(water.locator("img")).toHaveCSS("width", "48px");
await expect(waterAttack.locator("li img").first()).toHaveCSS("width", "24px");
const ice = picker.getByRole("button", { name: "Glace", exact: true });
await ice.focus();
await page.keyboard.press("Space");
await expect(ice).toHaveAttribute("aria-pressed", "true");
await expect(picker.getByRole("button", { name: "Feu", exact: true })).toBeDisabled();
const iceAttack = attack.getByRole("region", { name: /Compétence.*Glace/ });
const skillHeading = waterAttack.getByRole("heading", { level: 3, name: /Compétence.*Eau/ });
await expect(skillHeading).toHaveClass(/nds-section-heading/);
await expect(skillHeading).toHaveCSS("justify-content", "flex-start");
await expect(skillHeading).toHaveCSS("column-gap", "12px");
await expect(skillHeading.locator(".aniimo-skill-element")).toContainText("Eau");
await expect(iceAttack.locator(".aniimo-skill-heading")).toHaveCount(1);
await expect(group(waterAttack, "Efficace").getByRole("listitem")).toHaveText(["Feu", "Roche"]);
await expect(group(iceAttack, "Peu efficace")).toContainText("×0,625");
await expect(group(iceAttack, "Peu efficace").getByRole("listitem")).toHaveText(["Feu", "Roche", "Glace"]);
await expect(group(defense, "Dégâts normaux")).toContainText("×1");
await expect(group(defense, "Dégâts normaux").getByRole("listitem")).toHaveText(["Feu", "Électrique", "Roche", "Vent", "Glace", "Sacré"]);
expect(await group(defense, "Dégâts normaux").locator(".aniimo-matchup-members").evaluate((element) => globalThis.getComputedStyle(element).gridTemplateColumns.split(" ").length)).toBe(4);
await expect(group(defense, "Très résistant")).toContainText("×0,390625");
await expect(group(defense, "Très résistant").getByRole("listitem")).toHaveText(["Eau"]);
await expect(waterAttack.getByRole("listitem")).toHaveCount(9);
await expect(iceAttack.getByRole("listitem")).toHaveCount(9);
await expect(defense.getByRole("listitem")).toHaveCount(9);
expect(await page.evaluate(() => globalThis.document.documentElement.scrollWidth <= globalThis.innerWidth)).toBe(true);
for (const panel of [attack, defense]) {
expect(await panel.evaluate((element) => element.scrollWidth <= element.clientWidth)).toBe(true);
}
const resultColumns = await page.locator(".aniimo-matchup-panels").evaluate((element) => globalThis.getComputedStyle(element).gridTemplateColumns.split(" ").length);
expect(resultColumns).toBe(width === 1440 ? 2 : 1);
const groupColumns = await page.locator(".aniimo-matchup-groups").evaluateAll((groups) => groups.map((group) => ({
mode: group.dataset.mode,
columns: globalThis.getComputedStyle(group).gridTemplateColumns.split(" ").length,
heights: [...group.children].map((card) => Math.round(card.getBoundingClientRect().height)),
fits: [...group.children].every((card) => card.scrollHeight <= card.clientHeight)
})));
for (const groupLayout of groupColumns) {
expect(groupLayout.columns).toBe(3);
expect(Math.max(...groupLayout.heights)).toBeLessThan(244);
expect(groupLayout.fits).toBe(true);
}
await page.screenshot({ path: test.info().outputPath(`aniimo-elements-${width}.png`), fullPage: true });
await ice.click();
await expect(picker.getByRole("button", { name: "Feu", exact: true })).toBeEnabled();
await page.getByRole("button", { name: "Effacer la sélection" }).click();
await expect(attack).toHaveCount(0);
await expect(picker.getByRole("button", { pressed: true })).toHaveCount(0);
await picker.getByRole("button", { name: "Ténèbres", exact: true }).click();
await picker.getByRole("button", { name: "Herbe", exact: true }).click();
await expect(group(defense, "Très vulnérable")).toContainText("×2,56");
await expect(group(defense, "Très vulnérable").getByRole("listitem")).toHaveText(["Vent"]);
});
}
test("element chart loading failure can be retried on the direct guide route", async ({ page }) => {
let fail = true;
await page.route("**/data/aniimo/elements.json", (route) => fail ? route.fulfill({ status: 503, body: "unavailable" }) : route.continue());
await page.goto("/#/games/aniimo/elements");
await expect(page.getByRole("alert")).toContainText("Impossible de charger Aniimo");
fail = false;
await page.getByRole("button", { name: "Réessayer" }).click();
await expect(page.getByRole("group", { name: "Éléments de l’Aniimo" })).toBeVisible();
});