aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAndres Ornelas2010-05-27 11:26:23 -0700
committerAndres Ornelas2010-05-27 11:26:23 -0700
commitcb5d21192787985bbff20b369e885639de253345 (patch)
tree127c401a80e03ac4f6ad657ddbc1dfe6841d0f2a /src
parent177873df86b6b069892184f24518959e7cef33cd (diff)
downloadangular.js-cb5d21192787985bbff20b369e885639de253345.tar.bz2
extracted switchRouteMatcher and added necessary libraries to angular-scenario
Diffstat (limited to 'src')
-rw-r--r--src/scenario/DSL.js2
-rw-r--r--src/scenario/Runner.js32
-rw-r--r--src/services.js25
-rw-r--r--src/widgets.js23
4 files changed, 43 insertions, 39 deletions
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index f1b9c226..b318e99c 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -4,8 +4,8 @@ angular.scenario.dsl.browser = {
var self = this;
self.testFrame.load(function(){
self.testFrame.unbind();
- self.testDocument = jQuery(self.testWindow.document);
self.testWindow = self.testFrame[0].contentWindow;
+ self.testDocument = jQuery(self.testWindow.document);
self.$browser = self.testWindow.angular.service.$browser();
self.notifyWhenNoOutstandingRequests = bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests);
self.notifyWhenNoOutstandingRequests(done);
diff --git a/src/scenario/Runner.js b/src/scenario/Runner.js
index 68c3ff65..da6e2c39 100644
--- a/src/scenario/Runner.js
+++ b/src/scenario/Runner.js
@@ -48,7 +48,6 @@ angular.scenario.Runner.prototype = {
jQuery(this).toggleClass('collapsed');
});
this.testFrame = body.find('#testView iframe');
- this.testWindow = this.testFrame[0].contentWindow;
function logger(parent) {
var container;
return function(type, text) {
@@ -100,27 +99,30 @@ angular.scenario.Runner.prototype = {
execute: function(name, callback) {
var spec = this.specs[name],
+ self = this,
result = {
- passed: false,
- failed: false,
- finished: false,
- fail: function(error) {
- result.passed = false;
- result.failed = true;
- result.error = error;
- result.log('fail', isString(error) ? error : toJson(error)).fail();
- }
- };
- specThis = {
+ passed: false,
+ failed: false,
+ finished: false,
+ fail: function(error) {
+ result.passed = false;
+ result.failed = true;
+ result.error = error;
+ result.log('fail', isString(error) ? error : toJson(error)).fail();
+ }
+ },
+ specThis = createScope({
result: result,
- testWindow: this.testWindow,
- testFrame: this.testFrame
- };
+ testFrame: this.testFrame,
+ testWindow: this.testWindow
+ }, angularService, {});
+ this.self = specThis;
var stepLogger = this.logger('spec', name);
spec.nextStepIndex = 0;
function done() {
result.finished = true;
stepLogger.close();
+ self.self = null;
(callback||noop).call(specThis);
}
function next(){
diff --git a/src/services.js b/src/services.js
index 940f1905..5f42ef18 100644
--- a/src/services.js
+++ b/src/services.js
@@ -158,10 +158,33 @@ angularService("$invalidWidgets", function(){
return invalidWidgets;
});
+function switchRouteMatcher(on, when, dstName) {
+ var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$',
+ params = [],
+ dst = {};
+ foreach(when.split(/\W/), function(param){
+ if (param) {
+ var paramRegExp = new RegExp(":" + param + "([\\W])");
+ if (regex.match(paramRegExp)) {
+ regex = regex.replace(paramRegExp, "([^\/]*)$1");
+ params.push(param);
+ }
+ }
+ });
+ var match = on.match(new RegExp(regex));
+ if (match) {
+ foreach(params, function(name, index){
+ dst[name] = match[index + 1];
+ });
+ if (dstName) this.$set(dstName, dst);
+ }
+ return match ? dst : null;
+}
+
angularService('$route', function(location, params){
var routes = {},
onChange = [],
- matcher = angularWidget('NG:SWITCH').route,
+ matcher = switchRouteMatcher,
parentScope = this,
dirty = 0,
$route = {
diff --git a/src/widgets.js b/src/widgets.js
index 1c9fe605..43bed81f 100644
--- a/src/widgets.js
+++ b/src/widgets.js
@@ -317,26 +317,5 @@ var ngSwitch = angularWidget('NG:SWITCH', function (element){
equals: function(on, when) {
return on == when;
},
- route: function(on, when, dstName) {
- var regex = '^' + when.replace(/[\.\\\(\)\^\$]/g, "\$1") + '$',
- params = [],
- dst = {};
- foreach(when.split(/\W/), function(param){
- if (param) {
- var paramRegExp = new RegExp(":" + param + "([\\W])");
- if (regex.match(paramRegExp)) {
- regex = regex.replace(paramRegExp, "([^\/]*)$1");
- params.push(param);
- }
- }
- });
- var match = on.match(new RegExp(regex));
- if (match) {
- foreach(params, function(name, index){
- dst[name] = match[index + 1];
- });
- if (dstName) this.$set(dstName, dst);
- }
- return match ? dst : null;
- }
+ route: switchRouteMatcher
});