deno.land / x / xstate@xstate@4.33.6 / test / deep.test.ts

نووسراو ببینە
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import { Machine } from '../src/index';
describe('deep transitions', () => { const deepMachine = Machine({ key: 'deep', initial: 'A', on: { MACHINE_EVENT: '#deep.DONE' }, states: { DONE: {}, FAIL: {}, A: { on: { A_EVENT: '#deep.DONE', B_EVENT: 'FAIL', // shielded by B's B_EVENT A_S: '#deep.P.Q.R.S', A_P: '#deep.P' }, onEntry: 'ENTER_A', onExit: 'EXIT_A', initial: 'B', states: { B: { on: { B_EVENT: '#deep.DONE' }, onEntry: 'ENTER_B', onExit: 'EXIT_B', initial: 'C', states: { C: { on: { C_EVENT: '#deep.DONE' }, onEntry: 'ENTER_C', onExit: 'EXIT_C', initial: 'D', states: { D: { on: { D_EVENT: '#deep.DONE', D_S: '#deep.P.Q.R.S', D_P: '#deep.P' }, onEntry: 'ENTER_D', onExit: 'EXIT_D' } } } } } } }, P: { on: { P_EVENT: '#deep.DONE', Q_EVENT: 'FAIL' // shielded by Q's Q_EVENT }, onEntry: 'ENTER_P', onExit: 'EXIT_P', initial: 'Q', states: { Q: { on: { Q_EVENT: '#deep.DONE' }, onEntry: 'ENTER_Q', onExit: 'EXIT_Q', initial: 'R', states: { R: { on: { R_EVENT: '#deep.DONE' }, onEntry: 'ENTER_R', onExit: 'EXIT_R', initial: 'S', states: { S: { on: { S_EVENT: '#deep.DONE' }, onEntry: 'ENTER_S', onExit: 'EXIT_S' } } } } } } } } });
describe('exiting super/substates', () => { it('should exit all substates when superstates exits (A_EVENT)', () => { const actual = deepMachine .transition(deepMachine.initialState, 'A_EVENT') .actions.map((a) => a.type); const expected = ['EXIT_D', 'EXIT_C', 'EXIT_B', 'EXIT_A']; expect(actual).toEqual(expected); });
it('should exit substates and superstates when exiting (B_EVENT)', () => { const actual = deepMachine .transition(deepMachine.initialState, 'B_EVENT') .actions.map((a) => a.type); const expected = ['EXIT_D', 'EXIT_C', 'EXIT_B', 'EXIT_A']; expect(actual).toEqual(expected); });
it('should exit substates and superstates when exiting (C_EVENT)', () => { const actual = deepMachine .transition(deepMachine.initialState, 'C_EVENT') .actions.map((a) => a.type); const expected = ['EXIT_D', 'EXIT_C', 'EXIT_B', 'EXIT_A']; expect(actual).toEqual(expected); });
it('should exit superstates when exiting (D_EVENT)', () => { const actual = deepMachine .transition(deepMachine.initialState, 'D_EVENT') .actions.map((a) => a.type); const expected = ['EXIT_D', 'EXIT_C', 'EXIT_B', 'EXIT_A']; expect(actual).toEqual(expected); });
it('should exit substate when machine handles event (MACHINE_EVENT)', () => { const actual = deepMachine .transition(deepMachine.initialState, 'MACHINE_EVENT') .actions.map((a) => a.type); const expected = ['EXIT_D', 'EXIT_C', 'EXIT_B', 'EXIT_A']; expect(actual).toEqual(expected); });
const DBCAPQRS = [ 'EXIT_D', 'EXIT_C', 'EXIT_B', 'EXIT_A', 'ENTER_P', 'ENTER_Q', 'ENTER_R', 'ENTER_S' ];
it('should exit deep and enter deep (A_S)', () => { const actual = deepMachine .transition(deepMachine.initialState, 'A_S') .actions.map((a) => a.type); const expected = DBCAPQRS; expect(actual).toEqual(expected); });
it('should exit deep and enter deep (D_P)', () => { const actual = deepMachine .transition(deepMachine.initialState, 'D_P') .actions.map((a) => a.type); const expected = DBCAPQRS; expect(actual).toEqual(expected); });
it('should exit deep and enter deep (A_P)', () => { const actual = deepMachine .transition(deepMachine.initialState, 'A_P') .actions.map((a) => a.type); const expected = DBCAPQRS; expect(actual).toEqual(expected); });
it('should exit deep and enter deep (D_S)', () => { const actual = deepMachine .transition(deepMachine.initialState, 'D_S') .actions.map((a) => a.type); const expected = DBCAPQRS; expect(actual).toEqual(expected); }); });});
xstate

Version Info

Tagged at
2 years ago