Skip to content

Commit 922c026

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

File tree

1 file changed

+22
-6
lines changed

1 file changed

+22
-6
lines changed

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

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,31 @@ describe('FormMutations', () => {
9797
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
9898
});
9999

100+
it('updateArrayData', () => {
101+
const updateArrayFN = jest.fn();
102+
const updateMutation = stateMachineService.send('moveItemUp', {
103+
field: 'test',
104+
givenValue: 'test-2',
105+
updateArrayFN,
106+
});
107+
const contextMutations = JSON.parse(JSON.stringify(updateMutation.context));
108+
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": {}};
110+
expect(contextMutations).toStrictEqual(expected);
111+
expect(onChange).toHaveBeenCalledTimes(5);
112+
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
113+
expect(updateArrayFN).toHaveBeenCalledTimes(1);
114+
});
115+
100116
it('updateErrorData', () => {
101117
const noErrors = stateMachineService.send('noErrors', {
102118
hasError: false,
103119
});
104120
const contextMutations = JSON.parse(JSON.stringify(noErrors.context));
105121
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": {}};
122+
const expected = {"activeStep": 0, "hasError": false, "formData": {}, "formSchema": {}, "formSchemaXHR": {"new": "info"}, "hasXHRError": false, "lastField": "test", "parsedFormSchema": {}, "uiData": {}, "uiSchema": {}, "validations": {}, "xhrProgress": {"undefined": false}, "xhrSchema": {}};
107123
expect(contextMutations).toStrictEqual(expected);
108-
expect(onChange).toHaveBeenCalledTimes(4);
124+
expect(onChange).toHaveBeenCalledTimes(5);
109125
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
110126
});
111127

@@ -124,9 +140,9 @@ describe('FormMutations', () => {
124140
});
125141
const contextMutations = JSON.parse(JSON.stringify(updateErrorXHRProgress.context));
126142
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": {}};
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": {}};
128144
expect(contextMutations).toStrictEqual(expected);
129-
expect(onChange).toHaveBeenCalledTimes(5);
145+
expect(onChange).toHaveBeenCalledTimes(6);
130146
expect(stateMachineService.state.value).toStrictEqual({"formUI": "invalid"});
131147
});
132148

@@ -145,9 +161,9 @@ describe('FormMutations', () => {
145161
});
146162
const contextMutations = JSON.parse(JSON.stringify(updateErrorXHRProgress.context));
147163
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": {}};
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": {}};
149165
expect(contextMutations).toStrictEqual(expected);
150-
expect(onChange).toHaveBeenCalledTimes(6);
166+
expect(onChange).toHaveBeenCalledTimes(7);
151167
expect(stateMachineService.state.value).toStrictEqual({"formUI": "invalid"});
152168
});
153169
});

0 commit comments

Comments
 (0)