forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch.test.js
134 lines (125 loc) · 4.46 KB
/
Search.test.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
import { mount } from '@vue/test-utils';
import { asyncExpect } from '../../../tests/utils';
import Input from '../index';
import Button from '../../button';
import focusTest from '../../../tests/shared/focusTest';
const { Search } = Input;
describe('Input.Search', () => {
focusTest(Search);
it('should support custom button', async () => {
const wrapper = mount(
{
render() {
return <Search enterButton={<button type="button">ok</button>} />;
},
},
{ sync: false },
);
await asyncExpect(() => {
expect(wrapper.html()).toMatchSnapshot();
});
});
it('should support custom Button', async () => {
const wrapper = mount(
{
render() {
return <Search enterButton={<Button>ok</Button>} />;
},
},
{ sync: false },
);
await asyncExpect(() => {
expect(wrapper.html()).toMatchSnapshot();
});
});
it('should support VueNode suffix without error', () => {
const fn = () => {
mount({
render() {
return <Search suffix={<div>ok</div>} />;
},
});
};
expect(fn).not.toThrow();
});
it('should disable enter button when disabled prop is true', () => {
const wrapper = mount({
render() {
return <Search placeholder="input search text" enterButton disabled />;
},
});
expect(wrapper.findAll('.ant-btn-primary[disabled]')).toHaveLength(1);
});
// it('should trigger onSearch when click search icon', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" onSearch={onSearch} />
// );
// wrapper.find('.anticon-search').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton onSearch={onSearch} />
// );
// wrapper.find('Button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button with text', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton="button text" onSearch={onSearch} />
// );
// wrapper.find('Button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button with customize button', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton={<Button>antd button</Button>} onSearch={onSearch} />
// );
// wrapper.find('Button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when click search button of native', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" enterButton={<button type="button">antd button</button>} onSearch={onSearch} />
// );
// wrapper.find('button').simulate('click');
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'click',
// preventDefault: expect.any(Function),
// }));
// });
// it('should trigger onSearch when press enter', () => {
// const onSearch = jest.fn();
// const wrapper = mount(
// <Search defaultValue="search text" onSearch={onSearch} />
// );
// wrapper.find('input').simulate('keydown', { key: 'Enter', keyCode: 13 });
// expect(onSearch).toHaveBeenCalledTimes(1);
// expect(onSearch).toBeCalledWith('search text', expect.objectContaining({
// type: 'keydown',
// preventDefault: expect.any(Function),
// }));
// });
});