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

Commit 04e92a8

Browse files
Shyam Seshadrimhevery
Shyam Seshadri
authored andcommitted
modify element dsl to understand angular bindings and return jquery object for further checking
1 parent 27784b6 commit 04e92a8

File tree

2 files changed

+25
-23
lines changed

2 files changed

+25
-23
lines changed

src/scenario/DSL.js

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,16 @@ angular.scenario.dsl.repeater = function(selector) {
8989
angular.scenario.dsl.element = function(selector) {
9090
var nameSuffix = "element '" + selector + "'";
9191
return $scenario.addFuture('Find ' + nameSuffix, function(done) {
92-
var self = this;
93-
var element = angular.extend(this.testDocument.find(selector), {
94-
bindings: [],
95-
boundTo: function(name) { return this.bindings[name]; }
96-
});
97-
element.find('*').each(function() {
98-
var bindName = self.jQuery(this).attr('ng:bind');
99-
if (bindName) {
100-
element.bindings[bindName] = self.jQuery(this).text();
101-
}
102-
});
103-
done(element);
92+
var self = this, repeaterArray = [], ngBindPattern;
93+
var startIndex = selector.search(angular.scenario.dsl.NG_BIND_PATTERN);
94+
if (startIndex >= 0) {
95+
ngBindPattern = selector.substring(startIndex + 2, selector.length - 2);
96+
var element = this.testDocument.find('*').filter(function() {
97+
return self.jQuery(this).attr('ng:bind') == ngBindPattern;
98+
});
99+
done(element);
100+
} else {
101+
done(this.testDocument.find(selector));
102+
}
104103
});
105104
};

test/scenario/DSLSpec.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@ describe("DSL", function() {
100100
"repeater '.epic' collect '.game-name'",
101101
['Red Dead Redemption', 'Uncharted']);
102102
});
103-
it('should collect normal attributes', function() {});
103+
it('should collect normal attributes', function() {
104+
//TODO(shyamseshadri) : Left as an exercise to the user
105+
});
104106
});
105107

106108
describe('element', function() {
@@ -118,24 +120,25 @@ describe("DSL", function() {
118120
'</div>' +
119121
'</div>';
120122
});
123+
function timeTravel(future) {
124+
executeFuture(future, html, function(value) { future.fulfill(value); });
125+
expect(future.fulfilled).toBeTruthy();
126+
}
121127
it('should find elements on the page and provide jquery api', function() {
122128
var future = element('.reports-detail');
123129
expect(future.name).toEqual("Find element '.reports-detail'");
124-
executeFuture(future, html, function(value) { future.fulfill(value); });
125-
expect(future.fulfilled).toBeTruthy();
130+
timeTravel(future);
126131
expect(future.value.text()).
127132
toEqual('Description : Details...Date created: 01/01/01');
128133
expect(future.value.find('.desc').text()).
129134
toEqual('Description : Details...');
130135
});
131-
it('should know how to find ng:bind elements on page', function() {
132-
var future = element('.reports-detail');
133-
expect(future.name).toEqual("Find element '.reports-detail'");
134-
executeFuture(future, html, function(value) { future.fulfill(value); });
135-
expect(future.fulfilled).toBeTruthy();
136-
expect(future.value.boundTo('report.description')).toEqual('Details...');
137-
expect(future.value.boundTo('report.creationDate')).toEqual('01/01/01');
138-
expect(future.value.boundTo('doesnotexist')).not.toBeDefined();
136+
it('should find elements with angular syntax', function() {
137+
var future = element('{{report.description}}');
138+
expect(future.name).toEqual("Find element '{{report.description}}'");
139+
timeTravel(future);
140+
expect(future.value.text()).toEqual('Details...');
141+
expect(future.value.attr('ng:bind')).toEqual('report.description');
139142
});
140143
});
141144
});

0 commit comments

Comments
 (0)