|
1 | 1 | import React from 'react';
|
2 | 2 | import { mount } from 'enzyme';
|
3 |
| -import Form from '../src'; |
4 |
| -import InfoField from './common/InfoField'; |
5 |
| -import { changeValue, matchError, getField } from './common'; |
| 3 | +import Form, { Field } from '../src'; |
| 4 | +import InfoField, { Input } from './common/InfoField'; |
| 5 | +import { changeValue, matchError, getField, getInput } from './common'; |
6 | 6 |
|
7 | 7 | describe('dependencies', () => {
|
8 | 8 | it('touched', async () => {
|
@@ -30,4 +30,43 @@ describe('dependencies', () => {
|
30 | 30 | await changeValue(getField(wrapper, 0), '');
|
31 | 31 | matchError(getField(wrapper, 1), true);
|
32 | 32 | });
|
| 33 | + |
| 34 | + it('nest dependencies', async () => { |
| 35 | + let form = null; |
| 36 | + let rendered = false; |
| 37 | + |
| 38 | + const wrapper = mount( |
| 39 | + <div> |
| 40 | + <Form |
| 41 | + ref={instance => { |
| 42 | + form = instance; |
| 43 | + }} |
| 44 | + > |
| 45 | + <Field name="field_1"> |
| 46 | + <Input /> |
| 47 | + </Field> |
| 48 | + <Field name="field_2" dependencies={['field_1']}> |
| 49 | + <Input /> |
| 50 | + </Field> |
| 51 | + <Field name="field_3" dependencies={['field_2']}> |
| 52 | + {control => { |
| 53 | + rendered = true; |
| 54 | + return <Input {...control} />; |
| 55 | + }} |
| 56 | + </Field> |
| 57 | + </Form> |
| 58 | + </div>, |
| 59 | + ); |
| 60 | + |
| 61 | + form.setFields([ |
| 62 | + { name: 'field_1', touched: true }, |
| 63 | + { name: 'field_2', touched: true }, |
| 64 | + { name: 'field_3', touched: true }, |
| 65 | + ]); |
| 66 | + |
| 67 | + rendered = false; |
| 68 | + await changeValue(getInput(wrapper), '1'); |
| 69 | + |
| 70 | + expect(rendered).toBeTruthy(); |
| 71 | + }); |
33 | 72 | });
|
0 commit comments