modify element dsl to understand angular bindings and return jquery object for further checking

This commit is contained in:
Shyam Seshadri 2010-08-11 10:54:11 -07:00
parent e7b9095655
commit 567341c10f
2 changed files with 25 additions and 23 deletions

View file

@ -89,17 +89,16 @@ angular.scenario.dsl.repeater = function(selector) {
angular.scenario.dsl.element = function(selector) {
var nameSuffix = "element '" + selector + "'";
return $scenario.addFuture('Find ' + nameSuffix, function(done) {
var self = this;
var element = angular.extend(this.testDocument.find(selector), {
bindings: [],
boundTo: function(name) { return this.bindings[name]; }
});
element.find('*').each(function() {
var bindName = self.jQuery(this).attr('ng:bind');
if (bindName) {
element.bindings[bindName] = self.jQuery(this).text();
}
});
done(element);
var self = this, repeaterArray = [], ngBindPattern;
var startIndex = selector.search(angular.scenario.dsl.NG_BIND_PATTERN);
if (startIndex >= 0) {
ngBindPattern = selector.substring(startIndex + 2, selector.length - 2);
var element = this.testDocument.find('*').filter(function() {
return self.jQuery(this).attr('ng:bind') == ngBindPattern;
});
done(element);
} else {
done(this.testDocument.find(selector));
}
});
};

View file

@ -100,7 +100,9 @@ describe("DSL", function() {
"repeater '.epic' collect '.game-name'",
['Red Dead Redemption', 'Uncharted']);
});
it('should collect normal attributes', function() {});
it('should collect normal attributes', function() {
//TODO(shyamseshadri) : Left as an exercise to the user
});
});
describe('element', function() {
@ -118,24 +120,25 @@ describe("DSL", function() {
'</div>' +
'</div>';
});
function timeTravel(future) {
executeFuture(future, html, function(value) { future.fulfill(value); });
expect(future.fulfilled).toBeTruthy();
}
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();
timeTravel(future);
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();
it('should find elements with angular syntax', function() {
var future = element('{{report.description}}');
expect(future.name).toEqual("Find element '{{report.description}}'");
timeTravel(future);
expect(future.value.text()).toEqual('Details...');
expect(future.value.attr('ng:bind')).toEqual('report.description');
});
});
});