@@ -3,12 +3,29 @@ import { expect } from '@playwright/test';
3
3
import type { E2EPage } from '@utils/test/playwright' ;
4
4
import { test } from '@utils/test/playwright' ;
5
5
6
- const testAriaLabel = async ( page : E2EPage , buttonID : string , expectedAriaLabel : string ) => {
6
+ const testAria = async (
7
+ page : E2EPage ,
8
+ buttonID : string ,
9
+ expectedAriaLabelledBy : string | null ,
10
+ expectedAriaDescribedBy : string | null
11
+ ) => {
12
+ const didPresent = await page . spyOnEvent ( 'ionAlertDidPresent' ) ;
7
13
const button = page . locator ( `#${ buttonID } ` ) ;
14
+
8
15
await button . click ( ) ;
16
+ await didPresent . next ( ) ;
9
17
10
18
const alert = page . locator ( 'ion-alert' ) ;
11
- await expect ( alert ) . toHaveAttribute ( 'aria-label' , expectedAriaLabel ) ;
19
+
20
+ /**
21
+ * expect().toHaveAttribute() can't check for a null value, so grab and check
22
+ * the values manually instead.
23
+ */
24
+ const ariaLabelledBy = await alert . getAttribute ( 'aria-labelledby' ) ;
25
+ const ariaDescribedBy = await alert . getAttribute ( 'aria-describedby' ) ;
26
+
27
+ expect ( ariaLabelledBy ) . toBe ( expectedAriaLabelledBy ) ;
28
+ expect ( ariaDescribedBy ) . toBe ( expectedAriaDescribedBy ) ;
12
29
} ;
13
30
14
31
test . describe ( 'alert: a11y' , ( ) => {
@@ -17,27 +34,27 @@ test.describe('alert: a11y', () => {
17
34
await page . goto ( `/src/components/alert/test/a11y` ) ;
18
35
} ) ;
19
36
20
- test ( 'should not have accessibility violations' , async ( { page } ) => {
21
- const button = page . locator ( '#customHeader ' ) ;
37
+ test ( 'should not have accessibility violations when header and message are defined ' , async ( { page } ) => {
38
+ const button = page . locator ( '#bothHeaders ' ) ;
22
39
await button . click ( ) ;
23
40
24
41
const results = await new AxeBuilder ( { page } ) . analyze ( ) ;
25
42
expect ( results . violations ) . toEqual ( [ ] ) ;
26
43
} ) ;
27
44
28
- test ( 'should have fallback aria-label when no header or subheader is specified ' , async ( { page } ) => {
29
- await testAriaLabel ( page , 'noHeader ' , 'Alert' ) ;
45
+ test ( 'should have aria-labelledby when header is set ' , async ( { page } ) => {
46
+ await testAria ( page , 'noMessage ' , 'alert-1-hdr' , null ) ;
30
47
} ) ;
31
48
32
- test ( 'should inherit aria-label from header ' , async ( { page } ) => {
33
- await testAriaLabel ( page , 'customHeader ' , 'Header ') ;
49
+ test ( 'should have aria-describedby when message is set ' , async ( { page } ) => {
50
+ await testAria ( page , 'noHeaders ' , null , 'alert-1-msg ') ;
34
51
} ) ;
35
52
36
- test ( 'should inherit aria-label from subheader if no header is specified ' , async ( { page } ) => {
37
- await testAriaLabel ( page , 'subHeaderOnly' , 'Subtitle ' ) ;
53
+ test ( 'should fall back to subHeader for aria-labelledby if header is not defined ' , async ( { page } ) => {
54
+ await testAria ( page , 'subHeaderOnly' , 'alert-1-sub-hdr' , 'alert-1-msg ') ;
38
55
} ) ;
39
56
40
- test ( 'should allow for manually specifying aria-label ' , async ( { page } ) => {
41
- await testAriaLabel ( page , 'customAriaLabel ' , 'Custom alert ' ) ;
57
+ test ( 'should allow for manually specifying aria attributes ' , async ( { page } ) => {
58
+ await testAria ( page , 'customAria ' , 'Custom title' , 'Custom description ') ;
42
59
} ) ;
43
60
} ) ;
0 commit comments