From de8d0984c85ae3078fd72a9c7f010b0fd4397150 Mon Sep 17 00:00:00 2001 From: Andres Ornelas Date: Fri, 6 Aug 2010 17:28:47 -0700 Subject: added repeater.collect to E2E DSL --- src/scenario/DSL.js | 20 ++++++++++++++++++++ test/scenario/DSLSpec.js | 35 ++++++++++++++++++++++++++++++----- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index 26157059..13576824 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -50,6 +50,26 @@ angular.scenario.dsl.repeater = function(selector) { return $scenario.addFuture(namePrefix + ' count', function(done) { done(this.testDocument.find(selector).size()); }); + }, + collect: function() { + return $scenario.addFuture(namePrefix + ' collect', function(done) { + var doCollect = bind(this, function() { + var repeaterArray = []; + this.testDocument.find(selector).each(function(index) { + var element = angular.extend(_jQuery(this), + {bindings: [], + boundTo: function(name) { return this.bindings[name]; }} + ); + element.find('*').each(function(index) { + var bindName = _jQuery(this).attr('ng:bind'); + element.bindings[bindName] = _jQuery(this).text(); + }); + repeaterArray[index] = element; + }); + return repeaterArray; + }); + done(doCollect()); + }); } }; }; diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js index 47bedb80..64961e50 100644 --- a/test/scenario/DSLSpec.js +++ b/test/scenario/DSLSpec.js @@ -42,16 +42,41 @@ describe("DSL", function() { var repeater = angular.scenario.dsl.repeater; - it('should fetch the count of repeated elements', function() { + it('should count', function() { var future = repeater('.repeater-row').count(); expect(future.name).toEqual("repeater '.repeater-row' count"); - executeFuture(future, "
a
" + - "
b
", - function(value) { - future.fulfill(value); + executeFuture(future, + "
a
" + + "
b
", + function(value) { + future.fulfill(value); }); expect(future.fulfilled).toBeTruthy(); expect(future.value).toEqual(2); }); + + it('should collect', function() { + var future = repeater('.epic').collect(); + expect(future.name).toEqual("repeater '.epic' collect"); + executeFuture(future, + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "
John MarstonRed Dead Redemption
Nathan DrakeUncharted 2
", + function(value) { + future.fulfill(value); + }); + expect(future.fulfilled).toBeTruthy(); + expect(future.value[0].boundTo('hero')).toEqual('John Marston'); + expect(future.value[0].boundTo('game')).toEqual('Red Dead Redemption'); + expect(future.value[1].boundTo('hero')).toEqual('Nathan Drake'); + expect(future.value[1].boundTo('game')).toEqual('Uncharted 2'); + }); }); }); -- cgit v1.2.3