@@ -65,9 +65,11 @@ describe('FormMutations', () => {
65
65
delete contextMutations . effects ;
66
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
67
expect ( contextMutations ) . toStrictEqual ( expected ) ;
68
+ expect ( onChange ) . toHaveBeenCalledTimes ( 2 ) ;
69
+ expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
68
70
} ) ;
69
71
it ( 'updateXHRData' , ( ) => {
70
- const updateMutation = stateMachineService . send ( 'updateFormOnXHRComplete' , {
72
+ const updateFormOnXHRComplete = stateMachineService . send ( 'updateFormOnXHRComplete' , {
71
73
formSchema : {
72
74
'new' : 'info'
73
75
} ,
@@ -77,18 +79,76 @@ describe('FormMutations', () => {
77
79
formData : { } ,
78
80
uiData : { }
79
81
} ) ;
80
- const contextMutations = JSON . parse ( JSON . stringify ( updateMutation . context ) ) ;
82
+ const contextMutations = JSON . parse ( JSON . stringify ( updateFormOnXHRComplete . context ) ) ;
81
83
delete contextMutations . effects ;
82
84
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
85
expect ( contextMutations ) . toStrictEqual ( expected ) ;
86
+ expect ( onChange ) . toHaveBeenCalledTimes ( 3 ) ;
87
+ expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
84
88
} ) ;
85
89
86
90
it ( 'updateXHRData (edge case)' , ( ) => {
87
- const updateMutation = stateMachineService . send ( 'updateFormOnXHRComplete' , { } ) ;
88
- const contextMutations = JSON . parse ( JSON . stringify ( updateMutation . context ) ) ;
91
+ const updateFormOnXHRComplete = stateMachineService . send ( 'updateFormOnXHRComplete' , { } ) ;
92
+ const contextMutations = JSON . parse ( JSON . stringify ( updateFormOnXHRComplete . context ) ) ;
89
93
delete contextMutations . effects ;
90
94
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" : { } } ;
91
95
expect ( contextMutations ) . toStrictEqual ( expected ) ;
96
+ expect ( onChange ) . toHaveBeenCalledTimes ( 4 ) ;
97
+ expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
98
+ } ) ;
99
+
100
+ it ( 'updateErrorData' , ( ) => {
101
+ const noErrors = stateMachineService . send ( 'noErrors' , {
102
+ hasError : false ,
103
+ } ) ;
104
+ const contextMutations = JSON . parse ( JSON . stringify ( noErrors . context ) ) ;
105
+ delete contextMutations . effects ;
106
+ const expected = { "activeStep" : 0 , "hasError" : false , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validations" : { } , "xhrProgress" : { "undefined" : false } , "xhrSchema" : { } } ;
107
+ expect ( contextMutations ) . toStrictEqual ( expected ) ;
108
+ expect ( onChange ) . toHaveBeenCalledTimes ( 4 ) ;
109
+ expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
110
+ } ) ;
111
+
112
+ it ( 'updateErrorXHRProgress' , ( ) => {
113
+ const updateErrorXHRProgress = stateMachineService . send ( 'errorXHRProgress' , {
114
+ status : true ,
115
+ statusCode : 500 ,
116
+ formSchema : {
117
+ 'new' : 'info'
118
+ } ,
119
+ formSchemaXHR : {
120
+ 'new' : 'info'
121
+ } ,
122
+ formData : { } ,
123
+ uiData : { }
124
+ } ) ;
125
+ const contextMutations = JSON . parse ( JSON . stringify ( updateErrorXHRProgress . context ) ) ;
126
+ delete contextMutations . effects ;
127
+ const expected = { "activeStep" : 0 , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : true , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validation" : { "xhr" : [ ] } , "validations" : { } , "xhrProgress" : { "undefined" : true } , "xhrSchema" : { } } ;
128
+ expect ( contextMutations ) . toStrictEqual ( expected ) ;
129
+ expect ( onChange ) . toHaveBeenCalledTimes ( 5 ) ;
130
+ expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "invalid" } ) ;
131
+ } ) ;
132
+
133
+ it ( 'updateErrorXHRProgress (offline)' , ( ) => {
134
+ const updateErrorXHRProgress = stateMachineService . send ( 'errorXHRProgress' , {
135
+ status : true ,
136
+ statusCode : 999 ,
137
+ formSchema : {
138
+ 'new' : 'info'
139
+ } ,
140
+ formSchemaXHR : {
141
+ 'new' : 'info'
142
+ } ,
143
+ formData : { } ,
144
+ uiData : { }
145
+ } ) ;
146
+ const contextMutations = JSON . parse ( JSON . stringify ( updateErrorXHRProgress . context ) ) ;
147
+ delete contextMutations . effects ;
148
+ const expected = { "activeStep" : 0 , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : true , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validation" : { "xhr" : [ ] } , "validations" : { } , "xhrProgress" : { "undefined" : true } , "xhrSchema" : { } } ;
149
+ expect ( contextMutations ) . toStrictEqual ( expected ) ;
150
+ expect ( onChange ) . toHaveBeenCalledTimes ( 6 ) ;
151
+ expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "invalid" } ) ;
92
152
} ) ;
93
153
} ) ;
94
154
} ) ;
0 commit comments