forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.js
110 lines (98 loc) · 3.2 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
import { mount } from '@vue/test-utils';
import { asyncExpect } from '@/tests/utils';
import Input from '..';
import Form from '../../form';
import focusTest from '../../../tests/shared/focusTest';
const { TextArea, Password } = Input;
describe('Input', () => {
focusTest(Input);
focusTest(TextArea);
focusTest(Password);
it('select()', () => {
const wrapper = mount(Input);
wrapper.vm.select();
});
it('should not support allowClear when it is disabled', () => {
const wrapper = mount(Input, {
propsData: { allowClear: true, defaultValue: '111', disabled: true },
sync: false,
});
expect(wrapper.findAll('.ant-input-clear-icon').length).toBe(0);
});
});
focusTest(TextArea);
describe('TextArea', () => {
it('should auto calculate height according to content length', async () => {
const wrapper = mount(TextArea, {
propsData: { value: '', readOnly: true, autoSize: true },
sync: false,
});
const mockFunc = jest.spyOn(wrapper.vm.$refs.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, { propsData: { disabled: true }, sync: false });
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, { propsData: { suffix: 'suffix' }, sync: false });
await asyncExpect(() => {
expect(wrapper.html()).toMatchSnapshot();
});
});
});