mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-17 07:40:22 +00:00
added dsl tests and select method
This commit is contained in:
parent
3fab5d9879
commit
55c0767f16
2 changed files with 52 additions and 2 deletions
|
|
@ -19,14 +19,24 @@ angular.scenario.dsl.browser = {
|
|||
angular.scenario.dsl.input = function(selector) {
|
||||
return {
|
||||
enter: function(value){
|
||||
$scenario.addStep("Set input text of '" + selector + "' to value '" +
|
||||
$scenario.addStep("Set input text of '" + selector + "' to '" +
|
||||
value + "'", function(done){
|
||||
var input = this.testDocument.find('input[name=' + selector + ']');
|
||||
input.val(value);
|
||||
input.trigger('change');
|
||||
this.testWindow.angular.element(input[0]).trigger('change');
|
||||
done();
|
||||
});
|
||||
},
|
||||
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();
|
||||
});
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
|||
40
test/scenario/DSLSpec.js
Normal file
40
test/scenario/DSLSpec.js
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
describe("DSL", function() {
|
||||
|
||||
var lastStep, executeStep, lastDocument;
|
||||
|
||||
beforeEach(function() {
|
||||
lastStep = null;
|
||||
$scenario = {
|
||||
addStep: function(name, stepFunction) {
|
||||
lastStep = { name:name, fn: stepFunction};
|
||||
}
|
||||
};
|
||||
executeStep = function(step, html, callback) {
|
||||
lastDocument =_jQuery('<div>' + html + '</div>');
|
||||
var specThis = {
|
||||
testWindow: window,
|
||||
testDocument: lastDocument
|
||||
};
|
||||
step.fn.call(specThis, callback || noop);
|
||||
};
|
||||
});
|
||||
|
||||
describe("input", function() {
|
||||
|
||||
var input = angular.scenario.dsl.input;
|
||||
it('should enter', function() {
|
||||
input('name').enter('John');
|
||||
expect(lastStep.name).toEqual("Set input text of 'name' to 'John'");
|
||||
executeStep(lastStep, '<input type="text" name="name" />');
|
||||
expect(lastDocument.find('input').val()).toEqual('John');
|
||||
});
|
||||
|
||||
it('should select', function() {
|
||||
input('gender').select('female');
|
||||
expect(lastStep.name).toEqual("Select radio 'gender' to 'female'");
|
||||
executeStep(lastStep, '<input type="radio" name="0@gender" value="male"/>' +
|
||||
'<input type="radio" name="0@gender" value="female"/>');
|
||||
expect(lastDocument.find(':radio:checked').val()).toEqual('female');
|
||||
});
|
||||
});
|
||||
});
|
||||
Loading…
Reference in a new issue