diff options
| -rw-r--r-- | src/scenario/DSL.js | 14 | ||||
| -rw-r--r-- | test/scenario/DSLSpec.js | 40 |
2 files changed, 52 insertions, 2 deletions
diff --git a/src/scenario/DSL.js b/src/scenario/DSL.js index 4bc21d6c..842f7c7a 100644 --- a/src/scenario/DSL.js +++ b/src/scenario/DSL.js @@ -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(); + }); } }; }; diff --git a/test/scenario/DSLSpec.js b/test/scenario/DSLSpec.js new file mode 100644 index 00000000..3c16876d --- /dev/null +++ b/test/scenario/DSLSpec.js @@ -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'); + }); + }); +});
\ No newline at end of file |
