forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
166 lines (152 loc) · 5.21 KB
/
index.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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import { mount } from '@vue/test-utils';
import { asyncExpect } from '@/tests/utils';
import Input from '..';
// import Form from '../../form';
import focusTest from '../../../tests/shared/focusTest';
import { WifiOutlined, SyncOutlined } from '@ant-design/icons-vue';
const { TextArea, Password } = Input;
describe('Input', () => {
focusTest(Input);
focusTest(TextArea);
focusTest(Password);
it('should support maxlength', async () => {
const wrapper = mount(Input, { props: { maxlength: 3 }, sync: false });
await asyncExpect(() => {
expect(wrapper.html()).toMatchSnapshot();
}, 0);
});
it('select()', async () => {
const wrapper = mount(Input, { sync: false, attachTo: 'body' });
await asyncExpect(() => {
wrapper.vm.select();
}, 0);
});
it('should not support allowClear when it is disabled', () => {
const wrapper = mount(Input, {
props: { allowClear: true, defaultValue: '111', disabled: true },
sync: false,
});
expect(wrapper.findAll('.ant-input-clear-icon-hidden').length).toBeTruthy();
});
});
describe('TextArea', () => {
xit('should auto calculate height according to content length', async () => {
const wrapper = mount(TextArea, {
props: { value: '', readonly: true, autoSize: true },
sync: false,
});
const mockFunc = jest.spyOn(wrapper.vm.resizableTextArea, 'resizeTextarea');
await asyncExpect(() => {
wrapper.setProps({ value: '1111\n2222\n3333' });
});
await asyncExpect(() => {
expect(mockFunc).toHaveBeenCalledTimes(1);
});
await asyncExpect(() => {
wrapper.setProps({ value: '1111' });
});
await asyncExpect(() => {
expect(mockFunc).toHaveBeenCalledTimes(2);
}, 100);
});
it('should support disabled', async () => {
const wrapper = mount(TextArea, { props: { disabled: true }, sync: false });
await asyncExpect(() => {
expect(wrapper.html()).toMatchSnapshot();
});
});
it('should support maxlength', async () => {
const wrapper = mount(TextArea, { attrs: { maxlength: 10 }, sync: false });
await asyncExpect(() => {
expect(wrapper.html()).toMatchSnapshot();
});
});
it('should support showCount', async () => {
const wrapper = mount(TextArea, {
props: { showCount: true, defaultValue: '111', maxlength: 10 },
sync: false,
});
expect(wrapper.find('.ant-input-textarea-show-count')).toBeTruthy();
await asyncExpect(() => {
expect(wrapper.html()).toMatchSnapshot();
});
});
});
// describe('As Form Control', () => {
// it('should be reset when wrapped in form.getFieldDecorator without initialValue', async () => {
// const Demo = {
// methods: {
// reset() {
// this.form.resetFields();
// },
// },
// render() {
// const { getFieldDecorator } = this.form;
// return (
// <Form>
// <Form.Item>{getFieldDecorator('input')(<Input />)}</Form.Item>
// <Form.Item>{getFieldDecorator('textarea')(<Input.TextArea />)}</Form.Item>
// <button type="button" onClick={this.reset}>
// reset
// </button>
// </Form>
// );
// },
// };
// const DemoForm = Form.create()(Demo);
// const wrapper = mount(DemoForm, { sync: false });
// await asyncExpect(() => {
// wrapper.find('input').element.value = '111';
// wrapper.find('input').trigger('input');
// wrapper.find('textarea').element.value = '222';
// wrapper.find('textarea').trigger('input');
// });
// await asyncExpect(() => {
// expect(wrapper.find('input').element.value).toBe('111');
// expect(wrapper.find('textarea').element.value).toBe('222');
// wrapper.find('button').trigger('click');
// });
// await asyncExpect(() => {
// expect(wrapper.find('input').element.value).toBe('');
// expect(wrapper.find('textarea').element.value).toBe('');
// });
// });
// });
describe('Input.Search', () => {
it('should support suffix', async () => {
const wrapper = mount(Input.Search, { props: { suffix: 'suffix' }, sync: false });
await asyncExpect(() => {
expect(wrapper.html()).toMatchSnapshot();
}, 100);
});
});
describe('Input.Password', () => {
it('should support iconRender', async () => {
const wrapper = mount(Input.Password, {
props: { iconRender: visible => (visible ? <SyncOutlined /> : <WifiOutlined />) },
sync: false,
});
await asyncExpect(() => {
expect(wrapper.findAll('.anticon-wifi').length).toBe(1);
wrapper.find('.anticon-wifi').trigger('click');
}, 100);
await asyncExpect(() => {
expect(wrapper.findAll('.anticon-sync').length).toBe(1);
}, 100);
});
it('should support slot iconRender', async () => {
const wrapper = mount(Input.Password, {
slots: {
iconRender: visible => (visible ? <SyncOutlined /> : <WifiOutlined />),
},
sync: false,
});
await asyncExpect(() => {
expect(wrapper.findAll('.anticon-wifi').length).toBe(1);
wrapper.find('.anticon-wifi').trigger('click');
}, 100);
await asyncExpect(() => {
expect(wrapper.findAll('.anticon-sync').length).toBe(1);
}, 100);
});
});