Skip to content

Commit 5c18b81

Browse files
committed
unit: more tests for form mutations
1 parent 922c026 commit 5c18b81

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

src/helpers/state-machine/form/mutations/__tests__/form-state-mutations.spec.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,14 @@ describe('FormMutations', () => {
3131
const onError = jest.fn();
3232
const params = {
3333
uiSchema: {},
34-
xhrSchema: {},
34+
xhrSchema: {
35+
"ui:errors": {
36+
"offline": {
37+
"title": "You are Offline !",
38+
"message": "Please try again once you are online."
39+
}
40+
}
41+
},
3542
formSchema: {},
3643
formData: {},
3744
uiData: {},
@@ -63,7 +70,7 @@ describe('FormMutations', () => {
6370
});
6471
const contextMutations = JSON.parse(JSON.stringify(updateMutation.context));
6572
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": {}}
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}
6774
expect(contextMutations).toStrictEqual(expected);
6875
expect(onChange).toHaveBeenCalledTimes(2);
6976
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
@@ -81,7 +88,7 @@ describe('FormMutations', () => {
8188
});
8289
const contextMutations = JSON.parse(JSON.stringify(updateFormOnXHRComplete.context));
8390
delete contextMutations.effects;
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": {}};
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};
8592
expect(contextMutations).toStrictEqual(expected);
8693
expect(onChange).toHaveBeenCalledTimes(3);
8794
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
@@ -91,7 +98,7 @@ describe('FormMutations', () => {
9198
const updateFormOnXHRComplete = stateMachineService.send('updateFormOnXHRComplete', {});
9299
const contextMutations = JSON.parse(JSON.stringify(updateFormOnXHRComplete.context));
93100
delete contextMutations.effects;
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": {}};
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};
95102
expect(contextMutations).toStrictEqual(expected);
96103
expect(onChange).toHaveBeenCalledTimes(4);
97104
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
@@ -106,7 +113,7 @@ describe('FormMutations', () => {
106113
});
107114
const contextMutations = JSON.parse(JSON.stringify(updateMutation.context));
108115
delete contextMutations.effects;
109-
const expected = {"activeStep": 0, "formData": {}, "formSchema": {}, "formSchemaXHR": {"new": "info"}, "hasError": false, "hasXHRError": false, "lastField": "test", "parsedFormSchema": {}, "uiData": {}, "uiSchema": {}, "validation": {}, "validations": {}, "xhrProgress": {"undefined": false}, "xhrSchema": {}};
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};
110117
expect(contextMutations).toStrictEqual(expected);
111118
expect(onChange).toHaveBeenCalledTimes(5);
112119
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
@@ -119,7 +126,7 @@ describe('FormMutations', () => {
119126
});
120127
const contextMutations = JSON.parse(JSON.stringify(noErrors.context));
121128
delete contextMutations.effects;
122-
const expected = {"activeStep": 0, "hasError": false, "formData": {}, "formSchema": {}, "formSchemaXHR": {"new": "info"}, "hasXHRError": false, "lastField": "test", "parsedFormSchema": {}, "uiData": {}, "uiSchema": {}, "validations": {}, "xhrProgress": {"undefined": false}, "xhrSchema": {}};
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};
123130
expect(contextMutations).toStrictEqual(expected);
124131
expect(onChange).toHaveBeenCalledTimes(5);
125132
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
@@ -140,7 +147,7 @@ describe('FormMutations', () => {
140147
});
141148
const contextMutations = JSON.parse(JSON.stringify(updateErrorXHRProgress.context));
142149
delete contextMutations.effects;
143-
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": {}};
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};
144151
expect(contextMutations).toStrictEqual(expected);
145152
expect(onChange).toHaveBeenCalledTimes(6);
146153
expect(stateMachineService.state.value).toStrictEqual({"formUI": "invalid"});
@@ -161,7 +168,7 @@ describe('FormMutations', () => {
161168
});
162169
const contextMutations = JSON.parse(JSON.stringify(updateErrorXHRProgress.context));
163170
delete contextMutations.effects;
164-
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": {}};
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 !"}}}};
165172
expect(contextMutations).toStrictEqual(expected);
166173
expect(onChange).toHaveBeenCalledTimes(7);
167174
expect(stateMachineService.state.value).toStrictEqual({"formUI": "invalid"});

0 commit comments

Comments
 (0)