-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
464 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import React, { Fragment } from 'react' | ||
import SchemaForm, { Field, registerFormField, connect } from '../index' | ||
import { toArr } from '@uform/utils' | ||
import { render } from 'react-testing-library' | ||
|
||
beforeEach(() => { | ||
registerFormField('string', connect()(props => <div>{props.value}</div>)) | ||
|
||
registerFormField('array', props => { | ||
const { value, mutators, renderField } = props | ||
return ( | ||
<Fragment> | ||
{toArr(value).map((item, index) => { | ||
return ( | ||
<div data-testid='item' key={index}> | ||
{renderField(index)} | ||
</div> | ||
) | ||
})} | ||
<button | ||
type='button' | ||
onClick={() => { | ||
mutators.push() | ||
}} | ||
> | ||
Add Field | ||
</button> | ||
</Fragment> | ||
) | ||
}) | ||
}) | ||
|
||
test('destruct with initial values', async () => { | ||
const TestComponent = () => { | ||
return ( | ||
<SchemaForm initialValues={{ aa: 123, bb: 321 }}> | ||
<Field type='string' name='[aa,bb]' /> | ||
</SchemaForm> | ||
) | ||
} | ||
|
||
const { queryByText } = render(<TestComponent />) | ||
|
||
await sleep(33) | ||
expect(queryByText('123321')).toBeVisible() | ||
}) | ||
|
||
test('destruct with initial values in array', async () => { | ||
const TestComponent = () => { | ||
return ( | ||
<SchemaForm initialValues={{ array: [{ aa: 123, bb: 321 }] }}> | ||
<Field type='array' name='array'> | ||
<Field type='object'> | ||
<Field type='string' name='[aa,bb]' /> | ||
</Field> | ||
</Field> | ||
</SchemaForm> | ||
) | ||
} | ||
|
||
const { queryByText } = render(<TestComponent />) | ||
|
||
await sleep(33) | ||
expect(queryByText('123321')).toBeVisible() | ||
}) |
Oops, something went wrong.