aboutsummaryrefslogtreecommitdiffstats
path: root/src/scenario/DSL.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/scenario/DSL.js')
-rw-r--r--src/scenario/DSL.js125
1 files changed, 97 insertions, 28 deletions
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js
index b713cfd6..0607238c 100644
--- a/src/scenario/DSL.js
+++ b/src/scenario/DSL.js
@@ -1,38 +1,53 @@
angular.scenario.dsl.browser = {
navigateTo: function(url){
- $scenario.addStep('Navigate to: ' + url, function(done){
+ var location = this.location;
+ return $scenario.addFuture('Navigate to: ' + url, function(done){
var self = this;
this.testFrame.load(function(){
self.testFrame.unbind();
self.testWindow = self.testFrame[0].contentWindow;
- self.testDocument = jQuery(self.testWindow.document);
+ self.testDocument = self.jQuery(self.testWindow.document);
self.$browser = self.testWindow.angular.service.$browser();
- self.notifyWhenNoOutstandingRequests = bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests);
+ self.notifyWhenNoOutstandingRequests =
+ bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests);
self.notifyWhenNoOutstandingRequests(done);
});
if (this.testFrame.attr('src') == url) {
this.testFrame[0].contentWindow.location.reload();
} else {
this.testFrame.attr('src', url);
+ location.setLocation(url);
}
});
+ },
+ location: {
+ href: "",
+ hash: "",
+ toEqual: function(url) {
+ return (this.hash == "" ? (url == this.href) :
+ (url == (this.href + "/#/" + this.hash)));
+ },
+ setLocation: function(url) {
+ var urlParts = url.split("/#/");
+ this.href = urlParts[0] || "";
+ this.hash = urlParts[1] || "";
+ }
}
};
angular.scenario.dsl.input = function(selector) {
+ var namePrefix = "input '" + selector + "'";
return {
- enter: function(value){
- $scenario.addStep("Set input text of '" + selector + "' to '" +
- value + "'", function(done){
- var input = this.testDocument.find('input[name=' + selector + ']');
- input.val(value);
- this.testWindow.angular.element(input[0]).trigger('change');
- done();
+ enter: function(value) {
+ return $scenario.addFuture(namePrefix + " enter '" + value + "'", function(done) {
+ var input = this.testDocument.find('input[name=' + selector + ']');
+ input.val(value);
+ this.testWindow.angular.element(input[0]).trigger('change');
+ done();
});
},
- select: function(value){
- $scenario.addStep("Select radio '" + selector + "' to '" +
- value + "'", function(done){
+ select: function(value) {
+ return $scenario.addFuture(namePrefix + " select '" + value + "'", function(done) {
var input = this.testDocument.
find(':radio[name$=@' + selector + '][value=' + value + ']');
jqLiteWrap(input[0]).trigger('click');
@@ -41,22 +56,76 @@ angular.scenario.dsl.input = function(selector) {
});
}
};
-};
+},
-angular.scenario.dsl.expect = {
- repeater: function(selector) {
- return {
- count: {
- toEqual: function(number) {
- $scenario.addStep("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) {
- var items = this.testDocument.find(selector);
- if (items.length != number) {
- this.result.fail("Expected " + number + " but was " + items.length);
- }
- done();
+angular.scenario.dsl.NG_BIND_PATTERN =/\{\{[^\}]+\}\}/;
+
+angular.scenario.dsl.repeater = function(selector) {
+ var namePrefix = "repeater '" + selector + "'";
+ return {
+ count: function() {
+ return $scenario.addFuture(namePrefix + ' count', function(done) {
+ done(this.testDocument.find(selector).size());
+ });
+ },
+ collect: function(collectSelector) {
+ return $scenario.addFuture(
+ namePrefix + " collect '" + collectSelector + "'",
+ function(done) {
+ var self = this;
+ var doCollect = bind(this, function() {
+ var repeaterArray = [], ngBindPattern;
+ var startIndex = collectSelector.search(
+ angular.scenario.dsl.NG_BIND_PATTERN);
+ if (startIndex >= 0) {
+ ngBindPattern = collectSelector.substring(
+ startIndex + 2, collectSelector.length - 2);
+ collectSelector = '*';
+
+ }
+ this.testDocument.find(selector).each(function() {
+ var element = self.jQuery(this);
+ element.find(collectSelector).
+ each(function() {
+ var foundElem = self.jQuery(this);
+ if (foundElem.attr('ng:bind') == ngBindPattern) {
+ repeaterArray.push(foundElem.text());
+ }
+ });
});
- }
- }
- };
+ return repeaterArray;
+ });
+ done(doCollect());
+ });
+ }
+ };
+};
+
+angular.scenario.dsl.element = function(selector) {
+ var namePrefix = "Element '" + selector + "'";
+ var futureJquery = {};
+ for (key in (jQuery || _jQuery).fn) {
+ (function(){
+ var jqFnName = key;
+ var jqFn = (jQuery || _jQuery).fn[key];
+ futureJquery[key] = function() {
+ var jqArgs = arguments;
+ return $scenario.addFuture(namePrefix + "." + jqFnName + "()",
+ function(done) {
+ var self = this, repeaterArray = [], ngBindPattern;
+ var startIndex = selector.search(angular.scenario.dsl.NG_BIND_PATTERN);
+ if (startIndex >= 0) {
+ ngBindPattern = selector.substring(startIndex + 2, selector.length - 2);
+ var element = this.testDocument.find('*').filter(function() {
+ return self.jQuery(this).attr('ng:bind') == ngBindPattern;
+ });
+ done(jqFn.apply(element, jqArgs));
+ } else {
+ done(jqFn.apply(this.testDocument.find(selector), jqArgs));
+ }
+ });
+ };
+ })();
}
+ return futureJquery;
};