mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
Add element DSL, to find an element. Has knowledge of finding ng:bind elements and grabbing their contents.
This commit is contained in:
parent
de8d0984c8
commit
21d2b43e6c
2 changed files with 56 additions and 2 deletions
|
|
@ -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);
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 = '<div class="container">' +
|
||||
'<table class="reports-detail">' +
|
||||
'<span class="desc">Description : ' +
|
||||
'<span ng:bind="report.description">Details...</span>' +
|
||||
'</span>' +
|
||||
'<span>Date created: ' +
|
||||
'<span ng:bind="report.creationDate">01/01/01</span>' +
|
||||
'</span>' +
|
||||
'</table>' +
|
||||
'</div>';
|
||||
});
|
||||
it('should find elements on the page and provide jquery api', function() {
|
||||
var future = element('.reports-detail');
|
||||
expect(future.name).toEqual("Find element '.reports-detail'");
|
||||
executeFuture(future, html, function(value) { future.fulfill(value); });
|
||||
expect(future.fulfilled).toBeTruthy();
|
||||
expect(future.value.text()).
|
||||
toEqual('Description : Details...Date created: 01/01/01');
|
||||
expect(future.value.find('.desc').text()).
|
||||
toEqual('Description : Details...');
|
||||
});
|
||||
it('should know how to find ng:bind elements on page', function() {
|
||||
var future = element('.reports-detail');
|
||||
expect(future.name).toEqual("Find element '.reports-detail'");
|
||||
executeFuture(future, html, function(value) { future.fulfill(value); });
|
||||
expect(future.fulfilled).toBeTruthy();
|
||||
expect(future.value.boundTo('report.description')).toEqual('Details...');
|
||||
expect(future.value.boundTo('report.creationDate')).toEqual('01/01/01');
|
||||
expect(future.value.boundTo('doesnotexist')).not.toBeDefined();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue