Skip to content

Commit 39c6c59

Browse files
committed
get scenarios running again - open Runner.html in a browser to run them
1 parent 79b743e commit 39c6c59

12 files changed

Lines changed: 236 additions & 30 deletions

File tree

example/calculator-bootstrap.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
scope.set('a', 3);
1111
scope.updateView();
1212
});
13-
</script> </head>
13+
</script>
14+
</head>
1415
<body>
1516
Quantity: <input type="text" name="a" value="2">
1617
*

scenario/Runner.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<script type="text/javascript" src="../src/scenario/bootstrap.js"></script>
5+
<script type="text/javascript" src="widgets-scenarios.js"></script>
6+
<!--<script type="text/javascript" src="datastore-scenarios.js"></script>-->
7+
</head>
8+
<body>
9+
</body>
10+
</html>

scenario/datastore-scenarios.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
angular.scenarioDef.datastore = {
2+
$before:[
3+
{Given:"dataset",
4+
dataset:{
5+
Book:[{$id:'moby', name:"Moby Dick"},
6+
{$id:'gadsby', name:'Great Gadsby'}]
7+
}
8+
},
9+
{Given:"browser", at:"datastore.html#book=moby"},
10+
],
11+
checkLoadBook:[
12+
{Then:"drainRequestQueue"},
13+
14+
{Then:"text", at:"{{book.$id}}", should_be:"moby"},
15+
{Then:"text", at:"li[$index=0] {{book.name}}", should_be:"Great Gahdsby"},
16+
{Then:"text", at:"li[$index=0] {{book.name}}", should_be:"Moby Dick"},
17+
18+
]
19+
};

scenario/datastore.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<script type="text/javascript" src="../angular-bootstrap.js#database=$MEMORY"></script>
5+
</head>
6+
<body ng-entity="book=Book" ng-init="books=Book.all()">
7+
<p>{{book.$id}}</p>
8+
<li ng-repeat="book in books.$orderBy('name')">
9+
<li>{{book.name}}</li>
10+
</li>
11+
</body>
12+
</html>

scenario/widgets-scenarios.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
angular.scenarioDef.widgets = {
2+
$before:[
3+
{Given:"browser", at:"widgets.html"}
4+
],
5+
checkWidgetBinding:[
6+
{Then:"text", at:"{{name}}", should_be:""},
7+
{When:"enter", text:"John", at:":input[name=name]"},
8+
{Then:"text", at:"{{name}}", should_be:"John"},
9+
10+
{Then:"text", at:"{{gender}}", should_be:""},
11+
{When:"click", at:"input:radio[value=male]"},
12+
{Then:"text", at:"{{gender}}", should_be:"male"},
13+
14+
{Then:"text", at:"{{tea}}", should_be:"on"},
15+
{When:"click", at:"input[name=tea]"},
16+
{Then:"text", at:"{{tea}}", should_be:""},
17+
18+
{Then:"text", at:"{{coffee}}", should_be:""},
19+
{When:"click", at:"input[name=coffee]"},
20+
{Then:"text", at:"{{coffee}}", should_be:"on"},
21+
22+
{Then:"text", at:"{{count}}", should_be:0},
23+
{When:"click", at:"form :button"},
24+
{When:"click", at:"form :submit"},
25+
{When:"click", at:"form :image"},
26+
{Then:"text", at:"{{count}}", should_be:3},
27+
28+
{Then:"text", at:"{{select}}", should_be:"A"},
29+
{When:"select", at:"select[name=select]", option:"B"},
30+
{Then:"text", at:"{{select}}", should_be:"B"},
31+
32+
{Then:"text", at:"{{multiple}}", should_be:"[]"},
33+
{When:"select", at:"select[name=multiple]", option:"A"},
34+
{Then:"text", at:"{{multiple}}", should_be:["A"]},
35+
{When:"select", at:"select[name=multiple]", option:"B"},
36+
{Then:"text", at:"{{multiple}}", should_be:["A", "B"]},
37+
{When:"select", at:"select[name=multiple]", option:"A"},
38+
{Then:"text", at:"{{multiple}}", should_be:["B"]},
39+
40+
{Then:"text", at:"{{hidden}}", should_be:"hiddenValue"},
41+
42+
{Then:"text", at:"{{password}}", should_be:"passwordValue"},
43+
{When:"enter", text:"reset", at:":input[name=password]"},
44+
{Then:"text", at:"{{password}}", should_be:"reset"},
45+
],
46+
checkNewWidgetEmpty:[
47+
{Then:"text", at:"{{name}}", should_be:""},
48+
]
49+
};

