2019-01-12 11:33:27 +08:00
|
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
|
import Form from '..';
|
|
|
|
|
import { asyncExpect } from '@/tests/utils';
|
2018-06-28 21:41:02 +08:00
|
|
|
|
|
|
|
|
|
describe('Form', () => {
|
|
|
|
|
it('should remove duplicated user input colon', () => {
|
|
|
|
|
const wrapper = mount({
|
2019-01-12 11:33:27 +08:00
|
|
|
|
render() {
|
2018-06-28 21:41:02 +08:00
|
|
|
|
return (
|
|
|
|
|
<Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
<Form.Item label="label:">input</Form.Item>
|
|
|
|
|
<Form.Item label="label:">input</Form.Item>
|
2018-06-28 21:41:02 +08:00
|
|
|
|
</Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-06-28 21:41:02 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
expect(
|
|
|
|
|
wrapper
|
|
|
|
|
.findAll('.ant-form-item-label label')
|
|
|
|
|
.at(0)
|
|
|
|
|
.text(),
|
|
|
|
|
).not.toContain(':');
|
|
|
|
|
expect(
|
|
|
|
|
wrapper
|
|
|
|
|
.findAll('.ant-form-item-label label')
|
|
|
|
|
.at(1)
|
|
|
|
|
.text(),
|
|
|
|
|
).not.toContain(':');
|
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
|
|
|
|
|
it('should not remove duplicated user input colon when props colon is false', () => {
|
|
|
|
|
const wrapper = mount({
|
2019-01-12 11:33:27 +08:00
|
|
|
|
render() {
|
2018-06-28 21:41:02 +08:00
|
|
|
|
return (
|
|
|
|
|
<Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
<Form.Item label="label:" colon={false}>
|
|
|
|
|
input
|
|
|
|
|
</Form.Item>
|
|
|
|
|
<Form.Item label="label:" colon={false}>
|
|
|
|
|
input
|
|
|
|
|
</Form.Item>
|
2018-06-28 21:41:02 +08:00
|
|
|
|
</Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-06-28 21:41:02 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
expect(
|
|
|
|
|
wrapper
|
|
|
|
|
.findAll('.ant-form-item-label label')
|
|
|
|
|
.at(0)
|
|
|
|
|
.text(),
|
|
|
|
|
).toContain(':');
|
|
|
|
|
expect(
|
|
|
|
|
wrapper
|
|
|
|
|
.findAll('.ant-form-item-label label')
|
|
|
|
|
.at(1)
|
|
|
|
|
.text(),
|
|
|
|
|
).toContain(':');
|
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
|
|
|
|
|
it('should not remove duplicated user input colon when layout is vertical', () => {
|
|
|
|
|
const wrapper = mount({
|
2019-01-12 11:33:27 +08:00
|
|
|
|
render() {
|
2018-06-28 21:41:02 +08:00
|
|
|
|
return (
|
2019-01-12 11:33:27 +08:00
|
|
|
|
<Form layout="vertical">
|
|
|
|
|
<Form.Item label="label:">input</Form.Item>
|
|
|
|
|
<Form.Item label="label:">input</Form.Item>
|
2018-06-28 21:41:02 +08:00
|
|
|
|
</Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-06-28 21:41:02 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
expect(
|
|
|
|
|
wrapper
|
|
|
|
|
.findAll('.ant-form-item-label label')
|
|
|
|
|
.at(0)
|
|
|
|
|
.text(),
|
|
|
|
|
).toContain(':');
|
|
|
|
|
expect(
|
|
|
|
|
wrapper
|
|
|
|
|
.findAll('.ant-form-item-label label')
|
|
|
|
|
.at(1)
|
|
|
|
|
.text(),
|
|
|
|
|
).toContain(':');
|
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
|
|
|
|
|
it('should has dom with .ant-form-item-control-wrapper', () => {
|
|
|
|
|
const formItemLayout = {
|
|
|
|
|
labelCol: { span: 6 },
|
|
|
|
|
wrapperCol: { span: 14 },
|
2019-01-12 11:33:27 +08:00
|
|
|
|
};
|
2018-06-28 21:41:02 +08:00
|
|
|
|
const wrapper = mount({
|
2019-01-12 11:33:27 +08:00
|
|
|
|
render() {
|
2018-06-28 21:41:02 +08:00
|
|
|
|
return (
|
|
|
|
|
<Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
<Form.Item {...{ props: { ...formItemLayout } }}>input</Form.Item>
|
2018-06-28 21:41:02 +08:00
|
|
|
|
<Form.Item>input</Form.Item>
|
|
|
|
|
</Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-06-28 21:41:02 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
expect(wrapper.findAll('.ant-form-item-control-wrapper').length).toBe(2);
|
|
|
|
|
expect(wrapper.findAll('.ant-form-item-control-wrapper.ant-col-14').length).toBe(1);
|
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/7351
|
|
|
|
|
it('focus correct input when click label', async () => {
|
|
|
|
|
const Form1 = Form.create()({
|
2019-01-12 11:33:27 +08:00
|
|
|
|
render() {
|
2018-06-28 21:41:02 +08:00
|
|
|
|
return (
|
|
|
|
|
<Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
<Form.Item label="label 1">{this.form.getFieldDecorator('test')(<input />)}</Form.Item>
|
2018-06-28 21:41:02 +08:00
|
|
|
|
</Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-06-28 21:41:02 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
const Form2 = Form.create()({
|
2019-01-12 11:33:27 +08:00
|
|
|
|
render() {
|
2018-06-28 21:41:02 +08:00
|
|
|
|
return (
|
|
|
|
|
<Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
<Form.Item label="label 2">{this.form.getFieldDecorator('test2')(<input />)}</Form.Item>
|
2018-06-28 21:41:02 +08:00
|
|
|
|
</Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-06-28 21:41:02 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const wrapper = mount(
|
|
|
|
|
{
|
|
|
|
|
render() {
|
|
|
|
|
return (
|
|
|
|
|
<div>
|
|
|
|
|
<Form1 />
|
|
|
|
|
<Form2 />
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
},
|
2018-06-28 21:41:02 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
{ sync: false },
|
|
|
|
|
);
|
2018-06-28 21:41:02 +08:00
|
|
|
|
await asyncExpect(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
wrapper
|
|
|
|
|
.findAll({ name: 'AForm' })
|
|
|
|
|
.at(0)
|
|
|
|
|
.findAll('label')
|
|
|
|
|
.at(0)
|
|
|
|
|
.trigger('click');
|
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
await asyncExpect(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
expect(
|
|
|
|
|
wrapper
|
|
|
|
|
.findAll({ name: 'AForm' })
|
|
|
|
|
.at(0)
|
|
|
|
|
.findAll('input')
|
|
|
|
|
.at(0).element,
|
|
|
|
|
).toBe(document.activeElement);
|
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
await asyncExpect(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
wrapper
|
|
|
|
|
.findAll({ name: 'AForm' })
|
|
|
|
|
.at(1)
|
|
|
|
|
.findAll('label')
|
|
|
|
|
.at(0)
|
|
|
|
|
.trigger('click');
|
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
await asyncExpect(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
expect(
|
|
|
|
|
wrapper
|
|
|
|
|
.findAll({ name: 'AForm' })
|
|
|
|
|
.at(1)
|
|
|
|
|
.findAll('input')
|
|
|
|
|
.at(0).element,
|
|
|
|
|
).toBe(document.activeElement);
|
|
|
|
|
});
|
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
|
|
|
|
|
// https://github.com/ant-design/ant-design/issues/7693
|
|
|
|
|
it('should not throw error when is not a valid id', async () => {
|
|
|
|
|
const Form1 = Form.create()({
|
2019-01-12 11:33:27 +08:00
|
|
|
|
render() {
|
2018-06-28 21:41:02 +08:00
|
|
|
|
return (
|
|
|
|
|
<Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
<Form.Item label="label 1">
|
2018-06-28 21:41:02 +08:00
|
|
|
|
{this.form.getFieldDecorator('member[0].name.firstname')(<input />)}
|
|
|
|
|
</Form.Item>
|
|
|
|
|
</Form>
|
2019-01-12 11:33:27 +08:00
|
|
|
|
);
|
2018-06-28 21:41:02 +08:00
|
|
|
|
},
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
|
2019-01-12 11:33:27 +08:00
|
|
|
|
const wrapper = mount(Form1, { sync: false, attachToDocument: true });
|
2018-06-28 21:41:02 +08:00
|
|
|
|
await asyncExpect(() => {
|
|
|
|
|
expect(() => {
|
2019-01-12 11:33:27 +08:00
|
|
|
|
wrapper
|
|
|
|
|
.find({ name: 'AForm' })
|
|
|
|
|
.findAll('label')
|
|
|
|
|
.at(0)
|
|
|
|
|
.trigger('click');
|
|
|
|
|
}).not.toThrow();
|
|
|
|
|
});
|
2018-06-28 21:41:02 +08:00
|
|
|
|
// 不合法id时,document.activeElement没有正确更新
|
|
|
|
|
// await asyncExpect(() => {
|
|
|
|
|
// expect(wrapper.find({ name: 'AForm' }).findAll('input').at(0).element).toBe(document.activeElement)
|
|
|
|
|
// }, 0)
|
2019-01-12 11:33:27 +08:00
|
|
|
|
});
|
|
|
|
|
});
|