angular.js/src/scenario/DSL.js

64 lines
2.2 KiB
JavaScript
Raw Normal View History

angular.scenario.dsl.browser = {
2010-05-20 22:55:41 +00:00
navigateTo: function(url){
$scenario.addFuture('Navigate to: ' + url, function(done){
2010-05-20 22:55:41 +00:00
var self = this;
2010-06-09 22:38:56 +00:00
this.testFrame.load(function(){
2010-05-20 22:55:41 +00:00
self.testFrame.unbind();
self.testWindow = self.testFrame[0].contentWindow;
self.testDocument = jQuery(self.testWindow.document);
self.$browser = self.testWindow.angular.service.$browser();
self.notifyWhenNoOutstandingRequests = bind(self.$browser, self.$browser.notifyWhenNoOutstandingRequests);
self.notifyWhenNoOutstandingRequests(done);
2010-05-20 22:55:41 +00:00
});
if (this.testFrame.attr('src') == url) {
2010-06-09 22:38:56 +00:00
this.testFrame[0].contentWindow.location.reload();
2010-05-20 22:55:41 +00:00
} else {
this.testFrame.attr('src', url);
}
});
}
};
angular.scenario.dsl.input = function(selector) {
2010-05-20 22:55:41 +00:00
return {
enter: function(value){
$scenario.addFuture("Set input text of '" + selector + "' to '" +
value + "'", function(done){
var input = this.testDocument.find('input[name=' + selector + ']');
input.val(value);
this.testWindow.angular.element(input[0]).trigger('change');
done();
2010-05-20 22:55:41 +00:00
});
2010-05-25 00:48:17 +00:00
},
select: function(value){
$scenario.addFuture("Select radio '" + selector + "' to '" +
2010-05-25 00:48:17 +00:00
value + "'", function(done){
var input = this.testDocument.
find(':radio[name$=@' + selector + '][value=' + value + ']');
var event = this.testWindow.document.createEvent('MouseEvent');
event.initMouseEvent('click', true, true, this.testWindow, 0,0,0,0,0, false, false, false, false, 0, null);
input[0].dispatchEvent(event);
done();
});
2010-05-20 22:55:41 +00:00
}
};
};
2010-05-20 22:55:41 +00:00
2010-06-09 19:35:40 +00:00
angular.scenario.dsl.expect = {
repeater: function(selector) {
return {
count: {
toEqual: function(number) {
$scenario.addFuture("Expect that there are " + number + " items in Repeater with selector '" + selector + "'", function(done) {
2010-06-09 19:35:40 +00:00
var items = this.testDocument.find(selector);
if (items.length != number) {
this.result.fail("Expected " + number + " but was " + items.length);
}
done();
});
2010-05-20 22:55:41 +00:00
}
2010-06-09 19:35:40 +00:00
}
};
}
};