diff options
| author | Elliott Sprehn | 2010-11-01 16:51:15 -0700 | 
|---|---|---|
| committer | Igor Minar | 2010-11-02 11:20:41 -0700 | 
| commit | 56a3d52f45ceae7973999ab8351a090f3ffddbba (patch) | |
| tree | e179c4e12222b3a29be6aadb7944ebeda7a7bb7c | |
| parent | faa7d81b679346623c9f023042ddc40dee808e6f (diff) | |
| download | angular.js-56a3d52f45ceae7973999ab8351a090f3ffddbba.tar.bz2 | |
Make future names consistent and handle falsy values in jQuery generated methods properly
| -rw-r--r-- | src/scenario/SpecRunner.js | 4 | ||||
| -rw-r--r-- | src/scenario/dsl.js | 36 | ||||
| -rw-r--r-- | test/scenario/dslSpec.js | 18 | 
3 files changed, 34 insertions, 24 deletions
| diff --git a/src/scenario/SpecRunner.js b/src/scenario/SpecRunner.js index 1055b7f7..c6a56083 100644 --- a/src/scenario/SpecRunner.js +++ b/src/scenario/SpecRunner.js @@ -110,9 +110,7 @@ angular.scenario.SpecRunner.prototype.addFutureAction = function(name, behavior,        //TODO(esprehn): Refactor this so it doesn't need to be in here.        $document.elements = function(selector) {          var args = Array.prototype.slice.call(arguments, 1); -        if (self.selector) { -          selector = self.selector + ' ' + (selector || ''); -        } +        selector = (self.selector || '') + ' ' + (selector || '');          angular.foreach(args, function(value, index) {            selector = selector.replace('$' + (index + 1), value);          }); diff --git a/src/scenario/dsl.js b/src/scenario/dsl.js index 4ac91068..7974f4ad 100644 --- a/src/scenario/dsl.js +++ b/src/scenario/dsl.js @@ -43,7 +43,7 @@ angular.scenario.dsl('browser', function() {    chain.navigateTo = function(url, delegate) {      var application = this.application; -    return this.addFuture('browser navigate to ' + url, function(done) { +    return this.addFuture("browser navigate to '" + url + "'", function(done) {        if (delegate) {          url = delegate.call(this, url);        } @@ -140,9 +140,9 @@ angular.scenario.dsl('expect', function() {   */  angular.scenario.dsl('using', function() {    return function(selector, label) { -    this.selector = (this.selector||'') + ' ' + selector; +    this.selector = _jQuery.trim((this.selector||'') + ' ' + selector);      if (angular.isString(label) && label.length) { -      this.label = label + ' (' + this.selector + ' )'; +      this.label = label + ' ( ' + this.selector + ' )';      } else {        this.label = this.selector;      } @@ -169,7 +169,7 @@ angular.scenario.dsl('binding', function() {            return;          }        } -      done('Binding selector ' + name + ' did not match.'); +      done("Binding selector '" + name + "' did not match.");      });    };  }); @@ -225,7 +225,7 @@ angular.scenario.dsl('repeater', function() {    var chain = {};    chain.count = function() { -    return this.addFutureAction('repeater ' + this.label + ' count', function($window, $document, done) { +    return this.addFutureAction("repeater '" + this.label + "' count", function($window, $document, done) {        try {          done(null, $document.elements().length);        } catch (e) { @@ -235,7 +235,7 @@ angular.scenario.dsl('repeater', function() {    };    chain.column = function(binding) { -    return this.addFutureAction('repeater ' + this.label + ' column ' + binding, function($window, $document, done) { +    return this.addFutureAction("repeater '" + this.label + "' column '" + binding + "'", function($window, $document, done) {        var values = [];        $document.elements().each(function() {          _jQuery(this).find(':visible').each(function() { @@ -250,14 +250,14 @@ angular.scenario.dsl('repeater', function() {    };    chain.row = function(index) { -    return this.addFutureAction('repeater ' + this.label + ' row ' + index, function($window, $document, done) { +    return this.addFutureAction("repeater '" + this.label + "' row '" + index + "'", function($window, $document, done) {        var values = [];        var matches = $document.elements().slice(index, index + 1);        if (!matches.length)          return done('row ' + index + ' out of bounds');        _jQuery(matches[0]).find(':visible').each(function() {          var element = _jQuery(this); -        if (element.attr('ng:bind')) { +        if (angular.isDefined(element.attr('ng:bind'))) {            values.push(element.text());          }        }); @@ -280,7 +280,7 @@ angular.scenario.dsl('select', function() {    var chain = {};    chain.option = function(value) { -    return this.addFutureAction('select ' + this.name + ' option ' + value, function($window, $document, done) { +    return this.addFutureAction("select '" + this.name + "' option '" + value + "'", function($window, $document, done) {        var select = $document.elements('select[name="$1"]', this.name);        select.val(value);        select.trigger('change'); @@ -290,7 +290,7 @@ angular.scenario.dsl('select', function() {    chain.options = function() {      var values = arguments; -    return this.addFutureAction('select ' + this.name + ' options ' + values, function($window, $document, done) { +    return this.addFutureAction("select '" + this.name + "' options '" + values + "'", function($window, $document, done) {        var select = $document.elements('select[multiple][name="$1"]', this.name);        select.val(values);        select.trigger('change'); @@ -322,7 +322,7 @@ angular.scenario.dsl('element', function() {    var chain = {};    chain.count = function() { -    return this.addFutureAction('element ' + this.label + ' count', function($window, $document, done) { +    return this.addFutureAction("element '" + this.label + "' count", function($window, $document, done) {        try {          done(null, $document.elements().length);        } catch (e) { @@ -332,7 +332,7 @@ angular.scenario.dsl('element', function() {    };    chain.click = function() { -    return this.addFutureAction('element ' + this.label + ' click', function($window, $document, done) { +    return this.addFutureAction("element '" + this.label + "' click", function($window, $document, done) {        var elements = $document.elements();        var href = elements.attr('href');        elements.trigger('click'); @@ -347,9 +347,9 @@ angular.scenario.dsl('element', function() {    };    chain.attr = function(name, value) { -    var futureName = 'element ' + this.label + ' get attribute ' + name; -    if (value) { -      futureName = 'element ' + this.label + ' set attribute ' + name + ' to ' + 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)); @@ -364,9 +364,9 @@ angular.scenario.dsl('element', function() {    angular.foreach(VALUE_METHODS, function(methodName) {      chain[methodName] = function(value) { -      var futureName = 'element ' + this.label + ' ' + methodName; -      if (value) { -        futureName = 'element ' + this.label + ' set ' + methodName + ' to ' + value; +      var futureName = "element '" + this.label + "' " + methodName; +      if (angular.isDefined(value)) { +        futureName = "element '" + this.label + "' set " + methodName + " to '" + value + "'";        }        return this.addFutureAction(futureName, function($window, $document, done) {          var element = $document.elements(); diff --git a/test/scenario/dslSpec.js b/test/scenario/dslSpec.js index d06c3ec9..9f7bf085 100644 --- a/test/scenario/dslSpec.js +++ b/test/scenario/dslSpec.js @@ -278,6 +278,18 @@ describe("angular.scenario.dsl", function() {          expect(doc.find('input').val()).toEqual('baz');        }); +      it('should use correct future name for generated set methods', function() { +        doc.append('<input value="bar">'); +        $root.dsl.element('input').val(false); +        expect($root.futures.pop()).toMatch(/element 'input' set val/); +      }); + +      it('should use correct future name for generated get methods', function() { +        doc.append('<input value="bar">'); +        $root.dsl.element('input').val(); +        expect($root.futures.pop()).toMatch(/element 'input' val/); +      }); +        it('should add all jQuery property methods', function() {          var METHODS = [            'val', 'text', 'html', 'height', 'innerHeight', 'outerHeight', 'width', @@ -299,7 +311,7 @@ describe("angular.scenario.dsl", function() {        it('should use the selector as label if none is given', function() {          $root.dsl.element('mySelector'); -        expect($root.label).toEqual(' mySelector'); +        expect($root.label).toEqual('mySelector');        });        it('should include the selector in paren when a label is given', function() { @@ -342,7 +354,7 @@ describe("angular.scenario.dsl", function() {        });        it('should use the selector as label if none is given', function() { -        expect($root.label).toEqual(' ul li'); +        expect($root.label).toEqual('ul li');        });        it('should include the selector in paren when a label is given', function() { @@ -398,7 +410,7 @@ describe("angular.scenario.dsl", function() {        it('should use the selector as label if none is given', function() {          $root.dsl.using('mySelector'); -        expect($root.label).toEqual(' mySelector'); +        expect($root.label).toEqual('mySelector');        });        it('should include the selector in paren when a label is given', function() { | 
