@@ -739,7 +739,7 @@ describe('renderForm function', () => {
739
739
component : componentTypes . TEXT_FIELD ,
740
740
name : INITIALIZED_FIELD ,
741
741
initializeOnMount,
742
- initialValue,
742
+ ... ( initialValue ? { initialValue } : { } ) ,
743
743
condition : {
744
744
when : SHOWER_FIELD ,
745
745
is : SHOW_VALUE ,
@@ -884,5 +884,133 @@ describe('renderForm function', () => {
884
884
mountInitializedField ( wrapper ) ;
885
885
expectSchemaInitialValue ( wrapper ) ;
886
886
} ) ;
887
+
888
+ it ( 'should set false value in initializeOnMount' , ( ) => {
889
+ layoutMapper = {
890
+ [ layoutComponents . FORM_WRAPPER ] : ( { children, ...props } ) => < form { ...props } > { children } </ form > ,
891
+ [ layoutComponents . BUTTON ] : ( { label, ...rest } ) => < button { ...rest } > { label } </ button > ,
892
+ [ layoutComponents . BUTTON_GROUP ] : ( { children } ) => < div > { children } </ div > ,
893
+ [ layoutComponents . TITLE ] : ( { children } ) => < div > { children } </ div > ,
894
+ [ layoutComponents . DESCRIPTION ] : ( { children } ) => < div > { children } </ div > ,
895
+ } ;
896
+
897
+ const schema = {
898
+ fields : [ {
899
+ component : components . TEXT_FIELD ,
900
+ name : 'input' ,
901
+ } , {
902
+ component : components . TEXT_FIELD ,
903
+ name : 'unmounted' ,
904
+ initialValue : false ,
905
+ initializeOnMount : true ,
906
+ condition : {
907
+ when : 'input' ,
908
+ is : 'show_false' ,
909
+ } ,
910
+ } , {
911
+ component : components . TEXT_FIELD ,
912
+ name : 'unmounted' ,
913
+ initialValue : true ,
914
+ initializeOnMount : true ,
915
+ condition : {
916
+ when : 'input' ,
917
+ is : 'show_true' ,
918
+ } ,
919
+ } ] ,
920
+ } ;
921
+
922
+ const onSubmit = jest . fn ( ) ;
923
+
924
+ const wrapper = mount (
925
+ < FormRenderer
926
+ layoutMapper = { layoutMapper }
927
+ formFieldsMapper = { {
928
+ [ components . TEXT_FIELD ] : TextField ,
929
+ } }
930
+ schema = { schema }
931
+ onSubmit = { onSubmit }
932
+ />
933
+ ) ;
934
+
935
+ wrapper . find ( 'input' ) . first ( ) . simulate ( 'change' , { target : { value : 'show_true' } } ) ;
936
+ wrapper . update ( ) ;
937
+
938
+ wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
939
+
940
+ expect ( onSubmit ) . toHaveBeenCalledWith ( { input : 'show_true' , unmounted : true } , expect . any ( Object ) , expect . any ( Function ) ) ;
941
+ onSubmit . mockClear ( ) ;
942
+
943
+ wrapper . find ( 'input' ) . first ( ) . simulate ( 'change' , { target : { value : 'show_false' } } ) ;
944
+ wrapper . update ( ) ;
945
+
946
+ wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
947
+ wrapper . update ( ) ;
948
+
949
+ expect ( onSubmit ) . toHaveBeenCalledWith ( { input : 'show_false' , unmounted : false } , expect . any ( Object ) , expect . any ( Function ) ) ;
950
+ } ) ;
951
+
952
+ it ( 'should set unefined value in initializeOnMount' , ( ) => {
953
+ layoutMapper = {
954
+ [ layoutComponents . FORM_WRAPPER ] : ( { children, ...props } ) => < form { ...props } > { children } </ form > ,
955
+ [ layoutComponents . BUTTON ] : ( { label, ...rest } ) => < button { ...rest } > { label } </ button > ,
956
+ [ layoutComponents . BUTTON_GROUP ] : ( { children } ) => < div > { children } </ div > ,
957
+ [ layoutComponents . TITLE ] : ( { children } ) => < div > { children } </ div > ,
958
+ [ layoutComponents . DESCRIPTION ] : ( { children } ) => < div > { children } </ div > ,
959
+ } ;
960
+
961
+ const schema = {
962
+ fields : [ {
963
+ component : components . TEXT_FIELD ,
964
+ name : 'input' ,
965
+ } , {
966
+ component : components . TEXT_FIELD ,
967
+ name : 'unmounted' ,
968
+ initialValue : undefined ,
969
+ initializeOnMount : true ,
970
+ condition : {
971
+ when : 'input' ,
972
+ is : 'show_undef' ,
973
+ } ,
974
+ } , {
975
+ component : components . TEXT_FIELD ,
976
+ name : 'unmounted' ,
977
+ initialValue : true ,
978
+ initializeOnMount : true ,
979
+ condition : {
980
+ when : 'input' ,
981
+ is : 'show_true' ,
982
+ } ,
983
+ } ] ,
984
+ } ;
985
+
986
+ const onSubmit = jest . fn ( ) ;
987
+
988
+ const wrapper = mount (
989
+ < FormRenderer
990
+ layoutMapper = { layoutMapper }
991
+ formFieldsMapper = { {
992
+ [ components . TEXT_FIELD ] : TextField ,
993
+ } }
994
+ schema = { schema }
995
+ onSubmit = { onSubmit }
996
+ />
997
+ ) ;
998
+
999
+ wrapper . find ( 'input' ) . first ( ) . simulate ( 'change' , { target : { value : 'show_true' } } ) ;
1000
+ wrapper . update ( ) ;
1001
+
1002
+ wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
1003
+
1004
+ expect ( onSubmit ) . toHaveBeenCalledWith ( { input : 'show_true' , unmounted : true } , expect . any ( Object ) , expect . any ( Function ) ) ;
1005
+ onSubmit . mockClear ( ) ;
1006
+
1007
+ wrapper . find ( 'input' ) . first ( ) . simulate ( 'change' , { target : { value : 'show_undef' } } ) ;
1008
+ wrapper . update ( ) ;
1009
+
1010
+ wrapper . find ( 'form' ) . simulate ( 'submit' ) ;
1011
+ wrapper . update ( ) ;
1012
+
1013
+ expect ( onSubmit ) . toHaveBeenCalledWith ( { input : 'show_undef' , unmounted : undefined } , expect . any ( Object ) , expect . any ( Function ) ) ;
1014
+ } ) ;
887
1015
} ) ;
888
1016
} ) ;
0 commit comments