Skip to content

Commit 7a56812

Browse files
committed
unit: more tests for form mutations
1 parent 9ee2406 commit 7a56812

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

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

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ describe('FormMutations', () => {
2727
});
2828

2929
describe('All actions in the state machine', () => {
30+
const onChange = jest.fn();
31+
const onError = jest.fn();
3032
const params = {
3133
uiSchema: {},
3234
xhrSchema: {},
@@ -37,8 +39,8 @@ describe('FormMutations', () => {
3739
validations: {},
3840
hasError: false,
3941
effects: {
40-
onChange: jest.fn(),
41-
onError: jest.fn(),
42+
onChange,
43+
onError,
4244
},
4345
};
4446
const formStateMachine = createStateMachine(params);
@@ -55,10 +57,30 @@ describe('FormMutations', () => {
5557
}));
5658
stateMachineService.start();
5759
it('updateData', () => {
58-
stateMachineService.send('update', {
60+
const updateMutation = stateMachineService.send('update', {
5961
field: 'test',
6062
givenValue: 'test-2'
6163
});
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);
6284
});
6385
});
6486
});

0 commit comments

Comments
 (0)