@@ -10,16 +10,43 @@ const testAria = async (page: E2EPage, buttonID: string, expectedAriaLabelledBy:
10
10
await button . click ( ) ;
11
11
await didPresent . next ( ) ;
12
12
13
- const alert = page . locator ( 'ion-action-sheet' ) ;
13
+ const actionSheet = page . locator ( 'ion-action-sheet' ) ;
14
14
15
15
/**
16
16
* expect().toHaveAttribute() can't check for a null value, so grab and check
17
17
* the value manually instead.
18
18
*/
19
- const ariaLabelledBy = await alert . getAttribute ( 'aria-labelledby' ) ;
19
+ const ariaLabelledBy = await actionSheet . getAttribute ( 'aria-labelledby' ) ;
20
20
21
21
expect ( ariaLabelledBy ) . toBe ( expectedAriaLabelledBy ) ;
22
22
} ;
23
+
24
+ const testAriaButton = async (
25
+ page : E2EPage ,
26
+ buttonID : string ,
27
+ expectedAriaLabelledBy : string | null ,
28
+ expectedAriaLabel : string | null
29
+ ) => {
30
+ const didPresent = await page . spyOnEvent ( 'ionActionSheetDidPresent' ) ;
31
+
32
+ const button = page . locator ( `#${ buttonID } ` ) ;
33
+ await button . click ( ) ;
34
+
35
+ await didPresent . next ( ) ;
36
+
37
+ const actionSheetButton = page . locator ( 'ion-action-sheet .action-sheet-button' ) ;
38
+
39
+ /**
40
+ * expect().toHaveAttribute() can't check for a null value, so grab and check
41
+ * the value manually instead.
42
+ */
43
+ const ariaLabelledBy = await actionSheetButton . getAttribute ( 'aria-labelledby' ) ;
44
+ expect ( ariaLabelledBy ) . toBe ( expectedAriaLabelledBy ) ;
45
+
46
+ const ariaLabel = await actionSheetButton . getAttribute ( 'aria-label' ) ;
47
+ expect ( ariaLabel ) . toBe ( expectedAriaLabel ) ;
48
+ } ;
49
+
23
50
configs ( { directions : [ 'ltr' ] } ) . forEach ( ( { config, title } ) => {
24
51
test . describe ( title ( 'action-sheet: a11y' ) , ( ) => {
25
52
test . beforeEach ( async ( { page } ) => {
@@ -52,5 +79,17 @@ configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
52
79
test ( 'should allow for manually specifying aria attributes' , async ( { page } ) => {
53
80
await testAria ( page , 'customAria' , 'Custom title' ) ;
54
81
} ) ;
82
+
83
+ test ( 'should have aria-labelledby and aria-label added to the button when htmlAttributes is set' , async ( {
84
+ page,
85
+ } ) => {
86
+ await testAriaButton ( page , 'ariaLabelButton' , 'close-label' , 'close button' ) ;
87
+ } ) ;
88
+
89
+ test ( 'should have aria-labelledby and aria-label added to the cancel button when htmlAttributes is set' , async ( {
90
+ page,
91
+ } ) => {
92
+ await testAriaButton ( page , 'ariaLabelCancelButton' , 'cancel-label' , 'cancel button' ) ;
93
+ } ) ;
55
94
} ) ;
56
95
} ) ;
0 commit comments