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

Commit 21d2b43

Browse files
author
Shyam Seshadri
committed
Add element DSL, to find an element. Has knowledge of finding ng:bind elements and grabbing their contents.
1 parent de8d098 commit 21d2b43

File tree

2 files changed

+56
-2
lines changed

2 files changed

+56
-2
lines changed

src/scenario/DSL.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,9 @@ angular.scenario.dsl.repeater = function(selector) {
6262
);
6363
element.find('*').each(function(index) {
6464
var bindName = _jQuery(this).attr('ng:bind');
65-
element.bindings[bindName] = _jQuery(this).text();
65+
if (bindName) {
66+
element.bindings[bindName] = _jQuery(this).text();
67+
}
6668
});
6769
repeaterArray[index] = element;
6870
});
@@ -73,3 +75,20 @@ angular.scenario.dsl.repeater = function(selector) {
7375
}
7476
};
7577
};
78+
79+
angular.scenario.dsl.element = function(selector) {
80+
var nameSuffix = "element '" + selector + "'";
81+
return $scenario.addFuture('Find ' + nameSuffix, function(done) {
82+
var element = angular.extend(this.testDocument.find(selector), {
83+
bindings: [],
84+
boundTo: function(name) { return this.bindings[name]; }
85+
});
86+
element.find('*').each(function(index) {
87+
var bindName = _jQuery(this).attr('ng:bind');
88+
if (bindName) {
89+
element.bindings[bindName] = _jQuery(this).text();
90+
}
91+
});
92+
done(element);
93+
});
94+
};

test/scenario/DSLSpec.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ describe("DSL", function() {
4141
describe('repeater', function() {
4242

4343
var repeater = angular.scenario.dsl.repeater;
44-
4544
it('should count', function() {
4645
var future = repeater('.repeater-row').count();
4746
expect(future.name).toEqual("repeater '.repeater-row' count");
@@ -79,4 +78,40 @@ describe("DSL", function() {
7978
expect(future.value[1].boundTo('game')).toEqual('Uncharted 2');
8079
});
8180
});
81+
82+
describe('element', function() {
83+
var element = angular.scenario.dsl.element;
84+
var html;
85+
beforeEach(function() {
86+
html = '<div class="container">' +
87+
'<table class="reports-detail">' +
88+
'<span class="desc">Description : ' +
89+
'<span ng:bind="report.description">Details...</span>' +
90+
'</span>' +
91+
'<span>Date created: ' +
92+
'<span ng:bind="report.creationDate">01/01/01</span>' +
93+
'</span>' +
94+
'</table>' +
95+
'</div>';
96+
});
97+
it('should find elements on the page and provide jquery api', function() {
98+
var future = element('.reports-detail');
99+
expect(future.name).toEqual("Find element '.reports-detail'");
100+
executeFuture(future, html, function(value) { future.fulfill(value); });
101+
expect(future.fulfilled).toBeTruthy();
102+
expect(future.value.text()).
103+
toEqual('Description : Details...Date created: 01/01/01');
104+
expect(future.value.find('.desc').text()).
105+
toEqual('Description : Details...');
106+
});
107+
it('should know how to find ng:bind elements on page', function() {
108+
var future = element('.reports-detail');
109+
expect(future.name).toEqual("Find element '.reports-detail'");
110+
executeFuture(future, html, function(value) { future.fulfill(value); });
111+
expect(future.fulfilled).toBeTruthy();
112+
expect(future.value.boundTo('report.description')).toEqual('Details...');
113+
expect(future.value.boundTo('report.creationDate')).toEqual('01/01/01');
114+
expect(future.value.boundTo('doesnotexist')).not.toBeDefined();
115+
});
116+
});
82117
});

0 commit comments

Comments
 (0)