-
Notifications
You must be signed in to change notification settings - Fork 446
/
Accessibility.test.tsx
70 lines (60 loc) · 1.93 KB
/
Accessibility.test.tsx
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
import * as React from 'react';
import KeyCode from 'rc-util/lib/KeyCode';
import Select from '../src';
import { injectRunAllTimers, expectOpen, keyDown } from './utils/common';
import { fireEvent, render } from '@testing-library/react';
describe('Select.Accessibility', () => {
injectRunAllTimers(jest);
beforeEach(() => {
jest.useFakeTimers();
});
afterEach(() => {
jest.useRealTimers();
});
it('pass aria info to internal input', () => {
const MySelect = Select as any;
const { container } = render(<MySelect aria-label="light" data-attr="bamboo" useless="2333" />);
expect(container.querySelector('input')!.getAttribute('aria-label')).toEqual('light');
});
// https://github.com/ant-design/ant-design/issues/31850
it('active index should keep', () => {
const { container } = render(
<Select
showSearch
options={[
{
label: 'Little',
value: 'little',
},
{
label: 'Bamboo',
value: 'bamboo',
},
{
label: 'Light',
value: 'light',
},
]}
/>,
);
// First Match
fireEvent.change(container.querySelector('input')!, { target: { value: 'b' } });
jest.runAllTimers();
expectOpen(container);
expect(
document.querySelector('.rc-select-item-option-active .rc-select-item-option-content')
.textContent,
).toEqual('Bamboo');
keyDown(container.querySelector('input')!, KeyCode.ENTER);
expectOpen(container, false);
// Next Match
fireEvent.change(container.querySelector('input')!, { target: { value: '' } });
fireEvent.change(container.querySelector('input')!, { target: { value: 'g' } });
jest.runAllTimers();
expectOpen(container);
expect(
document.querySelector('.rc-select-item-option-active .rc-select-item-option-content')!
.textContent,
).toEqual('Light');
});
});