From 3fc0938aecc5a4007d37c0cc643692bad8aa8efc Mon Sep 17 00:00:00 2001 From: Richard R Date: Mon, 1 Jun 2026 14:33:37 -0600 Subject: [PATCH] test(accessibility): improve confirm dialog test coverage and refactor media state helper Expand accessibility tests for ConfirmDialog to assert dialog semantics, ARIA attributes, and visible destructive actions using test IDs. Refactor expectMediaState helper to check both UI control state and underlying media signals for more robust playback state detection. --- src/components/ConfirmDialog.tsx | 2 +- tests/accessibility.spec.ts | 12 ++++-- tests/helpers.ts | 63 ++++++++++++++++++-------------- 3 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/components/ConfirmDialog.tsx b/src/components/ConfirmDialog.tsx index 48e1439..8bdc0b9 100644 --- a/src/components/ConfirmDialog.tsx +++ b/src/components/ConfirmDialog.tsx @@ -30,7 +30,7 @@ export function ConfirmDialog({ }; return ( - + {title}

{message}

diff --git a/tests/accessibility.spec.ts b/tests/accessibility.spec.ts index 7bd3ba0..ed9580f 100644 --- a/tests/accessibility.spec.ts +++ b/tests/accessibility.spec.ts @@ -39,14 +39,18 @@ test.describe('Accessibility smoke', () => { // Open the confirm dialog by clicking the row delete button await page.getByRole('button', { name: /^Delete sample\.pdf$/i }).first().click(); - // Title and dialog role visible + // Title and dialog semantics are present const heading = page.getByRole('heading', { name: 'Delete Document' }); await expect(heading).toBeVisible({ timeout: 10000 }); - const dialog = heading.locator('xpath=ancestor::*[@role="dialog"][1]'); - await expect(dialog).toBeVisible(); + const dialog = page.getByRole('dialog', { name: 'Delete Document' }).first(); + await expect(dialog).toHaveAttribute('aria-modal', 'true'); + + // The visible panel content is rendered and includes destructive action + const panel = page.getByTestId('confirm-dialog-panel').first(); + await expect(panel).toBeVisible(); // Has a destructive action (Delete) - await expect(dialog.getByRole('button', { name: 'Delete' })).toBeVisible(); + await expect(panel.getByRole('button', { name: /^Delete$/ })).toBeVisible(); // Close with Escape to avoid deleting test data await page.keyboard.press('Escape'); diff --git a/tests/helpers.ts b/tests/helpers.ts index 8c19785..a8d2182 100644 --- a/tests/helpers.ts +++ b/tests/helpers.ts @@ -497,37 +497,44 @@ export async function expectProcessingTransition(page: Page) { // Expect navigator.mediaSession.playbackState to equal given state export async function expectMediaState(page: Page, state: 'playing' | 'paused') { - // WebKit (and sometimes other engines) may not reliably update navigator.mediaSession.playbackState. - // Fallback heuristics: - // 1. Prefer mediaSession if it matches desired state. - // 2. Otherwise inspect any