Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Updated statechart logic so that if a state's initialSubstate is *not…
…* assigned a value then the default state used will be an empty state (Ki.EmptyState). A root state must *always* have its initialSubstate property assigned an explicit value.
- Loading branch information
Showing
4 changed files
with
132 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
// ========================================================================== | ||
// Ki.State Unit Test | ||
// ========================================================================== | ||
/*globals Ki externalState1 externalState2 */ | ||
|
||
var statechart, root, monitor, stateA, stateB, stateC, stateD, stateE, stateF; | ||
|
||
// .......................................................... | ||
// CONTENT CHANGING | ||
// | ||
|
||
module("Ki.Statechart: State Initial Substate Tests", { | ||
setup: function() { | ||
|
||
statechart = Ki.Statechart.create({ | ||
|
||
monitorIsActive: YES, | ||
|
||
rootState: Ki.State.design({ | ||
|
||
initialSubstate: 'a', | ||
|
||
a: Ki.State.design({ | ||
initialSubstate: 'c', | ||
c: Ki.State.design(), | ||
d: Ki.State.design() | ||
}), | ||
|
||
b: Ki.State.design({ | ||
e: Ki.State.design(), | ||
f: Ki.State.design() | ||
}) | ||
|
||
}) | ||
|
||
}); | ||
|
||
statechart.initStatechart(); | ||
|
||
root = statechart.get('rootState'); | ||
monitor = statechart.get('monitor'); | ||
stateA = statechart.getState('a'); | ||
stateB = statechart.getState('b'); | ||
stateC = statechart.getState('c'); | ||
stateD = statechart.getState('d'); | ||
stateE = statechart.getState('e'); | ||
stateF = statechart.getState('f'); | ||
}, | ||
|
||
teardown: function() { | ||
statechart = root = stateA = stateB = stateC = stateD = stateE = stateF = null; | ||
} | ||
}); | ||
|
||
test("check initial substates", function() { | ||
equals(root.get('initialSubstate'), stateA, "root state's initial substate should be state A"); | ||
equals(stateA.get('initialSubstate'), stateC, "state a's initial substate should be state c"); | ||
equals(stateC.get('initialSubstate'), null, "state c's initial substate should be null"); | ||
equals(stateD.get('initialSubstate'), null, "state d's initial substate should be null"); | ||
equals(SC.kindOf(stateB.get('initialSubstate'), Ki.EmptyState), true, "state b's initial substate should be an empty state"); | ||
equals(stateE.get('initialSubstate'), null, "state e's initial substate should be null"); | ||
equals(stateF.get('initialSubstate'), null, "state f's initial substate should be null"); | ||
}); | ||
|
||
test("go to state b and confirm current state is an empty state", function() { | ||
equals(stateC.get('isCurrentState'), true); | ||
monitor.reset(); | ||
statechart.gotoState(stateB); | ||
ok(monitor.matchSequence().begin().exited(stateC, stateA).entered(stateB, stateB.get('initialSubstate')).end()); | ||
equals(stateB.getPath('initialSubstate.isCurrentState'), true, "state b\'s initial substate should be the current state"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
0601cf9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good solution to the problem (identical to the one I had on my TODO list).
0601cf9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great minds think alike :-)