Skip to content

Commit

Permalink
Merge pull request #92 from Katahdin/master
Browse files Browse the repository at this point in the history
added in tests for history state
  • Loading branch information
etgryphon committed Nov 12, 2014
2 parents 8580b28 + 990d91c commit 5191bc7
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
<script src="http://code.jquery.com/jquery-2.1.1.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.14.0.css" type="text/css" media="screen" />
<script type="text/javascript" src="http://code.jquery.com/qunit/qunit-1.14.0.js"></script>
<script type="text/javascript" src="../stativus.js"></script>
<script type="text/javascript" src="libs/sample.js"></script>
<script type="text/javascript" src="libs/test_init.js"></script>
Expand All @@ -13,6 +13,7 @@
<script type="text/javascript" src="libs/test_get_set_remove.js"></script>
<script type="text/javascript" src="libs/test_async.js"></script>
<script type="text/javascript" src="libs/test_statechart_testing.js"></script>
<script type="text/javascript" src="libs/test_history.js"></script>

</head>
<body>
Expand All @@ -21,6 +22,11 @@ <h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>
<div id="qunit-fixture">
test markup, will be hidden
<button id="testButton">
Test Button.
</button>
</div>
</body>
</html>
71 changes: 71 additions & 0 deletions test/libs/test_history.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module("Module: Test Statechart History", {
setup: function(){

this.sc = Stativus.createStatechart();
this.sc.addState("parent", {
substatesAreConcurrent: true
});

this.sc.addState("childA", {
parentState:"parent",
initialSubstate: 'childA1',
states:[
{name:"childA1"},
{name:"childA2",
enterState:function(){
ok(true, 'Entered childA2');
}
}
]
});

this.sc.addState("childB", {
parentState:"parent",
initialSubstate: 'childB1',
events:{
"click #testButton":"gotoA2",
},
states:[
{name:"childB1"},
{name:"childB2",
enterState:function(){
ok(true, 'Entered childB2');
},

exitState: function(){
ok(true, 'Exited childB2');
}
}
],

exitState: function(){
ok(true, 'Exited childB');
start();
},

gotoA2:function(){
this.goToHistoryState("childA2");
}

});
}
});

asyncTest("Test to see if history state is calling exitState", function(){
this.sc.initStates('parent');
var state = this.sc.currentState()[0];
state.goToState("childA2");
state.goToState("childB2");
state.goToHistoryState("childA");

});


asyncTest("Test to see if history state works inside an click event", function(){
this.sc.initStates("default",'parent');
var state = this.sc.currentState()[0];
state.goToState("childA2");
state.goToState("childB2");
$("#testButton").click();

});

0 comments on commit 5191bc7

Please sign in to comment.