/** * @file Vérifie au clavier le focus, l'arrière-plan et la restitution des modales communes. */ import { expect, test } from "@playwright/test"; import { resetSokkoStorage } from "./helpers/storage.js"; test("common modals trap focus, close with Escape and restore their trigger at compact desktop size", async ({ page }) => { await page.setViewportSize({ width: 768, height: 720 }); await resetSokkoStorage(page); await page.goto("/#/toolboxes"); const createTrigger = page.getByRole("button", { name: "Nouvelle toolbox", exact: true }); await createTrigger.click(); let dialog = page.getByRole("dialog", { name: "Nouvelle toolbox", exact: true }); const nameInput = dialog.getByLabel("Nom"); await expect(nameInput).toBeFocused(); await expect(page.locator("#app")).toHaveAttribute("inert", ""); await expect(page.locator("#app")).toHaveAttribute("aria-hidden", "true"); const createButton = dialog.getByRole("button", { name: "Créer", exact: true }); await createButton.focus(); await page.keyboard.press("Tab"); await expect(nameInput).toBeFocused(); await page.keyboard.press("Shift+Tab"); await expect(createButton).toBeFocused(); await page.keyboard.press("Escape"); await expect(dialog).toHaveCount(0); await expect(createTrigger).toBeFocused(); await expect(page.locator("#app")).not.toHaveAttribute("inert", ""); await expect(page.locator("#app")).not.toHaveAttribute("aria-hidden", "true"); await createTrigger.click(); dialog = page.getByRole("dialog", { name: "Nouvelle toolbox", exact: true }); await dialog.getByLabel("Nom").fill("Clavier E2E"); await dialog.getByRole("button", { name: "Créer", exact: true }).click(); const addTrigger = page.getByRole("button", { name: "Ajouter un outil", exact: true }); await addTrigger.click(); dialog = page.getByRole("dialog", { name: "Ajouter un outil", exact: true }); const firstTool = dialog.locator(".tool-add-card").first(); const lastTool = dialog.locator(".tool-add-card").last(); const closeButton = dialog.getByRole("button", { name: "Fermer", exact: true }); await expect(firstTool).toBeFocused(); await closeButton.focus(); await page.keyboard.press("Shift+Tab"); await expect(lastTool).toBeFocused(); await page.keyboard.press("Tab"); await expect(closeButton).toBeFocused(); await page.keyboard.press("Escape"); await expect(dialog).toHaveCount(0); await expect(addTrigger).toBeFocused(); await page.goto("/#/toolboxes"); const deleteTrigger = page.getByRole("button", { name: "Supprimer Clavier E2E", exact: true }); await deleteTrigger.click(); dialog = page.getByRole("dialog", { name: "Supprimer la toolbox", exact: true }); await expect(dialog.getByRole("button", { name: "Annuler", exact: true })).toBeFocused(); await expect(dialog.getByRole("button", { name: "Supprimer", exact: true })).not.toBeFocused(); await page.keyboard.press("Escape"); await expect(dialog).toHaveCount(0); await expect(deleteTrigger).toBeFocused(); await expect(page.locator("body")).not.toHaveCSS("overflow-y", "hidden"); });