Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit de8d098

Browse files
author
Andres Ornelas
committed
added repeater.collect to E2E DSL
1 parent 989cffb commit de8d098

File tree

2 files changed

+50
-5
lines changed

2 files changed

+50
-5
lines changed

src/scenario/DSL.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,26 @@ angular.scenario.dsl.repeater = function(selector) {
5050
return $scenario.addFuture(namePrefix + ' count', function(done) {
5151
done(this.testDocument.find(selector).size());
5252
});
53+
},
54+
collect: function() {
55+
return $scenario.addFuture(namePrefix + ' collect', function(done) {
56+
var doCollect = bind(this, function() {
57+
var repeaterArray = [];
58+
this.testDocument.find(selector).each(function(index) {
59+
var element = angular.extend(_jQuery(this),
60+
{bindings: [],
61+
boundTo: function(name) { return this.bindings[name]; }}
62+
);
63+
element.find('*').each(function(index) {
64+
var bindName = _jQuery(this).attr('ng:bind');
65+
element.bindings[bindName] = _jQuery(this).text();
66+
});
67+
repeaterArray[index] = element;
68+
});
69+
return repeaterArray;
70+
});
71+
done(doCollect());
72+
});
5373
}
5474
};
5575
};

test/scenario/DSLSpec.js

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,41 @@ describe("DSL", function() {
4242

4343
var repeater = angular.scenario.dsl.repeater;
4444

45-
it('should fetch the count of repeated elements', function() {
45+
it('should count', function() {
4646
var future = repeater('.repeater-row').count();
4747
expect(future.name).toEqual("repeater '.repeater-row' count");
48-
executeFuture(future, "<div class='repeater-row'>a</div>" +
49-
"<div class='repeater-row'>b</div>",
50-
function(value) {
51-
future.fulfill(value);
48+
executeFuture(future,
49+
"<div class='repeater-row'>a</div>" +
50+
"<div class='repeater-row'>b</div>",
51+
function(value) {
52+
future.fulfill(value);
5253
});
5354
expect(future.fulfilled).toBeTruthy();
5455
expect(future.value).toEqual(2);
5556
});
57+
58+
it('should collect', function() {
59+
var future = repeater('.epic').collect();
60+
expect(future.name).toEqual("repeater '.epic' collect");
61+
executeFuture(future,
62+
"<table>" +
63+
"<tr class='epic'>" +
64+
"<td ng:bind='hero'>John Marston</td>" +
65+
"<td ng:bind='game'>Red Dead Redemption</td>" +
66+
"</tr>" +
67+
"<tr class='epic'>" +
68+
"<td ng:bind='hero'>Nathan Drake</td>" +
69+
"<td ng:bind='game'>Uncharted 2</td>" +
70+
"</tr>" +
71+
"</table>",
72+
function(value) {
73+
future.fulfill(value);
74+
});
75+
expect(future.fulfilled).toBeTruthy();
76+
expect(future.value[0].boundTo('hero')).toEqual('John Marston');
77+
expect(future.value[0].boundTo('game')).toEqual('Red Dead Redemption');
78+
expect(future.value[1].boundTo('hero')).toEqual('Nathan Drake');
79+
expect(future.value[1].boundTo('game')).toEqual('Uncharted 2');
80+
});
5681
});
5782
});

0 commit comments

Comments
 (0)