diff options
| -rw-r--r-- | src/scenario/dsl.js | 32 | ||||
| -rw-r--r-- | test/scenario/dslSpec.js | 20 |
2 files changed, 38 insertions, 14 deletions
diff --git a/src/scenario/dsl.js b/src/scenario/dsl.js index 99bc63a9..3fb84596 100644 --- a/src/scenario/dsl.js +++ b/src/scenario/dsl.js @@ -315,13 +315,14 @@ angular.scenario.dsl('select', function() { * Usage: * element(selector, label).count() get the number of elements that match selector * element(selector, label).click() clicks an element - * element(selector, label).attr(name) gets the value of an attribute - * element(selector, label).attr(name, value) sets the value of an attribute - * element(selector, label).val() gets the value (as defined by jQuery) - * element(selector, label).val(value) sets the value (as defined by jQuery) * element(selector, label).query(fn) executes fn(selectedElements, done) + * element(selector, label).{method}() gets the value (as defined by jQuery, ex. val) + * element(selector, label).{method}(value) sets the value (as defined by jQuery, ex. val) + * element(selector, label).{method}(key) gets the value (as defined by jQuery, ex. attr) + * element(selector, label).{method}(key, value) sets the value (as defined by jQuery, ex. attr) */ angular.scenario.dsl('element', function() { + var KEY_VALUE_METHODS = ['attr', 'css']; var VALUE_METHODS = [ 'val', 'text', 'html', 'height', 'innerHeight', 'outerHeight', 'width', 'innerWidth', 'outerWidth', 'position', 'scrollLeft', 'scrollTop', 'offset' @@ -353,22 +354,25 @@ angular.scenario.dsl('element', function() { }); }; - chain.attr = function(name, value) { - var futureName = "element '" + this.label + "' get attribute '" + name + "'"; - if (angular.isDefined(value)) { - futureName = "element '" + this.label + "' set attribute '" + name + "' to " + "'" + value + "'"; - } - return this.addFutureAction(futureName, function($window, $document, done) { - done(null, $document.elements().attr(name, value)); - }); - }; - chain.query = function(fn) { return this.addFutureAction('element ' + this.label + ' custom query', function($window, $document, done) { fn.call(this, $document.elements(), done); }); }; + angular.foreach(KEY_VALUE_METHODS, function(methodName) { + chain[methodName] = function(name, value) { + var futureName = "element '" + this.label + "' get " + methodName + " '" + name + "'"; + if (angular.isDefined(value)) { + futureName = "element '" + this.label + "' set " + methodName + " '" + name + "' to " + "'" + value + "'"; + } + return this.addFutureAction(futureName, function($window, $document, done) { + var element = $document.elements(); + done(null, element[methodName].call(element, name, value)); + }); + }; + }); + angular.foreach(VALUE_METHODS, function(methodName) { chain[methodName] = function(value) { var futureName = "element '" + this.label + "' " + methodName; diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js index e33cd056..e2c66105 100644 --- a/test/scenario/dslSpec.js +++ b/test/scenario/dslSpec.js @@ -266,6 +266,26 @@ describe("angular.scenario.dsl", function() { expect(doc.find('div').attr('class')).toEqual('bam'); }); + it('should get css', function() { + doc.append('<div id="test" style="border: 1px solid red"></div>'); + $root.dsl.element('#test').css('border'); + expect($root.futureResult).toMatch(/red/); + }); + + it('should set css', function() { + doc.append('<div id="test" style="border: 1px solid red"></div>'); + $root.dsl.element('#test').css('border', '1px solid green'); + expect(doc.find('#test').css('border')).toMatch(/green/); + }); + + it('should add all jQuery key/value methods', function() { + var METHODS = ['css', 'attr']; + var chain = $root.dsl.element('input'); + angular.foreach(METHODS, function(name) { + expect(angular.isFunction(chain[name])).toBeTruthy(); + }); + }); + it('should get val', function() { doc.append('<input value="bar">'); $root.dsl.element('input').val(); |
