|
| 1 | +import { mount } from '@vue/test-utils' |
| 2 | +import Form from '..' |
| 3 | +import { asyncExpect } from '@/tests/utils' |
| 4 | + |
| 5 | +describe('Form', () => { |
| 6 | + it('should remove duplicated user input colon', () => { |
| 7 | + const wrapper = mount({ |
| 8 | + render () { |
| 9 | + return ( |
| 10 | + <Form> |
| 11 | + <Form.Item label='label:'>input</Form.Item> |
| 12 | + <Form.Item label='label:'>input</Form.Item> |
| 13 | + </Form> |
| 14 | + ) |
| 15 | + }, |
| 16 | + }) |
| 17 | + expect(wrapper.findAll('.ant-form-item-label label').at(0).text()).not.toContain(':') |
| 18 | + expect(wrapper.findAll('.ant-form-item-label label').at(1).text()).not.toContain(':') |
| 19 | + }) |
| 20 | + |
| 21 | + it('should not remove duplicated user input colon when props colon is false', () => { |
| 22 | + const wrapper = mount({ |
| 23 | + render () { |
| 24 | + return ( |
| 25 | + <Form> |
| 26 | + <Form.Item label='label:' colon={false}>input</Form.Item> |
| 27 | + <Form.Item label='label:' colon={false}>input</Form.Item> |
| 28 | + </Form> |
| 29 | + ) |
| 30 | + }, |
| 31 | + }) |
| 32 | + expect(wrapper.findAll('.ant-form-item-label label').at(0).text()).toContain(':') |
| 33 | + expect(wrapper.findAll('.ant-form-item-label label').at(1).text()).toContain(':') |
| 34 | + }) |
| 35 | + |
| 36 | + it('should not remove duplicated user input colon when layout is vertical', () => { |
| 37 | + const wrapper = mount({ |
| 38 | + render () { |
| 39 | + return ( |
| 40 | + <Form layout='vertical'> |
| 41 | + <Form.Item label='label:'>input</Form.Item> |
| 42 | + <Form.Item label='label:'>input</Form.Item> |
| 43 | + </Form> |
| 44 | + ) |
| 45 | + }, |
| 46 | + }) |
| 47 | + expect(wrapper.findAll('.ant-form-item-label label').at(0).text()).toContain(':') |
| 48 | + expect(wrapper.findAll('.ant-form-item-label label').at(1).text()).toContain(':') |
| 49 | + }) |
| 50 | + |
| 51 | + it('should has dom with .ant-form-item-control-wrapper', () => { |
| 52 | + const formItemLayout = { |
| 53 | + labelCol: { span: 6 }, |
| 54 | + wrapperCol: { span: 14 }, |
| 55 | + } |
| 56 | + const wrapper = mount({ |
| 57 | + render () { |
| 58 | + return ( |
| 59 | + <Form> |
| 60 | + <Form.Item {...{ props: { ...formItemLayout }}}>input</Form.Item> |
| 61 | + <Form.Item>input</Form.Item> |
| 62 | + </Form> |
| 63 | + ) |
| 64 | + }, |
| 65 | + }) |
| 66 | + expect(wrapper.findAll('.ant-form-item-control-wrapper').length).toBe(2) |
| 67 | + expect(wrapper.findAll('.ant-form-item-control-wrapper.ant-col-14').length).toBe(1) |
| 68 | + }) |
| 69 | + |
| 70 | + // https://github.com/ant-design/ant-design/issues/7351 |
| 71 | + it('focus correct input when click label', async () => { |
| 72 | + const Form1 = Form.create()({ |
| 73 | + render () { |
| 74 | + return ( |
| 75 | + <Form> |
| 76 | + <Form.Item label='label 1'> |
| 77 | + {this.form.getFieldDecorator('test')(<input />)} |
| 78 | + </Form.Item> |
| 79 | + </Form> |
| 80 | + ) |
| 81 | + }, |
| 82 | + }) |
| 83 | + const Form2 = Form.create()({ |
| 84 | + render () { |
| 85 | + return ( |
| 86 | + <Form> |
| 87 | + <Form.Item label='label 2'> |
| 88 | + {this.form.getFieldDecorator('test2')(<input />)} |
| 89 | + </Form.Item> |
| 90 | + </Form> |
| 91 | + ) |
| 92 | + }, |
| 93 | + }) |
| 94 | + |
| 95 | + const wrapper = mount({ |
| 96 | + render () { |
| 97 | + return <div><Form1 /><Form2 /></div> |
| 98 | + }, |
| 99 | + }, { sync: false }) |
| 100 | + await asyncExpect(() => { |
| 101 | + wrapper.findAll({ name: 'AForm' }).at(0).findAll('label').at(0).trigger('click') |
| 102 | + }) |
| 103 | + await asyncExpect(() => { |
| 104 | + expect(wrapper.findAll({ name: 'AForm' }).at(0).findAll('input').at(0).element).toBe(document.activeElement) |
| 105 | + }) |
| 106 | + await asyncExpect(() => { |
| 107 | + wrapper.findAll({ name: 'AForm' }).at(1).findAll('label').at(0).trigger('click') |
| 108 | + }) |
| 109 | + await asyncExpect(() => { |
| 110 | + expect(wrapper.findAll({ name: 'AForm' }).at(1).findAll('input').at(0).element).toBe(document.activeElement) |
| 111 | + }) |
| 112 | + }) |
| 113 | + |
| 114 | + // https://github.com/ant-design/ant-design/issues/7693 |
| 115 | + it('should not throw error when is not a valid id', async () => { |
| 116 | + const Form1 = Form.create()({ |
| 117 | + render () { |
| 118 | + return ( |
| 119 | + <Form> |
| 120 | + <Form.Item label='label 1'> |
| 121 | + {this.form.getFieldDecorator('member[0].name.firstname')(<input />)} |
| 122 | + </Form.Item> |
| 123 | + </Form> |
| 124 | + ) |
| 125 | + }, |
| 126 | + }) |
| 127 | + |
| 128 | + const wrapper = mount(Form1, { sync: false, attachToDocument: true }) |
| 129 | + await asyncExpect(() => { |
| 130 | + expect(() => { |
| 131 | + wrapper.find({ name: 'AForm' }).findAll('label').at(0).trigger('click') |
| 132 | + }).not.toThrow() |
| 133 | + }) |
| 134 | + // 不合法id时,document.activeElement没有正确更新 |
| 135 | + // await asyncExpect(() => { |
| 136 | + // expect(wrapper.find({ name: 'AForm' }).findAll('input').at(0).element).toBe(document.activeElement) |
| 137 | + // }, 0) |
| 138 | + }) |
| 139 | +}) |
0 commit comments