-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtoggleable.a11y.test.ts
72 lines (55 loc) · 2.23 KB
/
toggleable.a11y.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import {ESLToggleable} from '../core';
describe('ESLToggleable custom element - a11y attributes test', () => {
beforeAll(() => {
jest.useFakeTimers();
ESLToggleable.register();
});
describe('Default a11y target', () => {
const $el = ESLToggleable.create();
beforeAll(() => document.body.appendChild($el));
test('a11y target set initially', () => expect($el.getAttribute('aria-hidden')).toBe('true'));
test('a11y target should be update on toggle actions', () => {
$el.show();
jest.advanceTimersByTime(1);
expect($el.getAttribute('aria-hidden')).toBe('false');
$el.hide();
jest.advanceTimersByTime(1);
expect($el.getAttribute('aria-hidden')).toBe('true');
});
});
describe('No a11y target', () => {
const $el = ESLToggleable.create();
$el.setAttribute('a11y-target', 'none');
beforeAll(() => document.body.appendChild($el));
test('a11y target should be missing initially', () => expect($el.hasAttribute('aria-hidden')).toBe(false));
test('a11y target shouldn`t apper on toggle actions', () => {
$el.show();
jest.advanceTimersByTime(1);
expect($el.hasAttribute('aria-hidden')).toBe(false);
$el.hide();
jest.advanceTimersByTime(1);
expect($el.hasAttribute('aria-hidden')).toBe(false);
});
});
describe('Internal element a11y target', () => {
const $el = ESLToggleable.create();
$el.setAttribute('a11y-target', 'button');
const $innerEl = document.createElement('button');
$el.appendChild($innerEl);
beforeAll(() => document.body.appendChild($el));
test('a11y target should initially appear on target element', () => {
expect($el.hasAttribute('aria-hidden')).toBe(false);
expect($innerEl.getAttribute('aria-hidden')).toBe('true');
});
test('a11y target should update on target element on toggle action', () => {
$el.show();
jest.advanceTimersByTime(1);
expect($el.hasAttribute('aria-hidden')).toBe(false);
expect($innerEl.getAttribute('aria-hidden')).toBe('false');
$el.hide();
jest.advanceTimersByTime(1);
expect($el.hasAttribute('aria-hidden')).toBe(false);
expect($innerEl.getAttribute('aria-hidden')).toBe('true');
});
});
});