@@ -27,6 +27,8 @@ describe('FormMutations', () => {
27
27
} ) ;
28
28
29
29
describe ( 'All actions in the state machine' , ( ) => {
30
+ const onChange = jest . fn ( ) ;
31
+ const onError = jest . fn ( ) ;
30
32
const params = {
31
33
uiSchema : { } ,
32
34
xhrSchema : { } ,
@@ -37,8 +39,8 @@ describe('FormMutations', () => {
37
39
validations : { } ,
38
40
hasError : false ,
39
41
effects : {
40
- onChange : jest . fn ( ) ,
41
- onError : jest . fn ( ) ,
42
+ onChange,
43
+ onError,
42
44
} ,
43
45
} ;
44
46
const formStateMachine = createStateMachine ( params ) ;
@@ -55,10 +57,30 @@ describe('FormMutations', () => {
55
57
} ) ) ;
56
58
stateMachineService . start ( ) ;
57
59
it ( 'updateData' , ( ) => {
58
- stateMachineService . send ( 'update' , {
60
+ const updateMutation = stateMachineService . send ( 'update' , {
59
61
field : 'test' ,
60
62
givenValue : 'test-2'
61
63
} ) ;
64
+ const contextMutations = JSON . parse ( JSON . stringify ( updateMutation . context ) ) ;
65
+ delete contextMutations . effects ;
66
+ const expected = { "activeStep" : 0 , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { } , "hasError" : false , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validation" : { } , "validations" : { } , "xhrProgress" : { } , "xhrSchema" : { } }
67
+ expect ( contextMutations ) . toStrictEqual ( expected ) ;
68
+ } ) ;
69
+ it ( 'updateXHRData' , ( ) => {
70
+ const updateMutation = stateMachineService . send ( 'updateFormOnXHRComplete' , {
71
+ formSchema : {
72
+ 'new' : 'info'
73
+ } ,
74
+ formSchemaXHR : {
75
+ 'new' : 'info'
76
+ } ,
77
+ formData : { } ,
78
+ uiData : { }
79
+ } ) ;
80
+ const contextMutations = JSON . parse ( JSON . stringify ( updateMutation . context ) ) ;
81
+ delete contextMutations . effects ;
82
+ const expected = { "activeStep" : 0 , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validation" : { } , "validations" : { } , "xhrProgress" : { "undefined" : false } , "xhrSchema" : { } } ;
83
+ expect ( contextMutations ) . toStrictEqual ( expected ) ;
62
84
} ) ;
63
85
} ) ;
64
86
} ) ;
0 commit comments