Skip to content

Commit 5afe018

Browse files
committed
test(alert): test for the correct heading aria values and tag names
1 parent 4d91dea commit 5afe018

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { newSpecPage } from '@stencil/core/testing';
2+
3+
import { Alert } from '../alert';
4+
5+
describe('alert: aria', () => {
6+
it('alert should assign proper aria attributes and tag names with a header, subHeader and message', async () => {
7+
const page = await newSpecPage({
8+
components: [Alert],
9+
html: `<ion-alert is-open="true" header="Alert" sub-header="Subtitle" message="This is an alert message."></ion-alert>`,
10+
});
11+
12+
const alert = page.body.querySelector('ion-alert')!;
13+
14+
expect(alert.getAttribute('id')).toBe('ion-overlay-1');
15+
expect(alert.getAttribute('aria-labelledby')).toBe('alert-1-hdr alert-1-sub-hdr');
16+
expect(alert.getAttribute('aria-describedby')).toBe('alert-1-msg');
17+
18+
const header = page.body.querySelector('.alert-title')!;
19+
expect(header.tagName).toBe('H2');
20+
21+
const subHeader = page.body.querySelector('.alert-sub-title')!;
22+
expect(subHeader.tagName).toBe('H3');
23+
});
24+
25+
it('alert should assign proper aria attributes and tag name with only a header', async () => {
26+
const page = await newSpecPage({
27+
components: [Alert],
28+
html: `<ion-alert is-open="true" header="Alert"></ion-alert>`,
29+
});
30+
31+
const alert = page.body.querySelector('ion-alert')!;
32+
33+
expect(alert.getAttribute('id')).toBe('ion-overlay-2');
34+
expect(alert.getAttribute('aria-labelledby')).toBe('alert-2-hdr');
35+
36+
const header = page.body.querySelector('.alert-title')!;
37+
expect(header.tagName).toBe('H2');
38+
});
39+
40+
it('alert should assign proper aria attributes and tag name with only a subHeader', async () => {
41+
const page = await newSpecPage({
42+
components: [Alert],
43+
html: `<ion-alert is-open="true" sub-header="Subtitle"></ion-alert>`,
44+
});
45+
46+
const alert = page.body.querySelector('ion-alert')!;
47+
48+
expect(alert.getAttribute('id')).toBe('ion-overlay-3');
49+
expect(alert.getAttribute('aria-labelledby')).toBe('alert-3-sub-hdr');
50+
51+
const subHeader = page.body.querySelector('.alert-sub-title')!;
52+
expect(subHeader.tagName).toBe('H2');
53+
});
54+
});

0 commit comments

Comments
 (0)