|
| 1 | +/** |
| 2 | + * Copyright 2025 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 | +import AxeBuilder from '@axe-core/playwright'; |
| 15 | +import { gotoStory } from '../../../../2nd-gen/test/a11y-helpers.js'; |
| 16 | + |
| 17 | +/** |
| 18 | + * Accessibility tests for Badge component |
| 19 | + * |
| 20 | + * Tests both ARIA snapshot structure and aXe WCAG compliance |
| 21 | + */ |
| 22 | + |
| 23 | +test.describe('Badge - ARIA Snapshots', () => { |
| 24 | + test('should have correct accessibility tree for default badge', async ({ |
| 25 | + page, |
| 26 | + }) => { |
| 27 | + const badge = await gotoStory(page, 'badge--default', 'sp-badge'); |
| 28 | + const snapshot = await badge.ariaSnapshot(); |
| 29 | + |
| 30 | + expect(snapshot).toBeTruthy(); |
| 31 | + await expect(badge).toMatchAriaSnapshot(); |
| 32 | + }); |
| 33 | + |
| 34 | + test('should handle badge with icon', async ({ page }) => { |
| 35 | + const badge = await gotoStory(page, 'badge--icons', 'sp-badge'); |
| 36 | + const snapshot = await badge.ariaSnapshot(); |
| 37 | + |
| 38 | + expect(snapshot).toBeTruthy(); |
| 39 | + }); |
| 40 | + |
| 41 | + test('should maintain accessibility with semantic variants', async ({ |
| 42 | + page, |
| 43 | + }) => { |
| 44 | + await gotoStory(page, 'badge--semantic', 'sp-badge'); |
| 45 | + const badges = page.locator('sp-badge'); |
| 46 | + |
| 47 | + const count = await badges.count(); |
| 48 | + expect(count).toBeGreaterThan(0); |
| 49 | + |
| 50 | + // Verify each badge is accessible |
| 51 | + for (let i = 0; i < count; i++) { |
| 52 | + const badge = badges.nth(i); |
| 53 | + const snapshot = await badge.ariaSnapshot(); |
| 54 | + expect(snapshot).toBeTruthy(); |
| 55 | + } |
| 56 | + }); |
| 57 | +}); |
| 58 | + |
| 59 | +test.describe('Badge - aXe Validation', () => { |
| 60 | + test('should not have accessibility violations - default', async ({ |
| 61 | + page, |
| 62 | + }) => { |
| 63 | + await gotoStory(page, 'badge--default', 'sp-badge'); |
| 64 | + |
| 65 | + const results = await new AxeBuilder({ page }) |
| 66 | + .withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']) |
| 67 | + .analyze(); |
| 68 | + |
| 69 | + expect(results.violations).toEqual([]); |
| 70 | + }); |
| 71 | + |
| 72 | + test('should not have violations - semantic variants', async ({ page }) => { |
| 73 | + await gotoStory(page, 'badge--semantic', 'sp-badge'); |
| 74 | + |
| 75 | + const results = await new AxeBuilder({ page }) |
| 76 | + .withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']) |
| 77 | + .analyze(); |
| 78 | + |
| 79 | + expect(results.violations).toEqual([]); |
| 80 | + }); |
| 81 | + |
| 82 | + test('should not have violations - with icon', async ({ page }) => { |
| 83 | + await gotoStory(page, 'badge--icons', 'sp-badge'); |
| 84 | + |
| 85 | + const results = await new AxeBuilder({ page }) |
| 86 | + .withTags(['wcag2a', 'wcag2aa', 'wcag21a', 'wcag21aa']) |
| 87 | + .analyze(); |
| 88 | + |
| 89 | + expect(results.violations).toEqual([]); |
| 90 | + }); |
| 91 | + |
| 92 | + test('should verify color contrast', async ({ page }) => { |
| 93 | + await gotoStory(page, 'badge--semantic', 'sp-badge'); |
| 94 | + |
| 95 | + const results = await new AxeBuilder({ page }) |
| 96 | + .withRules(['color-contrast']) |
| 97 | + .analyze(); |
| 98 | + |
| 99 | + expect(results.violations).toEqual([]); |
| 100 | + }); |
| 101 | +}); |
0 commit comments