|
| 1 | +/** |
| 2 | + * Copyright 2026 Adobe. All rights reserved. |
| 3 | + * This file is licensed to you under the Apache License, Version 2.0 (the "License"); |
| 4 | + * you may not use this file except in compliance with the License. You may obtain a copy |
| 5 | + * of the License at http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under |
| 8 | + * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS |
| 9 | + * OF ANY KIND, either express or implied. See the License for the specific language |
| 10 | + * governing permissions and limitations under the License. |
| 11 | + */ |
| 12 | + |
| 13 | +import { expect, test } from '@playwright/test'; |
| 14 | + |
| 15 | +import { gotoStory } from '../../../utils/a11y-helpers.js'; |
| 16 | + |
| 17 | +/** |
| 18 | + * Accessibility tests for the Drop Zone component (2nd generation). |
| 19 | + * |
| 20 | + * ARIA snapshot tests validate accessibility tree structure for each significant |
| 21 | + * state. aXe WCAG compliance and color contrast checks are run separately via |
| 22 | + * test-storybook (see .storybook/test-runner.ts). Both are included in `test:a11y`. |
| 23 | + */ |
| 24 | + |
| 25 | +test.describe('Drop Zone - ARIA snapshots', () => { |
| 26 | + test('default drop zone has correct group role and accessible name', async ({ |
| 27 | + page, |
| 28 | + }) => { |
| 29 | + const root = await gotoStory( |
| 30 | + page, |
| 31 | + 'components-drop-zone--overview', |
| 32 | + 'swc-dropzone' |
| 33 | + ); |
| 34 | + await expect(root).toMatchAriaSnapshot(` |
| 35 | + - group "Upload files": |
| 36 | + - heading "Drag and drop your file" [level=2] |
| 37 | + - button "Browse files" |
| 38 | + `); |
| 39 | + }); |
| 40 | + |
| 41 | + test('dragged drop zone announces "File ready to drop" via status region', async ({ |
| 42 | + page, |
| 43 | + }) => { |
| 44 | + const root = await gotoStory( |
| 45 | + page, |
| 46 | + 'components-drop-zone--states', |
| 47 | + 'swc-dropzone' |
| 48 | + ); |
| 49 | + const draggedDropzone = root |
| 50 | + .locator('swc-dropzone[dragged]:not([filled])') |
| 51 | + .first(); |
| 52 | + await expect(draggedDropzone).toMatchAriaSnapshot(` |
| 53 | + - group "Dragged drop zone": |
| 54 | + - status: File ready to drop |
| 55 | + - heading "Drop file to upload" [level=2] |
| 56 | + - button "Browse files" |
| 57 | + `); |
| 58 | + }); |
| 59 | + |
| 60 | + test('filled drop zone announces "File accepted" via status region', async ({ |
| 61 | + page, |
| 62 | + }) => { |
| 63 | + const root = await gotoStory( |
| 64 | + page, |
| 65 | + 'components-drop-zone--states', |
| 66 | + 'swc-dropzone' |
| 67 | + ); |
| 68 | + const filledDropzone = root |
| 69 | + .locator('swc-dropzone[filled]:not([dragged])') |
| 70 | + .first(); |
| 71 | + await expect(filledDropzone).toMatchAriaSnapshot(` |
| 72 | + - group "Filled drop zone": |
| 73 | + - status: File accepted |
| 74 | + `); |
| 75 | + }); |
| 76 | + |
| 77 | + test('filled-and-dragged drop zone announces "Drop to replace existing file"', async ({ |
| 78 | + page, |
| 79 | + }) => { |
| 80 | + const root = await gotoStory( |
| 81 | + page, |
| 82 | + 'components-drop-zone--states', |
| 83 | + 'swc-dropzone' |
| 84 | + ); |
| 85 | + const filledAndDraggedDropzone = root |
| 86 | + .locator('swc-dropzone[filled][dragged]') |
| 87 | + .first(); |
| 88 | + await expect(filledAndDraggedDropzone).toMatchAriaSnapshot(` |
| 89 | + - group "Filled and dragged drop zone": |
| 90 | + - status: Drop to replace existing file |
| 91 | + `); |
| 92 | + }); |
| 93 | + |
| 94 | + test('host element is not keyboard focusable', async ({ page }) => { |
| 95 | + const root = await gotoStory( |
| 96 | + page, |
| 97 | + 'components-drop-zone--overview', |
| 98 | + 'swc-dropzone' |
| 99 | + ); |
| 100 | + const dropzone = root.locator('swc-dropzone'); |
| 101 | + await expect(dropzone).not.toBeFocused(); |
| 102 | + // Tab once — focus should not land on the host. |
| 103 | + await page.keyboard.press('Tab'); |
| 104 | + await expect(dropzone).not.toBeFocused(); |
| 105 | + }); |
| 106 | + |
| 107 | + test('browse button is the first keyboard-focusable element', async ({ |
| 108 | + page, |
| 109 | + }) => { |
| 110 | + const root = await gotoStory( |
| 111 | + page, |
| 112 | + 'components-drop-zone--overview', |
| 113 | + 'swc-dropzone' |
| 114 | + ); |
| 115 | + const browseButton = root.locator('swc-button'); |
| 116 | + await page.keyboard.press('Tab'); |
| 117 | + await expect(browseButton).toBeFocused(); |
| 118 | + }); |
| 119 | +}); |
0 commit comments