@@ -30,7 +30,28 @@ describe('FormMutations', () => {
30
30
const onChange = jest . fn ( ) ;
31
31
const onError = jest . fn ( ) ;
32
32
const params = {
33
- uiSchema : { } ,
33
+ uiSchema : {
34
+ "ui:page" : {
35
+ "ui:layout" : "tabs" ,
36
+ "props" : {
37
+ "ui:schemaErrors" : true
38
+ } ,
39
+ "style" : {
40
+ "boxShadow" : "none"
41
+ } ,
42
+ "tabs" : {
43
+ "style" : {
44
+ "width" : "29vw" ,
45
+ "marginTop" : 10
46
+ }
47
+ } ,
48
+ "tab" : {
49
+ "style" : {
50
+ "minWidth" : 81
51
+ }
52
+ }
53
+ }
54
+ } ,
34
55
xhrSchema : {
35
56
"ui:errors" : {
36
57
"offline" : {
@@ -70,11 +91,12 @@ describe('FormMutations', () => {
70
91
} ) ;
71
92
const contextMutations = JSON . parse ( JSON . stringify ( updateMutation . context ) ) ;
72
93
delete contextMutations . effects ;
73
- const expected = { "activeStep" : 0 , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { } , "hasError" : false , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validation" : { } , "validations" : { } , "xhrProgress" : { } , "xhrSchema" : params . xhrSchema }
94
+ const expected = { "activeStep" : 0 , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { } , "hasError" : false , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : params . uiSchema , "validation" : { } , "validations" : { } , "xhrProgress" : { } , "xhrSchema" : params . xhrSchema }
74
95
expect ( contextMutations ) . toStrictEqual ( expected ) ;
75
96
expect ( onChange ) . toHaveBeenCalledTimes ( 2 ) ;
76
97
expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
77
98
} ) ;
99
+
78
100
it ( 'updateXHRData' , ( ) => {
79
101
const updateFormOnXHRComplete = stateMachineService . send ( 'updateFormOnXHRComplete' , {
80
102
formSchema : {
@@ -88,7 +110,7 @@ describe('FormMutations', () => {
88
110
} ) ;
89
111
const contextMutations = JSON . parse ( JSON . stringify ( updateFormOnXHRComplete . context ) ) ;
90
112
delete contextMutations . effects ;
91
- 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" : params . xhrSchema } ;
113
+ const expected = { "activeStep" : 0 , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : params . uiSchema , "validation" : { } , "validations" : { } , "xhrProgress" : { "undefined" : false } , "xhrSchema" : params . xhrSchema } ;
92
114
expect ( contextMutations ) . toStrictEqual ( expected ) ;
93
115
expect ( onChange ) . toHaveBeenCalledTimes ( 3 ) ;
94
116
expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
@@ -98,9 +120,21 @@ describe('FormMutations', () => {
98
120
const updateFormOnXHRComplete = stateMachineService . send ( 'updateFormOnXHRComplete' , { } ) ;
99
121
const contextMutations = JSON . parse ( JSON . stringify ( updateFormOnXHRComplete . context ) ) ;
100
122
delete contextMutations . effects ;
101
- 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" : params . xhrSchema } ;
123
+ const expected = { "activeStep" : 0 , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : params . uiSchema , "validation" : { } , "validations" : { } , "xhrProgress" : { "undefined" : false } , "xhrSchema" : params . xhrSchema } ;
124
+ expect ( contextMutations ) . toStrictEqual ( expected ) ;
125
+ expect ( onChange ) . toHaveBeenCalled ( ) ;
126
+ expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
127
+ } ) ;
128
+
129
+ it ( 'updateTabIndex' , ( ) => {
130
+ const updateMutation = stateMachineService . send ( 'updateTabIndex' , {
131
+ tabIndex : 1 ,
132
+ } ) ;
133
+ const contextMutations = JSON . parse ( JSON . stringify ( updateMutation . context ) ) ;
134
+ delete contextMutations . effects ;
135
+ const expected = { "activeStep" : 1 , "formData" : { "test" : "test-2" } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { "ui:page" : { "props" : { "ui:schemaErrors" : true } , "style" : { "boxShadow" : "none" } , "tab" : { "style" : { "minWidth" : 81 } } , "tabs" : { "props" : { "tabIndex" : 1 } , "style" : { "marginTop" : 10 , "width" : "29vw" } } , "ui:layout" : "tabs" } } , "validation" : { } , "validations" : { } , "xhrProgress" : { "undefined" : false } , "xhrSchema" : { "ui:errors" : { "offline" : { "message" : "Please try again once you are online." , "title" : "You are Offline !" } } } }
102
136
expect ( contextMutations ) . toStrictEqual ( expected ) ;
103
- expect ( onChange ) . toHaveBeenCalledTimes ( 4 ) ;
137
+ expect ( onChange ) . toHaveBeenCalled ( ) ;
104
138
expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
105
139
} ) ;
106
140
@@ -113,9 +147,9 @@ describe('FormMutations', () => {
113
147
} ) ;
114
148
const contextMutations = JSON . parse ( JSON . stringify ( updateMutation . context ) ) ;
115
149
delete contextMutations . effects ;
116
- const expected = { "activeStep" : 0 , "formData" : { } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validation" : { } , "validations" : { } , "xhrProgress" : { "undefined" : false } , "xhrSchema" : params . xhrSchema } ;
150
+ const expected = { "activeStep" : 1 , "formData" : { } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { "ui:page" : { "props" : { "ui:schemaErrors" : true } , "style" : { "boxShadow" : "none" } , "tab" : { "style" : { "minWidth" : 81 } } , "tabs" : { "props" : { "tabIndex" : 1 } , "style" : { "marginTop" : 10 , "width" : "29vw" } } , "ui:layout" : "tabs" } } , " validation" : { } , "validations" : { } , "xhrProgress" : { "undefined" : false } , "xhrSchema" : { "ui:errors" : { "offline" : { "message" : "Please try again once you are online." , "title" : "You are Offline !" } } } } ;
117
151
expect ( contextMutations ) . toStrictEqual ( expected ) ;
118
- expect ( onChange ) . toHaveBeenCalledTimes ( 5 ) ;
152
+ expect ( onChange ) . toHaveBeenCalled ( ) ;
119
153
expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
120
154
expect ( updateArrayFN ) . toHaveBeenCalledTimes ( 1 ) ;
121
155
} ) ;
@@ -126,9 +160,9 @@ describe('FormMutations', () => {
126
160
} ) ;
127
161
const contextMutations = JSON . parse ( JSON . stringify ( noErrors . context ) ) ;
128
162
delete contextMutations . effects ;
129
- const expected = { "activeStep" : 0 , "hasError" : false , " formData" : { } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validations" : { } , "xhrProgress" : { "undefined" : false } , "xhrSchema" : params . xhrSchema } ;
163
+ const expected = { "activeStep" : 1 , "formData" : { } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , " hasXHRError" : false , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { "ui:page" : { "props" : { "ui:schemaErrors" : true } , "style" : { "boxShadow" : "none" } , "tab" : { "style" : { "minWidth" : 81 } } , "tabs" : { "props" : { "tabIndex" : 1 } , "style" : { "marginTop" : 10 , "width" : "29vw" } } , "ui:layout" : "tabs" } } , " validations" : { } , "xhrProgress" : { "undefined" : false } , "xhrSchema" : { "ui:errors" : { "offline" : { "message" : "Please try again once you are online." , "title" : "You are Offline !" } } } } ;
130
164
expect ( contextMutations ) . toStrictEqual ( expected ) ;
131
- expect ( onChange ) . toHaveBeenCalledTimes ( 5 ) ;
165
+ expect ( onChange ) . toHaveBeenCalled ( ) ;
132
166
expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "dirty" } ) ;
133
167
} ) ;
134
168
@@ -147,9 +181,9 @@ describe('FormMutations', () => {
147
181
} ) ;
148
182
const contextMutations = JSON . parse ( JSON . stringify ( updateErrorXHRProgress . context ) ) ;
149
183
delete contextMutations . effects ;
150
- const expected = { "activeStep" : 0 , "formData" : { } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : true , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validation" : { "xhr" : [ ] } , "validations" : { } , "xhrProgress" : { "undefined" : true } , "xhrSchema" : params . xhrSchema } ;
184
+ const expected = { "activeStep" : 1 , "formData" : { } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : true , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { "ui:page" : { "props" : { "ui:schemaErrors" : true } , "style" : { "boxShadow" : "none" } , "tab" : { "style" : { "minWidth" : 81 } } , "tabs" : { "props" : { "tabIndex" : 1 } , "style" : { "marginTop" : 10 , "width" : "29vw" } } , "ui:layout" : "tabs" } } , " validation" : { "xhr" : [ ] } , "validations" : { } , "xhrProgress" : { "undefined" : true } , "xhrSchema" : { "ui:errors" : { "offline" : { "message" : "Please try again once you are online." , "title" : "You are Offline !" } } } } ;
151
185
expect ( contextMutations ) . toStrictEqual ( expected ) ;
152
- expect ( onChange ) . toHaveBeenCalledTimes ( 6 ) ;
186
+ expect ( onChange ) . toHaveBeenCalled ( ) ;
153
187
expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "invalid" } ) ;
154
188
} ) ;
155
189
@@ -168,9 +202,9 @@ describe('FormMutations', () => {
168
202
} ) ;
169
203
const contextMutations = JSON . parse ( JSON . stringify ( updateErrorXHRProgress . context ) ) ;
170
204
delete contextMutations . effects ;
171
- const expected = { "activeStep" : 0 , "formData" : { } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : true , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { } , "validation" : { "xhr" : [ { "message" : "Please try again once you are online." , "rule" : "offline" , "title" : "You are Offline !" } ] } , "validations" : { } , "xhrProgress" : { "undefined" : true } , "xhrSchema" : { "ui:errors" : { "offline" : { "message" : "Please try again once you are online." , "title" : "You are Offline !" } } } } ;
205
+ const expected = { "activeStep" : 1 , "formData" : { } , "formSchema" : { } , "formSchemaXHR" : { "new" : "info" } , "hasError" : false , "hasXHRError" : true , "lastField" : "test" , "parsedFormSchema" : { } , "uiData" : { } , "uiSchema" : { "ui:page" : { "props" : { "ui:schemaErrors" : true } , "style" : { "boxShadow" : "none" } , "tab" : { "style" : { "minWidth" : 81 } } , "tabs" : { "props" : { "tabIndex" : 1 } , "style" : { "marginTop" : 10 , "width" : "29vw" } } , "ui:layout" : "tabs" } } , "validation" : { "xhr" : [ { "message" : "Please try again once you are online." , "rule" : "offline" , "title" : "You are Offline !" } ] } , "validations" : { } , "xhrProgress" : { "undefined" : true } , "xhrSchema" : { "ui:errors" : { "offline" : { "message" : "Please try again once you are online." , "title" : "You are Offline !" } } } } ;
172
206
expect ( contextMutations ) . toStrictEqual ( expected ) ;
173
- expect ( onChange ) . toHaveBeenCalledTimes ( 7 ) ;
207
+ expect ( onChange ) . toHaveBeenCalled ( ) ;
174
208
expect ( stateMachineService . state . value ) . toStrictEqual ( { "formUI" : "invalid" } ) ;
175
209
} ) ;
176
210
} ) ;
0 commit comments