-
-
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.
fix(@uform/core): fix field props transformer is not work
- Loading branch information
Showing
6 changed files
with
72 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import React, { useState } from 'react' | ||
import { render, act } from '@testing-library/react' | ||
import SchemaForm, { | ||
Field, | ||
registerFormField, | ||
connect, | ||
createFormActions, | ||
registerFormFieldPropsTransformer | ||
} from '../index' | ||
|
||
registerFormField( | ||
'test-string', | ||
connect()(props => ( | ||
<React.Fragment> | ||
<div data-testid="value">{props.value}</div> | ||
<div data-testid="type-value">{typeof props.value}</div> | ||
<div data-testid="extra-props">{props.extra}</div> | ||
</React.Fragment> | ||
)) | ||
) | ||
|
||
registerFormFieldPropsTransformer('test-string', schema => { | ||
schema['x-props'] = { | ||
extra: 'this is extra props' | ||
} | ||
return schema | ||
}) | ||
|
||
registerFormFieldPropsTransformer('test-string', schema => { | ||
schema['x-props'] = { | ||
extra: 'this is extra props 2' | ||
} | ||
return schema | ||
}) | ||
|
||
test('props traverse', async () => { | ||
|
||
const actions = createFormActions() | ||
|
||
const Component = () => { | ||
return ( | ||
<SchemaForm actions={actions} value={{ foo: '123' }}> | ||
<Field name="foo" type="test-string" /> | ||
</SchemaForm> | ||
) | ||
} | ||
|
||
const { getByTestId, baseElement } = render(<Component />) | ||
await sleep(33) | ||
expect(getByTestId('extra-props').textContent).toEqual('this is extra props 2') | ||
actions.setFieldState('foo',state=>{ | ||
state.props['x-props'].extra = 'modify props' | ||
}) | ||
await sleep(33) | ||
expect(getByTestId('extra-props').textContent).toEqual('modify props') | ||
}) |
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