@@ -18,7 +18,7 @@ test("multiple 'from' states for the same event", function() {
1818 equals ( fsm . current , 'green' , "initial state should be green" ) ;
1919
2020 ok ( fsm . can ( 'warn' ) , "should be able to warn from green state" )
21- ok ( fsm . can ( 'panic' ) , "should NOT be able to panic from green state" )
21+ ok ( fsm . can ( 'panic' ) , "should be able to panic from green state" )
2222 ok ( fsm . cannot ( 'calm' ) , "should NOT be able to calm from green state" )
2323 ok ( fsm . cannot ( 'clear' ) , "should NOT be able to clear from green state" )
2424
@@ -66,6 +66,48 @@ test("multiple 'to' states for the same event", function() {
6666
6767//-----------------------------------------------------------------------------
6868
69+ test ( "no-op transitions (github issue #5) with multiple from states" , function ( ) {
70+
71+ var fsm = StateMachine . create ( {
72+ initial : 'green' ,
73+ events : [
74+ { name : 'warn' , from : 'green' , to : 'yellow' } ,
75+ { name : 'panic' , from : [ 'green' , 'yellow' ] , to : 'red' } ,
76+ { name : 'noop' , from : [ 'green' , 'yellow' ] } , // NOTE: 'to' not specified
77+ { name : 'calm' , from : 'red' , to : 'yellow' } ,
78+ { name : 'clear' , from : [ 'yellow' , 'red' ] , to : 'green' } ,
79+ ] } ) ;
80+
81+ equals ( fsm . current , 'green' , "initial state should be green" ) ;
82+
83+ ok ( fsm . can ( 'warn' ) , "should be able to warn from green state" )
84+ ok ( fsm . can ( 'panic' ) , "should be able to panic from green state" )
85+ ok ( fsm . can ( 'noop' ) , "should be able to noop from green state" )
86+ ok ( fsm . cannot ( 'calm' ) , "should NOT be able to calm from green state" )
87+ ok ( fsm . cannot ( 'clear' ) , "should NOT be able to clear from green state" )
88+
89+ fsm . noop ( ) ; equals ( fsm . current , 'green' , "noop event should not transition" ) ;
90+ fsm . warn ( ) ; equals ( fsm . current , 'yellow' , "warn event should transition from green to yellow" ) ;
91+
92+ ok ( fsm . cannot ( 'warn' ) , "should NOT be able to warn from yellow state" )
93+ ok ( fsm . can ( 'panic' ) , "should be able to panic from yellow state" )
94+ ok ( fsm . can ( 'noop' ) , "should be able to noop from yellow state" )
95+ ok ( fsm . cannot ( 'calm' ) , "should NOT be able to calm from yellow state" )
96+ ok ( fsm . can ( 'clear' ) , "should be able to clear from yellow state" )
97+
98+ fsm . noop ( ) ; equals ( fsm . current , 'yellow' , "noop event should not transition" ) ;
99+ fsm . panic ( ) ; equals ( fsm . current , 'red' , "panic event should transition from yellow to red" ) ;
100+
101+ ok ( fsm . cannot ( 'warn' ) , "should NOT be able to warn from red state" )
102+ ok ( fsm . cannot ( 'panic' ) , "should NOT be able to panic from red state" )
103+ ok ( fsm . cannot ( 'noop' ) , "should NOT be able to noop from red state" )
104+ ok ( fsm . can ( 'calm' ) , "should be able to calm from red state" )
105+ ok ( fsm . can ( 'clear' ) , "should be able to clear from red state" )
106+
107+ } ) ;
108+
109+ //-----------------------------------------------------------------------------
110+
69111test ( "callbacks are called when appropriate for multiple 'from' and 'to' transitions" , function ( ) {
70112
71113 var called = [ ] ;
0 commit comments