@@ -6,11 +6,11 @@ import noop from 'lodash/noop';
66
77import { FieldConnector , FieldConnectorChildProps } from './FieldConnector' ;
88
9- it ( 'does not rerender with outdated value after calling setValue' , async ( ) => {
10- function getChild ( ) : FieldConnectorChildProps < any > {
11- return props . children . mock . calls [ props . children . mock . calls . length - 1 ] [ 0 ] ;
12- }
9+ function getChild ( children : any ) : FieldConnectorChildProps < any > {
10+ return children . mock . calls [ children . mock . calls . length - 1 ] [ 0 ] ;
11+ }
1312
13+ it ( 'does not rerender with outdated value after calling setValue' , async ( ) => {
1414 const onSchemaErrorsChanged = jest . fn ( ) ;
1515 const [ field ] = createFakeFieldAPI ( ( field : any ) => {
1616 return {
@@ -30,7 +30,7 @@ it('does not rerender with outdated value after calling setValue', async () => {
3030
3131 render ( < FieldConnector { ...props } /> ) ;
3232
33- let child = getChild ( ) ;
33+ let child = getChild ( props . children ) ;
3434 expect ( child . value ) . toBe ( 'initial value' ) ;
3535 const initialRenderCount = props . children . mock . calls . length ;
3636
@@ -40,9 +40,40 @@ it('does not rerender with outdated value after calling setValue', async () => {
4040
4141 onSchemaErrorsChanged . mock . calls . forEach ( ( [ cb ] ) => cb ( [ ] ) ) ;
4242
43- child = getChild ( ) ;
43+ child = getChild ( props . children ) ;
4444 expect ( child . value ) . toBe ( 'new value' ) ;
4545
4646 // to ensure that there was actually a rerender after calling `setValue` as we want to test that we don't rerender with outdated data
4747 expect ( props . children . mock . calls . length ) . toBeGreaterThan ( initialRenderCount ) ;
4848} ) ;
49+
50+ it ( 'takes initial disable state from sdk.field' , ( ) => {
51+ const [ field ] = createFakeFieldAPI ( ( field : any ) => {
52+ return {
53+ ...field ,
54+ // this promise never resolves
55+ getIsDisabled : jest . fn ( ) . mockReturnValue ( true ) ,
56+ } ;
57+ } , 'initial value' ) ;
58+
59+ const props = {
60+ isInitiallyDisabled : false ,
61+ children : jest . fn ( ) . mockImplementation ( ( ) => null ) ,
62+ field,
63+ debounce : 0 ,
64+ } ;
65+
66+ render ( < FieldConnector { ...props } /> ) ;
67+
68+ const child = getChild ( props . children ) ;
69+ expect ( child . value ) . toBe ( 'initial value' ) ;
70+
71+ expect ( field . getIsDisabled ) . toHaveBeenCalled ( ) ;
72+
73+ expect ( props . children ) . toHaveBeenCalledTimes ( 1 ) ;
74+ expect ( props . children ) . toHaveBeenCalledWith (
75+ expect . objectContaining ( {
76+ disabled : true ,
77+ } )
78+ ) ;
79+ } ) ;
0 commit comments