Skip to content

Commit 9d4dcf7

Browse files
committed
unit: more tests for stepper mutations
1 parent 2b72b71 commit 9d4dcf7

File tree

1 file changed

+80
-13
lines changed

1 file changed

+80
-13
lines changed

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

Lines changed: 80 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('FormMutations', () => {
2626
});
2727
});
2828

29-
describe('All actions in the state machine', () => {
29+
describe('All form actions in the state machine', () => {
3030
const onChange = jest.fn();
3131
const onError = jest.fn();
3232
const params = {
@@ -126,18 +126,6 @@ describe('FormMutations', () => {
126126
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
127127
});
128128

129-
it('stepChange', () => {
130-
const updateMutation = stateMachineService.send('updateTabIndex', {
131-
stepName: '',
132-
});
133-
const contextMutations = JSON.parse(JSON.stringify(updateMutation.context));
134-
delete contextMutations.effects;
135-
const expected = {"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": {}, "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 !"}}}}
136-
expect(contextMutations).toStrictEqual(expected);
137-
expect(onChange).toHaveBeenCalled();
138-
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
139-
});
140-
141129
it('updateTabIndex', () => {
142130
const updateMutation = stateMachineService.send('updateTabIndex', {
143131
tabIndex: 1,
@@ -221,4 +209,83 @@ describe('FormMutations', () => {
221209
expect(stateMachineService.state.value).toStrictEqual({"formUI": "invalid"});
222210
});
223211
});
212+
213+
214+
describe('All stepper actions in the state machine', () => {
215+
const onChange = jest.fn();
216+
const onError = jest.fn();
217+
const params = {
218+
uiSchema: {
219+
"ui:page": {
220+
"ui:layout": "tabs",
221+
"props": {
222+
"ui:schemaErrors": true
223+
},
224+
"style": {
225+
"boxShadow": "none"
226+
},
227+
"tabs": {
228+
"style": {
229+
"width": "29vw",
230+
"marginTop": 10
231+
}
232+
},
233+
"tab": {
234+
"style": {
235+
"minWidth": 81
236+
}
237+
}
238+
}
239+
},
240+
xhrSchema: {
241+
"ui:errors": {
242+
"offline": {
243+
"title": "You are Offline !",
244+
"message": "Please try again once you are online."
245+
}
246+
}
247+
},
248+
formSchema: {
249+
"properties": {
250+
"SelectComponents": {
251+
"title": "Select Components",
252+
"$ref": "#/definitions/componentsList"
253+
}
254+
}
255+
},
256+
formData: {},
257+
uiData: {},
258+
validation: {},
259+
validations: {},
260+
hasError: false,
261+
effects: {
262+
onChange,
263+
onError,
264+
},
265+
};
266+
const formStateMachine = createStateMachine(params);
267+
const stateMachineService = interpret(
268+
formStateMachine, { devTools: process.env.NODE_ENV === 'development' },
269+
).onTransition((state: any) => executeFormActionsByState({
270+
state,
271+
stateMachineService,
272+
}));
273+
const {
274+
result: { current: { executeFormActionsByState } },
275+
} = renderHook(() => useFormActions({
276+
isPartialUI: () => false,
277+
}));
278+
stateMachineService.start();
279+
it('stepChange', () => {
280+
const updateMutation = stateMachineService.send('stepChange', {
281+
stepName: '',
282+
});
283+
const contextMutations = JSON.parse(JSON.stringify(updateMutation.context));
284+
delete contextMutations.effects;
285+
const expected = {"activeStep": -1, "formData": {}, "formSchema": {"properties": {"SelectComponents": {"$ref": "#/definitions/componentsList", "title": "Select Components"}}}, "formSchemaXHR": {}, "hasError": false, "hasXHRError": false, "lastField": "", "parsedFormSchema": {"properties": {"SelectComponents": {"$ref": "#/definitions/componentsList", "title": "Select Components"}}}, "uiData": {}, "uiSchema": {"ui:page": {"props": {"ui:schemaErrors": true}, "style": {"boxShadow": "none"}, "tab": {"style": {"minWidth": 81}}, "tabs": {"style": {"marginTop": 10, "width": "29vw"}}, "ui:layout": "tabs"}}, "validations": {}, "xhrProgress": {}, "xhrSchema": {"ui:errors": {"offline": {"message": "Please try again once you are online.", "title": "You are Offline !"}}}}
286+
expect(contextMutations).toStrictEqual(expected);
287+
expect(onChange).toHaveBeenCalled();
288+
expect(stateMachineService.state.value).toStrictEqual({"formUI": "dirty"});
289+
});
290+
});
224291
});

0 commit comments

Comments
 (0)