scenario/widgets.html

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3+
<head>
4+
<script type="text/javascript" src="../lib/underscore/underscore.js"></script>
5+
<script type="text/javascript" src="../lib/jquery/jquery-1.3.2.js"></script>
6+
<script type="text/javascript" src="../src/angular-bootstrap.js"></script>
7+
<script type="text/javascript">
8+
$(document).ready(function(){angular.compile(document).init();});
9+
</script>
10+
</head>
11+
<body>
12+
<p>
13+
name: <input type="text" name="name" /> name={{name}} <br/>
14+
</p>
15+
<p>
16+
<input type="radio" name="gender" value="female"/> Female
17+
<input type="radio" name="gender" value="male"/> Male
18+
gender={{gender}}
19+
</p>
20+
<p>
21+
<input type="checkbox" name="tea" checked value="on"/> tea={{tea}} <br/>
22+
<input type="checkbox" name="coffee" value="on"/> coffee={{coffee}} <br/>
23+
</p>
24+
<p ng-init="count = 0">
25+
<form>
26+
<input type="button" value="button" ng-action="count = count + 1"/>
27+
<input type="submit" value="submit" ng-action="count = count + 1"/>
28+
<input type="image" src="" ng-action="count = count + 1"/>
29+
<a href="#ERROR" ng-action="count=count+1">action</a>
30+
count={{count}}
31+
</form>
32+
</p>
33+
<p>
34+
<select name="select">
35+
<option>A</option>
36+
<option>B</option>
37+
<option>C</option>
38+
</select>
39+
select={{select}}
40+
</p>
41+
<p>
42+
<select name="multiple" multiple>
43+
<option>A</option>
44+
<option>B</option>
45+
<option>C</option>
46+
</select>
47+
multiple={{multiple}}
48+
</p>
49+
<p>
50+
<input type="hidden" name="hidden" value="hiddenValue" />
51+
Hidden field = {{hidden}}
52+
</p>
53+
<p>
54+
<input type="password" name="password" value="passwordValue" />
55+
Password field = {{password}}
56+
</p>
57+
</body>
58+
</html>
Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
if (typeof test == 'undefined') test = {};
2-
3-
test.ScenarioRunner = function(scenarios, body) {
1+
var scenario = angular.scenario;
2+
scenario.SuiteRunner = function(scenarios, body) {
43
this.scenarios = scenarios;
54
this.body = body;
65
};
76

8-
test.ScenarioRunner.prototype = {
7+
scenario.SuiteRunner.prototype = {
98
run:function(){
109
this.setUpUI();
1110
this.runScenarios();
1211
},
12+
13+
1314
setUpUI:function(){
1415
this.body.html(
1516
'<div id="runner">' +
@@ -24,23 +25,25 @@ test.ScenarioRunner.prototype = {
2425
jQuery(this).parent().find('.log').toggle();
2526
});
2627
},
28+
29+
2730
runScenarios:function(){
28-
var runner = new test.Runner(this.console, this.testFrame);
29-
_.stepper(this.scenarios, function(next, scenario, name){
30-
new test.Scenario(name, scenario).run(runner, next);
31+
var runner = new scenario.Runner(this.console, this.testFrame);
32+
_.stepper(this.scenarios, function(next, scenarioObj, name){
33+
new scenario.Scenario(name, scenarioObj).run(runner, next);
3134
}, function(){
3235
}
3336
);
3437
}
3538
};
3639

37-
test.Runner = function(console, frame){
40+
scenario.Runner = function(console, frame){
3841
this.console = console;
3942
this.current = null;
4043
this.tests = [];
4144
this.frame = frame;
4245
};
43-
test.Runner.prototype = {
46+
scenario.Runner.prototype = {
4447
start:function(name){
4548
var current = this.current = {
4649
name:name,
@@ -86,11 +89,11 @@ test.Runner.prototype = {
8689
}
8790
};
8891

89-
test.Scenario = function(name, scenario){
92+
scenario.Scenario = function(name, scenario){
9093
this.name = name;
9194
this.scenario = scenario;
9295
};
93-
test.Scenario.prototype = {
96+
scenario.Scenario.prototype = {
9497
run:function(runner, callback) {
9598
var self = this;
9699
_.stepper(this.scenario, function(next, steps, name){
@@ -108,16 +111,20 @@ test.Scenario.prototype = {
108111
}
109112
}, callback);
110113
},
114+
115+
111116
verb:function(step){
112117
var fn = null;
113-
if (!step) fn = function (){ throw "Step is null!"; };
114-
else if (step.Given) fn = angular.test.GIVEN[step.Given];
115-
else if (step.When) fn = angular.test.WHEN[step.When];
116-
else if (step.Then) fn = angular.test.THEN[step.Then];
117-
return fn || function (){
118-
throw "ERROR: Need Given/When/Then got: " + toJson(step);
119-
};
118+
if (!step) fn = function (){ throw "Step is null!"; };
119+
else if (step.Given) fn = scenario.GIVEN[step.Given];
120+
else if (step.When) fn = scenario.WHEN[step.When];
121+
else if (step.Then) fn = scenario.THEN[step.Then];
122+
return fn || function (){
123+
throw "ERROR: Need Given/When/Then got: " + toJson(step);
124+
};
120125
},
126+
127+
121128
context: function(runner) {
122129
var frame = runner.frame;
123130
var window = frame[0].contentWindow;
@@ -144,11 +151,13 @@ test.Scenario.prototype = {
144151
};
145152
return context;
146153
},
154+
155+
147156
executeStep:function(runner, step, callback) {
148157
if (!step) {
149-
callback();
150-
return;
151-
}
158+
callback();
159+
return;
160+
}
152161
runner.log("info", toJson(step));
153162
var fn = this.verb(step);
154163
var context = this.context(runner);
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
angular.test.GIVEN = {
1+
angular.scenario.GIVEN = {
22
browser:function(){
33
var self = this;
44
if (jQuery.browser.safari && this.frame.attr('src') == this.at) {
@@ -17,7 +17,7 @@ angular.test.GIVEN = {
1717
this.frame.name="$DATASET:" + toJson({dataset:this.dataset});
1818
}
1919
};
20-
angular.test.WHEN = {
20+
angular.scenario.WHEN = {
2121
enter:function(){
2222
var element = this.element(this.at);
2323
element.attr('value', this.text);
@@ -40,7 +40,7 @@ angular.test.WHEN = {
4040
element.change();
4141
}
4242
};
43-
angular.test.THEN = {
43+
angular.scenario.THEN = {
4444
text:function(){
4545
var element = this.element(this.at);
4646
if (typeof this.should_be != undefined ) {

src/scenario/_namespace.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
if (!angular) var angular = window['angular'] = {};
2+
if (!angular['scenario']) var angularScenario = angular['scenario'] = {};
3+
if (!angular['scenarioDef']) var scenarioDef = angular['scenarioDef'] = {};
4+
if (!angular['scenario']['GIVEN']) angularScenario['GIVEN'] = {};
5+
if (!angular['scenario']['WHEN']) angularScenario['WHEN'] = {};
6+
if (!angular['scenario']['THEN']) angularScenario['THEN'] = {};

src/scenario/bootstrap.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
(function(onLoadDelegate){
2+
var prefix = (function(){
3+
var filename = /(.*\/)bootstrap.js(#(.*))?/;
4+
var scripts = document.getElementsByTagName("script");
5+
for(var j = 0; j < scripts.length; j++) {
6+
var src = scripts[j].src;
7+
if (src && src.match(filename)) {
8+
var parts = src.match(filename);
9+
return parts[1];
10+
}
11+
}
12+
})();
13+
function addScript(path) {
14+
document.write('<script type="text/javascript" src="' + prefix + path + '"></script>');
15+
};
16+
function addCSS(path) {
17+
document.write('<link rel="stylesheet" type="text/css" href="' + prefix + path + '"/>');
18+
};
19+
window.onload = function(){
20+
if (!_.stepper) {
21+
_.stepper = function(collection, iterator, done){
22+
var keys = _.keys(collection);
23+
function next() {
24+
if (keys.length) {
25+
var key = keys.shift();
26+
iterator(next, collection[key], key);
27+
} else {
28+
(done||_.identity)();
29+
}
30+
}
31+
next();
32+
};
33+
}
34+
_.defer(function(){
35+
new angular.scenario.SuiteRunner(angular.scenarioDef, jQuery(document.body)).run();
36+
});
37+
(onLoadDelegate||function(){})();
38+
};
39+
addCSS("../../css/angular-scenario.css");
40+
addScript("../../lib/underscore/underscore.js");
41+
addScript("../../lib/jquery/jquery-1.3.2.js");
42+
addScript("../angular-bootstrap.js");
43+
addScript("_namespace.js");
44+
addScript("Steps.js");
45+
addScript("Runner.js");
46+
})(window.onload);
47+

0 commit comments

Comments
 (0)