Skip to content

Commit 0d6feb0

Browse files
committed
test(alert): check for aria-label and aria-labelledby being passed
1 parent 86731c9 commit 0d6feb0

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

core/src/components/alert/test/a11y/alert.e2e.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,5 +60,26 @@ configs({ directions: ['ltr'] }).forEach(({ config, title }) => {
6060
test('should allow for manually specifying aria attributes', async ({ page }) => {
6161
await testAria(page, 'customAria', 'Custom title', 'Custom description');
6262
});
63+
64+
test('should have aria-labelledby and aria-label added to the button when htmlAttributes is set', async ({ page }) => {
65+
const didPresent = await page.spyOnEvent('ionAlertDidPresent');
66+
67+
const button = page.locator('#ariaLabelButton');
68+
await button.click();
69+
70+
await didPresent.next();
71+
72+
const alertButton = page.locator('ion-alert .alert-button');
73+
74+
/**
75+
* expect().toHaveAttribute() can't check for a null value, so grab and check
76+
* the value manually instead.
77+
*/
78+
const ariaLabelledBy = await alertButton.getAttribute('aria-labelledby');
79+
expect(ariaLabelledBy).toBe('close-label');
80+
81+
const ariaLabel = await alertButton.getAttribute('aria-label');
82+
expect(ariaLabel).toBe('close button');
83+
});
6384
});
6485
});

core/src/components/alert/test/a11y/index.html

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ <h1>Alert - A11y</h1>
2424
<ion-button id="noHeaders" expand="block" onclick="presentNoHeaders()">No Headers</ion-button>
2525
<ion-button id="noMessage" expand="block" onclick="presentNoMessage()">No Message</ion-button>
2626
<ion-button id="customAria" expand="block" onclick="presentCustomAria()">Custom Aria</ion-button>
27+
<ion-button id="ariaLabelButton" expand="block" onclick="presentAriaLabelButton()">Aria Label Button</ion-button>
2728
</main>
2829

2930
<script>
@@ -76,6 +77,21 @@ <h1>Alert - A11y</h1>
7677
},
7778
});
7879
}
80+
81+
function presentAriaLabelButton() {
82+
openAlert({
83+
header: 'Header',
84+
subHeader: 'Subtitle',
85+
message: 'This is an alert message with custom aria attributes passed to the button.',
86+
buttons: [{
87+
text: 'Close',
88+
htmlAttributes: {
89+
ariaLabel: 'close button',
90+
'aria-labelledby': 'close-label',
91+
}
92+
}],
93+
});
94+
}
7995
</script>
8096
</body>
8197
</html>

0 commit comments

Comments
 (0)