mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-18 19:41:07 +00:00
added repeater.collect to E2E DSL
This commit is contained in:
parent
989cffb435
commit
de8d0984c8
2 changed files with 50 additions and 5 deletions
|
|
@ -50,6 +50,26 @@ angular.scenario.dsl.repeater = function(selector) {
|
||||||
return $scenario.addFuture(namePrefix + ' count', function(done) {
|
return $scenario.addFuture(namePrefix + ' count', function(done) {
|
||||||
done(this.testDocument.find(selector).size());
|
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());
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -42,16 +42,41 @@ describe("DSL", function() {
|
||||||
|
|
||||||
var repeater = angular.scenario.dsl.repeater;
|
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();
|
var future = repeater('.repeater-row').count();
|
||||||
expect(future.name).toEqual("repeater '.repeater-row' count");
|
expect(future.name).toEqual("repeater '.repeater-row' count");
|
||||||
executeFuture(future, "<div class='repeater-row'>a</div>" +
|
executeFuture(future,
|
||||||
"<div class='repeater-row'>b</div>",
|
"<div class='repeater-row'>a</div>" +
|
||||||
function(value) {
|
"<div class='repeater-row'>b</div>",
|
||||||
future.fulfill(value);
|
function(value) {
|
||||||
|
future.fulfill(value);
|
||||||
});
|
});
|
||||||
expect(future.fulfilled).toBeTruthy();
|
expect(future.fulfilled).toBeTruthy();
|
||||||
expect(future.value).toEqual(2);
|
expect(future.value).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should collect', function() {
|
||||||
|
var future = repeater('.epic').collect();
|
||||||
|
expect(future.name).toEqual("repeater '.epic' collect");
|
||||||
|
executeFuture(future,
|
||||||
|
"<table>" +
|
||||||
|
"<tr class='epic'>" +
|
||||||
|
"<td ng:bind='hero'>John Marston</td>" +
|
||||||
|
"<td ng:bind='game'>Red Dead Redemption</td>" +
|
||||||
|
"</tr>" +
|
||||||
|
"<tr class='epic'>" +
|
||||||
|
"<td ng:bind='hero'>Nathan Drake</td>" +
|
||||||
|
"<td ng:bind='game'>Uncharted 2</td>" +
|
||||||
|
"</tr>" +
|
||||||
|
"</table>",
|
||||||
|
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');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue