mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-15 18:23:09 +00:00
Make future names consistent and handle falsy values in jQuery generated methods properly
This commit is contained in:
parent
faa7d81b67
commit
56a3d52f45
3 changed files with 34 additions and 24 deletions
|
|
@ -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.
|
//TODO(esprehn): Refactor this so it doesn't need to be in here.
|
||||||
$document.elements = function(selector) {
|
$document.elements = function(selector) {
|
||||||
var args = Array.prototype.slice.call(arguments, 1);
|
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) {
|
angular.foreach(args, function(value, index) {
|
||||||
selector = selector.replace('$' + (index + 1), value);
|
selector = selector.replace('$' + (index + 1), value);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,7 @@ angular.scenario.dsl('browser', function() {
|
||||||
|
|
||||||
chain.navigateTo = function(url, delegate) {
|
chain.navigateTo = function(url, delegate) {
|
||||||
var application = this.application;
|
var application = this.application;
|
||||||
return this.addFuture('browser navigate to ' + url, function(done) {
|
return this.addFuture("browser navigate to '" + url + "'", function(done) {
|
||||||
if (delegate) {
|
if (delegate) {
|
||||||
url = delegate.call(this, url);
|
url = delegate.call(this, url);
|
||||||
}
|
}
|
||||||
|
|
@ -140,9 +140,9 @@ angular.scenario.dsl('expect', function() {
|
||||||
*/
|
*/
|
||||||
angular.scenario.dsl('using', function() {
|
angular.scenario.dsl('using', function() {
|
||||||
return function(selector, label) {
|
return function(selector, label) {
|
||||||
this.selector = (this.selector||'') + ' ' + selector;
|
this.selector = _jQuery.trim((this.selector||'') + ' ' + selector);
|
||||||
if (angular.isString(label) && label.length) {
|
if (angular.isString(label) && label.length) {
|
||||||
this.label = label + ' (' + this.selector + ' )';
|
this.label = label + ' ( ' + this.selector + ' )';
|
||||||
} else {
|
} else {
|
||||||
this.label = this.selector;
|
this.label = this.selector;
|
||||||
}
|
}
|
||||||
|
|
@ -169,7 +169,7 @@ angular.scenario.dsl('binding', function() {
|
||||||
return;
|
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 = {};
|
var chain = {};
|
||||||
|
|
||||||
chain.count = function() {
|
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 {
|
try {
|
||||||
done(null, $document.elements().length);
|
done(null, $document.elements().length);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -235,7 +235,7 @@ angular.scenario.dsl('repeater', function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
chain.column = function(binding) {
|
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 = [];
|
var values = [];
|
||||||
$document.elements().each(function() {
|
$document.elements().each(function() {
|
||||||
_jQuery(this).find(':visible').each(function() {
|
_jQuery(this).find(':visible').each(function() {
|
||||||
|
|
@ -250,14 +250,14 @@ angular.scenario.dsl('repeater', function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
chain.row = function(index) {
|
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 values = [];
|
||||||
var matches = $document.elements().slice(index, index + 1);
|
var matches = $document.elements().slice(index, index + 1);
|
||||||
if (!matches.length)
|
if (!matches.length)
|
||||||
return done('row ' + index + ' out of bounds');
|
return done('row ' + index + ' out of bounds');
|
||||||
_jQuery(matches[0]).find(':visible').each(function() {
|
_jQuery(matches[0]).find(':visible').each(function() {
|
||||||
var element = _jQuery(this);
|
var element = _jQuery(this);
|
||||||
if (element.attr('ng:bind')) {
|
if (angular.isDefined(element.attr('ng:bind'))) {
|
||||||
values.push(element.text());
|
values.push(element.text());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -280,7 +280,7 @@ angular.scenario.dsl('select', function() {
|
||||||
var chain = {};
|
var chain = {};
|
||||||
|
|
||||||
chain.option = function(value) {
|
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);
|
var select = $document.elements('select[name="$1"]', this.name);
|
||||||
select.val(value);
|
select.val(value);
|
||||||
select.trigger('change');
|
select.trigger('change');
|
||||||
|
|
@ -290,7 +290,7 @@ angular.scenario.dsl('select', function() {
|
||||||
|
|
||||||
chain.options = function() {
|
chain.options = function() {
|
||||||
var values = arguments;
|
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);
|
var select = $document.elements('select[multiple][name="$1"]', this.name);
|
||||||
select.val(values);
|
select.val(values);
|
||||||
select.trigger('change');
|
select.trigger('change');
|
||||||
|
|
@ -322,7 +322,7 @@ angular.scenario.dsl('element', function() {
|
||||||
var chain = {};
|
var chain = {};
|
||||||
|
|
||||||
chain.count = function() {
|
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 {
|
try {
|
||||||
done(null, $document.elements().length);
|
done(null, $document.elements().length);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
@ -332,7 +332,7 @@ angular.scenario.dsl('element', function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
chain.click = 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 elements = $document.elements();
|
||||||
var href = elements.attr('href');
|
var href = elements.attr('href');
|
||||||
elements.trigger('click');
|
elements.trigger('click');
|
||||||
|
|
@ -347,9 +347,9 @@ angular.scenario.dsl('element', function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
chain.attr = function(name, value) {
|
chain.attr = function(name, value) {
|
||||||
var futureName = 'element ' + this.label + ' get attribute ' + name;
|
var futureName = "element '" + this.label + "' get attribute '" + name + "'";
|
||||||
if (value) {
|
if (angular.isDefined(value)) {
|
||||||
futureName = 'element ' + this.label + ' set attribute ' + name + ' to ' + value;
|
futureName = "element '" + this.label + "' set attribute '" + name + "' to " + "'" + value + "'";
|
||||||
}
|
}
|
||||||
return this.addFutureAction(futureName, function($window, $document, done) {
|
return this.addFutureAction(futureName, function($window, $document, done) {
|
||||||
done(null, $document.elements().attr(name, value));
|
done(null, $document.elements().attr(name, value));
|
||||||
|
|
@ -364,9 +364,9 @@ angular.scenario.dsl('element', function() {
|
||||||
|
|
||||||
angular.foreach(VALUE_METHODS, function(methodName) {
|
angular.foreach(VALUE_METHODS, function(methodName) {
|
||||||
chain[methodName] = function(value) {
|
chain[methodName] = function(value) {
|
||||||
var futureName = 'element ' + this.label + ' ' + methodName;
|
var futureName = "element '" + this.label + "' " + methodName;
|
||||||
if (value) {
|
if (angular.isDefined(value)) {
|
||||||
futureName = 'element ' + this.label + ' set ' + methodName + ' to ' + value;
|
futureName = "element '" + this.label + "' set " + methodName + " to '" + value + "'";
|
||||||
}
|
}
|
||||||
return this.addFutureAction(futureName, function($window, $document, done) {
|
return this.addFutureAction(futureName, function($window, $document, done) {
|
||||||
var element = $document.elements();
|
var element = $document.elements();
|
||||||
|
|
|
||||||
|
|
@ -278,6 +278,18 @@ describe("angular.scenario.dsl", function() {
|
||||||
expect(doc.find('input').val()).toEqual('baz');
|
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() {
|
it('should add all jQuery property methods', function() {
|
||||||
var METHODS = [
|
var METHODS = [
|
||||||
'val', 'text', 'html', 'height', 'innerHeight', 'outerHeight', 'width',
|
'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() {
|
it('should use the selector as label if none is given', function() {
|
||||||
$root.dsl.element('mySelector');
|
$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() {
|
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() {
|
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() {
|
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() {
|
it('should use the selector as label if none is given', function() {
|
||||||
$root.dsl.using('mySelector');
|
$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() {
|
it('should include the selector in paren when a label is given', function() {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue