Skip to content

Commit 9ee2406

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

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// Import
2-
import { renderHook, act } from '@testing-library/react-hooks';
2+
import { renderHook } from '@testing-library/react-hooks';
33
import useFormStateMachine from '../form-state-machine.hooks';
44

55
describe('Form State Guards', () => {

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,14 @@
1+
// Library
2+
import { interpret } from 'xstate';
3+
import { renderHook } from '@testing-library/react-hooks';
4+
15
// Import
26
import FormMutations from '../form-state.mutations';
37

8+
// Helpers
9+
import createStateMachine from '../../../create-state-machine';
10+
import useFormActions from '../../actions';
11+
412
describe('FormMutations', () => {
513
[
614
'updateData',
@@ -17,4 +25,40 @@ describe('FormMutations', () => {
1725
expect(JSON.stringify(fieldStates)).toBe(expected);
1826
});
1927
});
28+
29+
describe('All actions in the state machine', () => {
30+
const params = {
31+
uiSchema: {},
32+
xhrSchema: {},
33+
formSchema: {},
34+
formData: {},
35+
uiData: {},
36+
validation: {},
37+
validations: {},
38+
hasError: false,
39+
effects: {
40+
onChange: jest.fn(),
41+
onError: jest.fn(),
42+
},
43+
};
44+
const formStateMachine = createStateMachine(params);
45+
const stateMachineService = interpret(
46+
formStateMachine, { devTools: process.env.NODE_ENV === 'development' },
47+
).onTransition((state: any) => executeFormActionsByState({
48+
state,
49+
stateMachineService,
50+
}));
51+
const {
52+
result: { current: { executeFormActionsByState } },
53+
} = renderHook(() => useFormActions({
54+
isPartialUI: () => false,
55+
}));
56+
stateMachineService.start();
57+
it('updateData', () => {
58+
stateMachineService.send('update', {
59+
field: 'test',
60+
givenValue: 'test-2'
61+
});
62+
});
63+
});
2064
});

0 commit comments

Comments
 (0)