-
-
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(core): Increase lastValidateValue value processing during initial…
…ization (#276) * fix(core): Increase lastValidateValue value processing during initialization * test: add lastValidateValue prop handler test * test: test lastValidateValue prop handling from SchemaForm
- Loading branch information
Showing
3 changed files
with
110 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { createForm } from '../index' | ||
|
||
test('Increase lastValidateValue value processing during initialization', async () => { | ||
const inpueFieldValidate = jest.fn() | ||
const requriedFieldValidate = jest.fn() | ||
|
||
const form = createForm({ | ||
initialValues: { | ||
requriedField: 'defaultValue' | ||
} | ||
}) | ||
|
||
form.registerField('inpueField', { | ||
props: { | ||
requried: true, | ||
'x-rules': () => | ||
new Promise(resolve => { | ||
inpueFieldValidate() | ||
|
||
resolve() | ||
}) | ||
} | ||
}) | ||
|
||
form.registerField('requriedField', { | ||
props: { | ||
requried: true, | ||
'x-rules': () => | ||
new Promise(resolve => { | ||
requriedFieldValidate() | ||
|
||
resolve() | ||
}) | ||
} | ||
}) | ||
|
||
form.setValue('inpueField', 1111) | ||
await sleep(1000) | ||
expect(inpueFieldValidate).toHaveBeenCalledTimes(1) | ||
expect(requriedFieldValidate).toHaveBeenCalledTimes(0) | ||
|
||
form.setValue('requriedField', 2222) | ||
await sleep(1000) | ||
expect(inpueFieldValidate).toHaveBeenCalledTimes(1) | ||
expect(requriedFieldValidate).toHaveBeenCalledTimes(1) | ||
}) |
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,60 @@ | ||
import React from 'react' | ||
import { render, fireEvent } from '@testing-library/react' | ||
|
||
import SchemaForm, { Field, registerFormField, connect } from '../index' | ||
|
||
registerFormField( | ||
'string', | ||
connect()(props => ( | ||
<input {...props} data-testid={props.testid} value={props.value || ''} /> | ||
)) | ||
) | ||
|
||
test('Increase lastValidateValue value processing during initialization', async () => { | ||
const inpueFieldValidate = jest.fn() | ||
const requriedFieldValidate = jest.fn() | ||
|
||
const TestComponent = () => ( | ||
<SchemaForm initialValues={{ requriedField: 'defaultValue' }}> | ||
<Field | ||
requried | ||
type="string" | ||
title="inpueField" | ||
name="inpueField" | ||
x-props={{ testid: 'inpueField' }} | ||
x-rules={() => | ||
new Promise(resolve => { | ||
inpueFieldValidate() | ||
|
||
resolve() | ||
}) | ||
} | ||
/> | ||
<Field | ||
requried | ||
type="string" | ||
title="requriedField" | ||
name="requriedField" | ||
x-props={{ testid: 'requriedField' }} | ||
x-rules={() => | ||
new Promise(resolve => { | ||
requriedFieldValidate() | ||
|
||
resolve() | ||
}) | ||
} | ||
/> | ||
</SchemaForm> | ||
) | ||
|
||
const { getByTestId } = render(<TestComponent />) | ||
fireEvent.change(getByTestId('inpueField'), { target: { value: 1111 } }) | ||
await sleep(1000) | ||
expect(inpueFieldValidate).toHaveBeenCalledTimes(1) | ||
expect(requriedFieldValidate).toHaveBeenCalledTimes(0) | ||
|
||
fireEvent.change(getByTestId('requriedField'), { target: { value: 2222 } }) | ||
await sleep(1000) | ||
expect(inpueFieldValidate).toHaveBeenCalledTimes(1) | ||
expect(requriedFieldValidate).toHaveBeenCalledTimes(1) | ||
}) |