From e7b90956552bc129935e7b8dec947eb3e30f3c29 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Tue, 10 Aug 2010 19:10:43 -0700 Subject: Change repeater dsl to collect and return an array of string contents based on match --- src/scenario/DSL.js | 39 ++++++++++++++++++++++++--------------- 1 file changed, 24 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index 96447aaf..2dd37250 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -43,6 +43,8 @@ angular.scenario.dsl.input = function(selector) { }; }, +angular.scenario.dsl.NG_BIND_PATTERN =/\{\{[^\}]+\}\}/; + angular.scenario.dsl.repeater = function(selector) { var namePrefix = "repeater '" + selector + "'"; return { @@ -51,23 +53,30 @@ angular.scenario.dsl.repeater = function(selector) { done(this.testDocument.find(selector).size()); }); }, - collect: function() { - return $scenario.addFuture(namePrefix + ' collect', function(done) { + collect: function(collectSelector) { + return $scenario.addFuture( + namePrefix + " collect '" + collectSelector + "'", + function(done) { var self = this; var doCollect = bind(this, function() { - var repeaterArray = []; + 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 = angular.extend(self.jQuery(this), - {bindings: [], - boundTo: function(name) { return this.bindings[name]; }} - ); - element.find('*').each(function() { - var bindName = self.jQuery(this).attr('ng:bind'); - if (bindName) { - element.bindings[bindName] = self.jQuery(this).text(); - } + 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()); + } }); - repeaterArray[index] = element; }); return repeaterArray; }); @@ -86,9 +95,9 @@ angular.scenario.dsl.element = function(selector) { boundTo: function(name) { return this.bindings[name]; } }); element.find('*').each(function() { - var bindName = self.jQuery(elem).attr('ng:bind'); + var bindName = self.jQuery(this).attr('ng:bind'); if (bindName) { - element.bindings[bindName] = self.jQuery(elem).text(); + element.bindings[bindName] = self.jQuery(this).text(); } }); done(element); -- cgit v1.2.3 From 567341c10fc7f74d5333f27514bb2201f1dbee42 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Wed, 11 Aug 2010 10:54:11 -0700 Subject: modify element dsl to understand angular bindings and return jquery object for further checking --- src/scenario/DSL.js | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index 2dd37250..3b049dc6 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -89,17 +89,16 @@ angular.scenario.dsl.repeater = function(selector) { angular.scenario.dsl.element = function(selector) { var nameSuffix = "element '" + selector + "'"; return $scenario.addFuture('Find ' + nameSuffix, function(done) { - var self = this; - var element = angular.extend(this.testDocument.find(selector), { - bindings: [], - boundTo: function(name) { return this.bindings[name]; } - }); - element.find('*').each(function() { - var bindName = self.jQuery(this).attr('ng:bind'); - if (bindName) { - element.bindings[bindName] = self.jQuery(this).text(); - } - }); - done(element); + 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(element); + } else { + done(this.testDocument.find(selector)); + } }); }; -- cgit v1.2.3 From b27fb8a6448b7c8d59b533fe2df9497170fbaa70 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Wed, 11 Aug 2010 11:42:04 -0700 Subject: Fix toEqual matcher to use angular.equals instead of simple == comparison, which breaks down for arrays and objects --- src/scenario/Matcher.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/scenario/Matcher.js b/src/scenario/Matcher.js index 62f094c8..a9c86571 100644 --- a/src/scenario/Matcher.js +++ b/src/scenario/Matcher.js @@ -18,4 +18,4 @@ Matcher.addMatcher = function(name, matcher) { }; }; -Matcher.addMatcher('toEqual', function(a,b) { return a == b; }); +Matcher.addMatcher('toEqual', angular.equals); -- cgit v1.2.3 From 577ddaa5392dfad3b984515de0ad9262764a8721 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Fri, 13 Aug 2010 09:31:06 -0700 Subject: Pull in Rajat's changes to add click and url checking dsl --- src/scenario/DSL.js | 50 ++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index 3b049dc6..ca944014 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -1,5 +1,6 @@ angular.scenario.dsl.browser = { navigateTo: function(url){ + var location = this.location; return $scenario.addFuture('Navigate to: ' + url, function(done){ var self = this; this.testFrame.load(function(){ @@ -15,8 +16,22 @@ angular.scenario.dsl.browser = { 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] || ""; + } } }; @@ -88,17 +103,28 @@ angular.scenario.dsl.repeater = function(selector) { angular.scenario.dsl.element = function(selector) { var nameSuffix = "element '" + selector + "'"; - return $scenario.addFuture('Find ' + nameSuffix, 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(element); - } else { - done(this.testDocument.find(selector)); + return { + find: function() { + return $scenario.addFuture('Find ' + nameSuffix, 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(element); + } else { + done(this.testDocument.find(selector)); + } + }); + }, + click: function() { + var self = this; + return $scenario.addFuture('Click ' + nameSuffix, function(done) { + _jQuery(self).click(); + done(); + }); } - }); + }; }; -- cgit v1.2.3 From 2767d7773f2e480552e9968eded31bd2b08bec71 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Fri, 13 Aug 2010 09:45:56 -0700 Subject: Revert click dsl, since what is returned by element is a jquery object --- src/scenario/DSL.js | 35 ++++++++++++----------------------- 1 file changed, 12 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index ca944014..a64f8548 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -103,28 +103,17 @@ angular.scenario.dsl.repeater = function(selector) { angular.scenario.dsl.element = function(selector) { var nameSuffix = "element '" + selector + "'"; - return { - find: function() { - return $scenario.addFuture('Find ' + nameSuffix, 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(element); - } else { - done(this.testDocument.find(selector)); - } - }); - }, - click: function() { - var self = this; - return $scenario.addFuture('Click ' + nameSuffix, function(done) { - _jQuery(self).click(); - done(); - }); + return $scenario.addFuture('Find ' + nameSuffix, 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(element); + } else { + done(this.testDocument.find(selector)); } - }; + }); }; -- cgit v1.2.3 From 675978f41fbd05a7ed3481a79b772877a59a1c15 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Fri, 13 Aug 2010 12:05:50 -0700 Subject: Provide all jquery functions as futures --- src/scenario/DSL.js | 40 ++++++++++++++++++++++++++-------------- 1 file changed, 26 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index a64f8548..a533a5c3 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -102,18 +102,30 @@ angular.scenario.dsl.repeater = function(selector) { }; angular.scenario.dsl.element = function(selector) { - var nameSuffix = "element '" + selector + "'"; - return $scenario.addFuture('Find ' + nameSuffix, 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(element); - } else { - done(this.testDocument.find(selector)); - } - }); + var namePrefix = "Element '" + selector + "'"; + var futureJquery = {}; + for (key in _jQuery.fn) { + (function(){ + var jqFnName = key; + var jqFn = _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; }; -- cgit v1.2.3 From aa656253b9d4495264f14a76b6a80aa9a1d9a854 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Fri, 13 Aug 2010 18:23:39 -0700 Subject: Fix issue with jquery not being visible in production --- src/scenario/DSL.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index a533a5c3..0607238c 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -104,10 +104,10 @@ angular.scenario.dsl.repeater = function(selector) { angular.scenario.dsl.element = function(selector) { var namePrefix = "Element '" + selector + "'"; var futureJquery = {}; - for (key in _jQuery.fn) { + for (key in (jQuery || _jQuery).fn) { (function(){ var jqFnName = key; - var jqFn = _jQuery.fn[key]; + var jqFn = (jQuery || _jQuery).fn[key]; futureJquery[key] = function() { var jqArgs = arguments; return $scenario.addFuture(namePrefix + "." + jqFnName + "()", -- cgit v1.2.3