mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
Provide all jquery functions as futures
This commit is contained in:
parent
9260f4867a
commit
60eeeb9f20
2 changed files with 42 additions and 23 deletions
|
|
@ -102,18 +102,30 @@ 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, 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));
|
||||
}
|
||||
});
|
||||
var namePrefix = "Element '" + selector + "'";
|
||||
var futureJquery = {};
|
||||
for (key in _jQuery.fn) {
|
||||
(function(){
|
||||
var jqFnName = key;
|
||||
var jqFn = _jQuery.fn[key];
|
||||
futureJquery[key] = function() {
|
||||
var jqArgs = arguments;
|
||||
return $scenario.addFuture(namePrefix + "." + jqFnName + "()",
|
||||
function(done) {
|
||||
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(jqFn.apply(element, jqArgs));
|
||||
} else {
|
||||
done(jqFn.apply(this.testDocument.find(selector), jqArgs));
|
||||
}
|
||||
});
|
||||
};
|
||||
})();
|
||||
}
|
||||
return futureJquery;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -159,20 +159,27 @@ describe("DSL", function() {
|
|||
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'");
|
||||
var future = element('.reports-detail').text();
|
||||
expect(future.name).toEqual("Element '.reports-detail'.text()");
|
||||
timeTravel(future);
|
||||
expect(future.value.text()).
|
||||
expect(future.value).
|
||||
toEqual('Description : Details...Date created: 01/01/01');
|
||||
expect(future.value.find('.desc').text()).
|
||||
toEqual('Description : Details...');
|
||||
// expect(future.value.find('.desc').text()).
|
||||
// toEqual('Description : Details...');
|
||||
});
|
||||
it('should find elements with angular syntax', function() {
|
||||
var future = element('{{report.description}}');
|
||||
expect(future.name).toEqual("Find element '{{report.description}}'");
|
||||
var future = element('{{report.description}}').text();
|
||||
expect(future.name).toEqual("Element '{{report.description}}'.text()");
|
||||
timeTravel(future);
|
||||
expect(future.value.text()).toEqual('Details...');
|
||||
expect(future.value.attr('ng:bind')).toEqual('report.description');
|
||||
expect(future.value).toEqual('Details...');
|
||||
// expect(future.value.attr('ng:bind')).toEqual('report.description');
|
||||
});
|
||||
it('should be able to click elements', function(){
|
||||
var future = element('.link-class').click();
|
||||
expect(future.name).toEqual("Element '.link-class'.click()");
|
||||
executeFuture(future, html, function(value) { future.fulfill(value); });
|
||||
expect(future.fulfilled).toBeTruthy();
|
||||
// TODO(rajat): look for some side effect from click happening?
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue