forked from jakesgordon/javascript-state-machine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaults.js
More file actions
62 lines (44 loc) · 1.65 KB
/
defaults.js
File metadata and controls
62 lines (44 loc) · 1.65 KB
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
import test from 'ava';
import StateMachine from '../src/app';
//-------------------------------------------------------------------------------------------------
const defaults = JSON.stringify(StateMachine.defaults);
test.afterEach.always('restore defaults', t => {
StateMachine.defaults = JSON.parse(defaults);
});
//-------------------------------------------------------------------------------------------------
test.serial('override global initialization defaults', t => {
StateMachine.defaults.init = {
name: 'boot',
from: 'booting'
}
var fsm = new StateMachine({
init: 'A',
transitions: [
{ name: 'step1', from: 'A', to: 'B' },
{ name: 'step2', from: 'B', to: 'C' }
]
});
t.is(fsm.state, 'A');
t.deepEqual(fsm.allStates(), [ 'booting', 'A', 'B', 'C' ]);
t.deepEqual(fsm.allTransitions(), [ 'boot', 'step1', 'step2' ]);
t.deepEqual(fsm.transitions(), [ 'step1' ]);
});
//-------------------------------------------------------------------------------------------------
test.serial('override global initialization defaults (again)', t => {
StateMachine.defaults.init = {
name: 'start',
from: 'unknown'
}
var fsm = new StateMachine({
init: 'A',
transitions: [
{ name: 'step1', from: 'A', to: 'B' },
{ name: 'step2', from: 'B', to: 'C' }
]
});
t.is(fsm.state, 'A');
t.deepEqual(fsm.allStates(), [ 'unknown', 'A', 'B', 'C' ]);
t.deepEqual(fsm.allTransitions(), [ 'start', 'step1', 'step2' ]);
t.deepEqual(fsm.transitions(), [ 'step1' ]);
});
//-------------------------------------------------------------------------------------------------