// Rôle : couvre les parcours navigateur principaux des toolboxes locales. import { expect, test } from "@playwright/test"; import path from "node:path"; import { fileURLToPath } from "node:url"; import { resetSokkoStorage } from "./helpers/storage.js"; const __dirname = path.dirname(fileURLToPath(import.meta.url)); const fixturePath = path.join(__dirname, "fixtures", "toolbox-export.json"); async function createToolbox(page, name) { await page.goto("/#/toolboxes"); await expect(page.getByRole("main")).toBeVisible(); await page.getByRole("button", { name: "Nouvelle toolbox" }).click(); const dialog = page.getByRole("dialog", { name: "Nouvelle toolbox" }); await expect(dialog).toBeVisible(); await dialog.getByLabel("Nom").fill(name); await dialog.getByRole("button", { name: "Créer" }).click(); await expect(page.getByRole("heading", { name })).toBeVisible(); } async function addTool(page, name) { await page.getByRole("button", { name: "Ajouter un outil", exact: true }).click(); const addDialog = page.getByRole("dialog", { name: "Ajouter un outil" }); await expect(addDialog).toBeVisible(); await addDialog.getByRole("button", { name }).click(); } test.beforeEach(async ({ page }) => { await resetSokkoStorage(page); }); test("creates a toolbox and lazy-loads an added tool", async ({ page }) => { await createToolbox(page, "E2E Toolbox"); await expect(page.getByRole("heading", { name: "E2E Toolbox" })).toBeVisible(); await expect(page.locator("[data-module-type='notepad']")).toBeVisible(); await expect(page.locator("[data-module-type='links']")).toBeVisible(); await addTool(page, "Arbre d'objectifs"); await expect(page.locator("[data-module-type='goalTree']")).toBeVisible(); }); test("creates, edits and deletes a weekly calendar event", async ({ page }) => { await createToolbox(page, "Calendar E2E Toolbox"); await addTool(page, "Calendrier"); const calendar = page.locator("[data-module-type='calendar']"); await expect(calendar).toBeVisible(); await calendar.getByRole("button", { name: "Hebdomadaire" }).click(); await expect(calendar.locator(".calendar-week-grid")).toBeVisible(); await calendar.getByRole("button", { name: /Afficher l'ajout de Calendrier/ }).click(); await calendar.getByLabel("Titre").fill("Raid E2E"); await calendar.getByRole("textbox", { name: "Début" }).fill("18:00"); await calendar.getByRole("textbox", { name: "Fin" }).fill("20:00"); await calendar.getByRole("button", { name: "Ajouter" }).click(); await expect(calendar.getByRole("button", { name: /Raid E2E/ })).toBeVisible(); await calendar.getByRole("button", { name: /Raid E2E/ }).click(); await calendar.getByLabel("Titre").fill("Raid E2E modifié"); await calendar.getByRole("button", { name: "Enregistrer" }).click(); await expect(calendar.getByRole("button", { name: /Raid E2E modifié/ })).toBeVisible(); await expect(calendar.getByRole("button", { name: /Raid E2E$/ })).toHaveCount(0); await calendar.getByRole("button", { name: /Raid E2E modifié/ }).click(); await calendar.getByRole("button", { name: "Supprimer" }).click(); await expect(calendar.getByRole("button", { name: /Raid E2E modifié/ })).toHaveCount(0); }); test("creates a game-linked toolbox from the drawer", async ({ page }) => { await page.goto("/#/games/mhwilds"); await expect(page.getByRole("heading", { name: /Monster Hunter.*Wilds/ })).toBeVisible(); await page.getByRole("button", { name: "Associer une toolbox" }).click(); const drawer = page.locator("#toolbox-drawer .drawer-panel"); await expect(drawer).toBeVisible(); await drawer.getByRole("button", { name: "Créer et associer" }).click(); const dialog = page.getByRole("dialog", { name: "Créer et associer une toolbox" }); await expect(dialog.getByLabel("Nom")).toHaveValue(/Monster Hunter.*Wilds/); await dialog.getByRole("button", { name: "Créer" }).click(); await expect(drawer.getByRole("heading", { name: /Monster Hunter.*Wilds/ })).toBeVisible(); await expect(drawer.locator("[data-module-type='notepad']")).toBeVisible(); await expect(page.getByRole("button", { name: /Ouvrir la toolbox Monster Hunter.*Wilds/ })).toBeVisible(); }); test("imports and exports a toolbox payload", async ({ page }) => { await page.goto("/#/toolboxes"); await expect(page.getByRole("main")).toBeVisible(); await page.getByText("Importer une toolbox").locator("input[type='file']").setInputFiles(fixturePath); await expect(page.getByRole("link", { name: "Ouvrir Fixture Toolbox" }).first()).toBeVisible(); const downloadPromise = page.waitForEvent("download"); await page.getByRole("button", { name: "Exporter Fixture Toolbox" }).click(); const download = await downloadPromise; expect(download.suggestedFilename()).toBe("fixture-toolbox.sokkog.json"); });