From 21d2b43e6c81b7b6b55599f0274495d25411b4f0 Mon Sep 17 00:00:00 2001 From: Shyam Seshadri Date: Mon, 9 Aug 2010 17:55:01 -0700 Subject: Add element DSL, to find an element. Has knowledge of finding ng:bind elements and grabbing their contents. --- src/scenario/DSL.js | 21 ++++++++++++++++++++- test/scenario/DSLSpec.js | 37 ++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index 13576824..fe834835 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -62,7 +62,9 @@ angular.scenario.dsl.repeater = function(selector) { ); element.find('*').each(function(index) { var bindName = _jQuery(this).attr('ng:bind'); - element.bindings[bindName] = _jQuery(this).text(); + if (bindName) { + element.bindings[bindName] = _jQuery(this).text(); + } }); repeaterArray[index] = element; }); @@ -73,3 +75,20 @@ angular.scenario.dsl.repeater = function(selector) { } }; }; + +angular.scenario.dsl.element = function(selector) { + var nameSuffix = "element '" + selector + "'"; + return $scenario.addFuture('Find ' + nameSuffix, function(done) { + var element = angular.extend(this.testDocument.find(selector), { + bindings: [], + boundTo: function(name) { return this.bindings[name]; } + }); + element.find('*').each(function(index) { + var bindName = _jQuery(this).attr('ng:bind'); + if (bindName) { + element.bindings[bindName] = _jQuery(this).text(); + } + }); + done(element); + }); +}; diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index 64961e50..a6a291f8 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -41,7 +41,6 @@ describe("DSL", function() { describe('repeater', function() { var repeater = angular.scenario.dsl.repeater; - it('should count', function() { var future = repeater('.repeater-row').count(); expect(future.name).toEqual("repeater '.repeater-row' count"); @@ -79,4 +78,40 @@ describe("DSL", function() { expect(future.value[1].boundTo('game')).toEqual('Uncharted 2'); }); }); + + describe('element', function() { + var element = angular.scenario.dsl.element; + var html; + beforeEach(function() { + html = '