Skip to content

Commit d45a081

Browse files
committed
test(action-sheet): add tests for htmlAttributes to a11y e2e tests
1 parent 645968a commit d45a081

File tree

2 files changed

+78
-2
lines changed

2 files changed

+78
-2
lines changed

core/src/components/action-sheet/test/a11y/action-sheet.e2e.ts

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,43 @@ const testAria = async (page: E2EPage, buttonID: string, expectedAriaLabelledBy:
1010
await button.click();
1111
await didPresent.next();
1212

13-
const alert = page.locator('ion-action-sheet');
13+
const actionSheet = page.locator('ion-action-sheet');
1414

1515
/**
1616
* expect().toHaveAttribute() can't check for a null value, so grab and check
1717
* the value manually instead.
1818
*/
19-
const ariaLabelledBy = await alert.getAttribute('aria-labelledby');
19+
const ariaLabelledBy = await actionSheet.getAttribute('aria-labelledby');
2020

2121
expect(ariaLabelledBy).toBe(expectedAriaLabelledBy);
2222
};
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+
2350
configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
2451
test.describe(title('action-sheet: a11y'), () => {
2552
test.beforeEach(async ({ page }) => {
@@ -52,5 +79,17 @@ configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
5279
test('should allow for manually specifying aria attributes', async ({ page }) => {
5380
await testAria(page, 'customAria', 'Custom title');
5481
});
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+
});
5594
});
5695
});

core/src/components/action-sheet/test/a11y/index.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ <h1>Action Sheet - A11y</h1>
2323
<ion-button id="subHeaderOnly" expand="block" onclick="presentSubHeaderOnly()">Subheader Only</ion-button>
2424
<ion-button id="noHeaders" expand="block" onclick="presentNoHeaders()">No Headers</ion-button>
2525
<ion-button id="customAria" expand="block" onclick="presentCustomAria()">Custom Aria</ion-button>
26+
<ion-button id="ariaLabelButton" expand="block" onclick="presentAriaLabelButton()">Aria Label Button</ion-button>
27+
<ion-button id="ariaLabelCancelButton" expand="block" onclick="presentAriaLabelCancelButton()"
28+
>Aria Label Cancel Button</ion-button
29+
>
2630
</main>
2731

2832
<script>
@@ -63,6 +67,39 @@ <h1>Action Sheet - A11y</h1>
6367
},
6468
});
6569
}
70+
71+
function presentAriaLabelButton() {
72+
openActionSheet({
73+
header: 'Header',
74+
subHeader: 'Subtitle',
75+
buttons: [
76+
{
77+
text: 'Close',
78+
htmlAttributes: {
79+
ariaLabel: 'close button',
80+
'aria-labelledby': 'close-label',
81+
},
82+
},
83+
],
84+
});
85+
}
86+
87+
function presentAriaLabelCancelButton() {
88+
openActionSheet({
89+
header: 'Header',
90+
subHeader: 'Subtitle',
91+
buttons: [
92+
{
93+
text: 'Cancel',
94+
role: 'cancel',
95+
htmlAttributes: {
96+
ariaLabel: 'cancel button',
97+
'aria-labelledby': 'cancel-label',
98+
},
99+
},
100+
],
101+
});
102+
}
66103
</script>
67104
</body>
68105
</html>

0 commit comments

Comments
 (0)