angular.js/src/scenario/DSL.js

59 lines
1.9 KiB
JavaScript
Raw Normal View History

angular.scenario.dsl.browser = {
2010-05-20 22:55:41 +00:00
navigateTo: function(url){
$scenario.addStep('Navigate to: ' + url, function(done){
var self = this;
self.testFrame.load(function(){
self.testFrame.unbind();
2010-05-24 20:54:32 +00:00
self.testDocument = jQuery(self.testWindow.document);
self.testWindow = self.testFrame[0].contentWindow;
2010-05-20 22:55:41 +00:00
done();
});
if (this.testFrame.attr('src') == url) {
this.testWindow.location.reload();
} else {
this.testFrame.attr('src', url);
}
});
}
};
angular.scenario.dsl.input = function(selector) {
2010-05-20 22:55:41 +00:00
return {
enter: function(value){
2010-05-25 00:48:17 +00:00
$scenario.addStep("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.addStep("Select radio '" + selector + "' to '" +
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
angular.scenario.dsl.expect = function(selector) {
2010-05-20 22:55:41 +00:00
return {
toEqual: function(expected) {
$scenario.addStep("Expect that " + selector + " equals '" + expected + "'", function(done){
var attrName = selector.substring(2, selector.length - 2);
var binding = this.testDocument.find('span[ng-bind=' + attrName + ']');
if (binding.text() != expected) {
this.result.fail("Expected '" + expected + "' but was '" + binding.text() + "'");
}
done();
});
}
};
};