sokko-g/e2e/toolbox-list.spec.js

181 lines
9.3 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 : valide l’accès immédiat aux toolboxes et aux réglages locaux de la collection.
/* global document, Buffer */
import { expect, test } from "@playwright/test";
import { resetSokkoStorage } from "./helpers/storage.js";
function toolbox(id, name) {
return {
id,
name,
modules: [],
updatedAt: `2026-10-${String(Number(id.replace("toolbox-", "")) + 1).padStart(2, "0")}T10:00:00.000Z`
};
}
async function seedToolboxes(page, toolboxes, links = {}) {
await page.evaluate(async ({ nextToolboxes, nextLinks }) => {
const db = await import("/src/utils/indexedDbStorage.js");
await db.setToolboxSnapshot(nextToolboxes, nextLinks, {});
}, { nextToolboxes: toolboxes, nextLinks: links });
await page.reload();
}
test.beforeEach(async ({ page }) => {
await page.setViewportSize({ width: 768, height: 720 });
await resetSokkoStorage(page);
await page.goto("/#/toolboxes");
});
test("keeps the empty action clear and groups local data settings in one dialog", async ({ page }) => {
await expect(page.getByRole("heading", { name: "Aucune toolbox" })).toBeVisible();
await expect(page.getByRole("button", { name: "Créer ma première toolbox" })).toBeVisible();
const automaticBackup = page.locator(".sidebar-note").getByRole("button", { name: "Sauvegarde automatique" });
await expect(automaticBackup).toBeVisible();
await expect(automaticBackup).toHaveAttribute("data-variant", "primary");
await expect(page.locator(".sidebar-note").getByRole("button", { name: "Importer toutes les toolboxes" })).toBeVisible();
await expect(page.locator(".sidebar-note").getByRole("button", { name: "Exporter toutes les toolboxes" })).toHaveCount(0);
await expect(page.getByLabel("Budget recommandé de stockage local")).toBeVisible();
const individualImport = page.locator(".toolbox-list-hero").getByRole("button", { name: "Importer une toolbox" });
await expect(individualImport).toBeVisible();
await individualImport.focus();
const fileChooser = page.waitForEvent("filechooser");
await individualImport.press("Enter");
await fileChooser;
const managementTrigger = page.getByRole("button", { name: "Données et préférences" });
await managementTrigger.click();
const management = page.getByRole("dialog", { name: "Données et préférences" });
await expect(management).toBeVisible();
await expect(management.getByRole("radio", { checked: true })).toBeFocused();
await expect(management.getByRole("button", { name: "Importer tout" })).toBeVisible();
await expect(management.getByRole("radiogroup", { name: "Positionnement des alertes" })).toBeVisible();
const preferencesHeading = management.getByRole("heading", { name: "Positionnement des alertes" });
const transfersHeading = management.getByRole("heading", { name: "Transferts de la collection" });
const [preferencesBox, transfersBox] = await Promise.all([preferencesHeading.boundingBox(), transfersHeading.boundingBox()]);
expect(preferencesBox.y).toBeLessThan(transfersBox.y);
const storageDetails = management.getByText("Comprendre le stockage local", { exact: true });
await storageDetails.focus();
await storageDetails.press("Enter");
await expect(management.getByText(/Rien n’est envoyé sur un serveur/)).toBeVisible();
await page.keyboard.press("Escape");
await expect(management).toHaveCount(0);
await expect(managementTrigger).toBeFocused();
await page.setViewportSize({ width: 1280, height: 720 });
const backupLabel = page.locator(".sidebar-storage-action-label");
await expect(backupLabel).toBeVisible();
await expect(backupLabel).toHaveText("Sauvegarde auto");
await expect(automaticBackup).toHaveCSS("padding-left", "8px");
await expect(automaticBackup).toHaveCSS("padding-right", "8px");
const sidebarImport = page.locator(".sidebar-note").getByRole("button", { name: "Importer toutes les toolboxes" });
await expect(sidebarImport).toHaveText("");
await expect(automaticBackup.locator(".ui-icon")).toHaveCount(0);
await expect(sidebarImport.locator(".ui-icon")).toHaveCount(1);
const [noteBox, actionsBox, backupBox, importBox] = await Promise.all([
page.locator(".sidebar-note").boundingBox(),
page.locator(".sidebar-storage-actions").boundingBox(),
automaticBackup.boundingBox(),
sidebarImport.boundingBox()
]);
expect(actionsBox.width).toBeLessThan(noteBox.width - 16);
expect(importBox.x).toBeGreaterThan(backupBox.x + backupBox.width);
expect(importBox.y).toBeCloseTo(backupBox.y, 0);
expect(importBox.height).toBeCloseTo(backupBox.height, 0);
expect(backupBox.height).toBeCloseTo(34, 0);
expect(importBox.width).toBeCloseTo(34, 0);
});
test("uses the same hero height as the games page", async ({ page }) => {
const toolboxHeroHeight = (await page.locator(".toolbox-list-hero").boundingBox()).height;
await page.goto("/#/games");
const gamesHero = page.locator(".page-hero");
await expect(gamesHero).toBeVisible();
const gamesHeroHeight = (await gamesHero.boundingBox()).height;
expect(toolboxHeroHeight).toBeCloseTo(gamesHeroHeight, 0);
});
test("a global import confirms game reassignment before preserving both toolboxes", async ({ page }) => {
await seedToolboxes(page, [toolbox("toolbox-1", "Existante")], { mhwilds: "toolbox-1" });
const payload = {
version: 2,
exportedAt: "2026-10-15T10:00:00.000Z",
toolboxes: [{
id: "source",
name: "Importée",
modules: [],
spaces: [{ id: "default", name: "Défaut", moduleOrder: { one: [], two: [[], []] } }],
defaultSpaceId: "default",
activeSpaceId: "default"
}],
links: { mhwilds: "source" },
modules: {}
};
const importButton = page.locator(".sidebar-note").getByRole("button", { name: "Importer toutes les toolboxes" });
await importButton.locator('input[type="file"]').setInputFiles({
name: "collection.sokkog.json",
mimeType: "application/json",
buffer: Buffer.from(JSON.stringify(payload))
});
const confirmation = page.getByRole("dialog", { name: "Réattribuer des associations de jeu ?" });
await expect(confirmation).toContainText("associations de jeu existantes (1)");
expect(await page.evaluate(async () => (await import("/src/utils/indexedDbStorage.js")).getLinks())).toEqual({ mhwilds: "toolbox-1" });
await confirmation.getByRole("button", { name: "Importer et réattribuer" }).click();
await expect(page.locator(".toolbox-card")).toHaveCount(2);
await expect(page.getByRole("heading", { name: "Existante" })).toBeVisible();
await expect(page.getByRole("heading", { name: "Importée (import)" })).toBeVisible();
const stored = await page.evaluate(async () => (await import("/src/utils/indexedDbStorage.js")).getToolboxSnapshot());
expect(stored.toolboxes.some((item) => item.id === "toolbox-1")).toBe(true);
expect(stored.links.mhwilds).not.toBe("toolbox-1");
});
test("shows one long game-linked toolbox name and its open action without scrolling", async ({ page }) => {
const longName = "Toolbox de préparation extrêmement longue pour la prochaine expédition coopérative";
await seedToolboxes(page, [toolbox("toolbox-1", longName)], { mhwilds: "toolbox-1" });
const card = page.locator(".toolbox-card");
const name = card.getByRole("heading", { name: longName });
const open = card.getByRole("link", { name: `Ouvrir ${longName}` }).first();
await expect(name).toBeVisible();
await expect(open).toBeVisible();
await expect(card.getByText(/Monster Hunter.*Wilds/)).toBeVisible();
const [nameBox, openBox] = await Promise.all([name.boundingBox(), open.boundingBox()]);
expect(nameBox.y + nameBox.height).toBeLessThanOrEqual(720);
expect(openBox.y + openBox.height).toBeLessThanOrEqual(720);
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(768);
});
test("renders ten toolboxes without overflow and persists card reordering", async ({ page }) => {
const toolboxes = Array.from({ length: 10 }, (_, index) => toolbox(
`toolbox-${index + 1}`,
`Collection ${index + 1} — préparation détaillée avec un nom volontairement très long`
));
await seedToolboxes(page, toolboxes, { mhwilds: "toolbox-1", diablo4: "toolbox-2" });
const cards = page.locator(".toolbox-card");
await expect(cards).toHaveCount(10);
await expect(page.locator(".toolbox-collection-heading .nds-badge")).toHaveText("10");
const [titleBox, badgeBox] = await Promise.all([
page.getByRole("heading", { name: "Mes toolboxes" }).boundingBox(),
page.locator(".toolbox-collection-heading .nds-badge").boundingBox()
]);
expect(badgeBox.x).toBeGreaterThanOrEqual(titleBox.x + titleBox.width);
expect(badgeBox.x - (titleBox.x + titleBox.width)).toBeLessThanOrEqual(12);
expect(await page.evaluate(() => document.documentElement.scrollWidth)).toBeLessThanOrEqual(768);
const sourceHandle = cards.nth(0).getByRole("button", { name: /Déplacer Collection 1/ });
const target = cards.nth(1);
const [sourceBox, targetBox] = await Promise.all([sourceHandle.boundingBox(), target.boundingBox()]);
await page.mouse.move(sourceBox.x + sourceBox.width / 2, sourceBox.y + sourceBox.height / 2);
await page.mouse.down();
await page.mouse.move(targetBox.x + targetBox.width * 0.8, targetBox.y + targetBox.height / 2, { steps: 8 });
await page.mouse.up();
await expect(cards.nth(0).getByRole("heading")).toHaveText(/Collection 2/);
await page.reload();
await expect(cards.nth(0).getByRole("heading")).toHaveText(/Collection 2/);
});