2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { asyncExpect } from '@/tests/utils';
|
|
|
|
import Input from '..';
|
2020-07-31 04:43:01 +00:00
|
|
|
// import Form from '../../form';
|
2019-01-12 03:33:27 +00:00
|
|
|
import focusTest from '../../../tests/shared/focusTest';
|
2018-06-10 02:26:24 +00:00
|
|
|
|
2019-12-10 09:15:36 +00:00
|
|
|
const { TextArea, Password } = Input;
|
2018-06-10 02:26:24 +00:00
|
|
|
|
|
|
|
describe('Input', () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
focusTest(Input);
|
2019-12-10 09:15:36 +00:00
|
|
|
focusTest(TextArea);
|
|
|
|
focusTest(Password);
|
2018-06-10 02:26:24 +00:00
|
|
|
|
2020-07-17 09:26:04 +00:00
|
|
|
it('should support maxlength', async () => {
|
2020-07-31 04:43:01 +00:00
|
|
|
const wrapper = mount(Input, { props: { maxlength: 3 }, sync: false });
|
2018-06-10 02:26:24 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
}, 0);
|
|
|
|
});
|
2020-07-31 04:43:01 +00:00
|
|
|
it('select()', async () => {
|
|
|
|
const wrapper = mount(Input, { sync: false, attachTo: 'body' });
|
|
|
|
await asyncExpect(() => {
|
|
|
|
wrapper.vm.select();
|
|
|
|
}, 0);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2019-10-17 10:52:10 +00:00
|
|
|
|
|
|
|
it('should not support allowClear when it is disabled', () => {
|
|
|
|
const wrapper = mount(Input, {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: { allowClear: true, defaultValue: '111', disabled: true },
|
2019-10-17 10:52:10 +00:00
|
|
|
sync: false,
|
|
|
|
});
|
|
|
|
expect(wrapper.findAll('.ant-input-clear-icon').length).toBe(0);
|
|
|
|
});
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-10 02:26:24 +00:00
|
|
|
|
|
|
|
describe('TextArea', () => {
|
2020-07-31 04:43:01 +00:00
|
|
|
xit('should auto calculate height according to content length', async () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const wrapper = mount(TextArea, {
|
2020-07-25 07:46:49 +00:00
|
|
|
props: { value: '', readonly: true, autoSize: true },
|
2019-01-12 03:33:27 +00:00
|
|
|
sync: false,
|
|
|
|
});
|
2020-06-27 06:02:30 +00:00
|
|
|
const mockFunc = jest.spyOn(wrapper.vm.resizableTextArea, 'resizeTextarea');
|
2018-06-10 02:26:24 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
wrapper.setProps({ value: '1111\n2222\n3333' });
|
|
|
|
});
|
2018-06-10 02:26:24 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(mockFunc).toHaveBeenCalledTimes(1);
|
|
|
|
});
|
2018-06-10 02:26:24 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
wrapper.setProps({ value: '1111' });
|
|
|
|
});
|
2018-06-10 02:26:24 +00:00
|
|
|
|
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(mockFunc).toHaveBeenCalledTimes(2);
|
2019-07-04 10:21:43 +00:00
|
|
|
}, 100);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-10 02:26:24 +00:00
|
|
|
|
|
|
|
it('should support disabled', async () => {
|
2020-07-25 07:46:49 +00:00
|
|
|
const wrapper = mount(TextArea, { props: { disabled: true }, sync: false });
|
2018-06-10 02:26:24 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
2018-06-10 02:26:24 +00:00
|
|
|
|
2020-07-17 09:26:04 +00:00
|
|
|
it('should support maxlength', async () => {
|
|
|
|
const wrapper = mount(TextArea, { attrs: { maxlength: 10 }, sync: false });
|
2018-06-10 02:26:24 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-06-10 02:26:24 +00:00
|
|
|
|
2020-07-31 04:43:01 +00:00
|
|
|
// describe('As Form Control', () => {
|
|
|
|
// it('should be reset when wrapped in form.getFieldDecorator without initialValue', async () => {
|
|
|
|
// const Demo = {
|
|
|
|
// methods: {
|
|
|
|
// reset() {
|
|
|
|
// this.form.resetFields();
|
|
|
|
// },
|
|
|
|
// },
|
2018-06-10 02:26:24 +00:00
|
|
|
|
2020-07-31 04:43:01 +00:00
|
|
|
// 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('');
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
// });
|
2018-06-10 02:26:24 +00:00
|
|
|
|
|
|
|
describe('Input.Search', () => {
|
|
|
|
it('should support suffix', async () => {
|
2020-07-25 07:46:49 +00:00
|
|
|
const wrapper = mount(Input.Search, { props: { suffix: 'suffix' }, sync: false });
|
2018-06-10 02:26:24 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(wrapper.html()).toMatchSnapshot();
|
2020-07-31 04:43:01 +00:00
|
|
|
}, 100);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
});
|