Skip to content

Commit 56a3d52

Browse files
esprehnIgorMinar
authored andcommitted
Make future names consistent and handle falsy values in jQuery generated methods properly
1 parent faa7d81 commit 56a3d52

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

src/scenario/SpecRunner.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ angular.scenario.SpecRunner.prototype.addFutureAction = function(name, behavior,
110110
//TODO(esprehn): Refactor this so it doesn't need to be in here.
111111
$document.elements = function(selector) {
112112
var args = Array.prototype.slice.call(arguments, 1);
113-
if (self.selector) {
114-
selector = self.selector + ' ' + (selector || '');
115-
}
113+
selector = (self.selector || '') + ' ' + (selector || '');
116114
angular.foreach(args, function(value, index) {
117115
selector = selector.replace('$' + (index + 1), value);
118116
});

src/scenario/dsl.js

+18-18
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ angular.scenario.dsl('browser', function() {
4343

4444
chain.navigateTo = function(url, delegate) {
4545
var application = this.application;
46-
return this.addFuture('browser navigate to ' + url, function(done) {
46+
return this.addFuture("browser navigate to '" + url + "'", function(done) {
4747
if (delegate) {
4848
url = delegate.call(this, url);
4949
}
@@ -140,9 +140,9 @@ angular.scenario.dsl('expect', function() {
140140
*/
141141
angular.scenario.dsl('using', function() {
142142
return function(selector, label) {
143-
this.selector = (this.selector||'') + ' ' + selector;
143+
this.selector = _jQuery.trim((this.selector||'') + ' ' + selector);
144144
if (angular.isString(label) && label.length) {
145-
this.label = label + ' (' + this.selector + ' )';
145+
this.label = label + ' ( ' + this.selector + ' )';
146146
} else {
147147
this.label = this.selector;
148148
}
@@ -169,7 +169,7 @@ angular.scenario.dsl('binding', function() {
169169
return;
170170
}
171171
}
172-
done('Binding selector ' + name + ' did not match.');
172+
done("Binding selector '" + name + "' did not match.");
173173
});
174174
};
175175
});
@@ -225,7 +225,7 @@ angular.scenario.dsl('repeater', function() {
225225
var chain = {};
226226

227227
chain.count = function() {
228-
return this.addFutureAction('repeater ' + this.label + ' count', function($window, $document, done) {
228+
return this.addFutureAction("repeater '" + this.label + "' count", function($window, $document, done) {
229229
try {
230230
done(null, $document.elements().length);
231231
} catch (e) {
@@ -235,7 +235,7 @@ angular.scenario.dsl('repeater', function() {
235235
};
236236

237237
chain.column = function(binding) {
238-
return this.addFutureAction('repeater ' + this.label + ' column ' + binding, function($window, $document, done) {
238+
return this.addFutureAction("repeater '" + this.label + "' column '" + binding + "'", function($window, $document, done) {
239239
var values = [];
240240
$document.elements().each(function() {
241241
_jQuery(this).find(':visible').each(function() {
@@ -250,14 +250,14 @@ angular.scenario.dsl('repeater', function() {
250250
};
251251

252252
chain.row = function(index) {
253-
return this.addFutureAction('repeater ' + this.label + ' row ' + index, function($window, $document, done) {
253+
return this.addFutureAction("repeater '" + this.label + "' row '" + index + "'", function($window, $document, done) {
254254
var values = [];
255255
var matches = $document.elements().slice(index, index + 1);
256256
if (!matches.length)
257257
return done('row ' + index + ' out of bounds');
258258
_jQuery(matches[0]).find(':visible').each(function() {
259259
var element = _jQuery(this);
260-
if (element.attr('ng:bind')) {
260+
if (angular.isDefined(element.attr('ng:bind'))) {
261261
values.push(element.text());
262262
}
263263
});
@@ -280,7 +280,7 @@ angular.scenario.dsl('select', function() {
280280
var chain = {};
281281

282282
chain.option = function(value) {
283-
return this.addFutureAction('select ' + this.name + ' option ' + value, function($window, $document, done) {
283+
return this.addFutureAction("select '" + this.name + "' option '" + value + "'", function($window, $document, done) {
284284
var select = $document.elements('select[name="$1"]', this.name);
285285
select.val(value);
286286
select.trigger('change');
@@ -290,7 +290,7 @@ angular.scenario.dsl('select', function() {
290290

291291
chain.options = function() {
292292
var values = arguments;
293-
return this.addFutureAction('select ' + this.name + ' options ' + values, function($window, $document, done) {
293+
return this.addFutureAction("select '" + this.name + "' options '" + values + "'", function($window, $document, done) {
294294
var select = $document.elements('select[multiple][name="$1"]', this.name);
295295
select.val(values);
296296
select.trigger('change');
@@ -322,7 +322,7 @@ angular.scenario.dsl('element', function() {
322322
var chain = {};
323323

324324
chain.count = function() {
325-
return this.addFutureAction('element ' + this.label + ' count', function($window, $document, done) {
325+
return this.addFutureAction("element '" + this.label + "' count", function($window, $document, done) {
326326
try {
327327
done(null, $document.elements().length);
328328
} catch (e) {
@@ -332,7 +332,7 @@ angular.scenario.dsl('element', function() {
332332
};
333333

334334
chain.click = function() {
335-
return this.addFutureAction('element ' + this.label + ' click', function($window, $document, done) {
335+
return this.addFutureAction("element '" + this.label + "' click", function($window, $document, done) {
336336
var elements = $document.elements();
337337
var href = elements.attr('href');
338338
elements.trigger('click');
@@ -347,9 +347,9 @@ angular.scenario.dsl('element', function() {
347347
};
348348

349349
chain.attr = function(name, value) {
350-
var futureName = 'element ' + this.label + ' get attribute ' + name;
351-
if (value) {
352-
futureName = 'element ' + this.label + ' set attribute ' + name + ' to ' + value;
350+
var futureName = "element '" + this.label + "' get attribute '" + name + "'";
351+
if (angular.isDefined(value)) {
352+
futureName = "element '" + this.label + "' set attribute '" + name + "' to " + "'" + value + "'";
353353
}
354354
return this.addFutureAction(futureName, function($window, $document, done) {
355355
done(null, $document.elements().attr(name, value));
@@ -364,9 +364,9 @@ angular.scenario.dsl('element', function() {
364364

365365
angular.foreach(VALUE_METHODS, function(methodName) {
366366
chain[methodName] = function(value) {
367-
var futureName = 'element ' + this.label + ' ' + methodName;
368-
if (value) {
369-
futureName = 'element ' + this.label + ' set ' + methodName + ' to ' + value;
367+
var futureName = "element '" + this.label + "' " + methodName;
368+
if (angular.isDefined(value)) {
369+
futureName = "element '" + this.label + "' set " + methodName + " to '" + value + "'";
370370
}
371371
return this.addFutureAction(futureName, function($window, $document, done) {
372372
var element = $document.elements();

test/scenario/dslSpec.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,18 @@ describe("angular.scenario.dsl", function() {
278278
expect(doc.find('input').val()).toEqual('baz');
279279
});
280280

281+
it('should use correct future name for generated set methods', function() {
282+
doc.append('<input value="bar">');
283+
$root.dsl.element('input').val(false);
284+
expect($root.futures.pop()).toMatch(/element 'input' set val/);
285+
});
286+
287+
it('should use correct future name for generated get methods', function() {
288+
doc.append('<input value="bar">');
289+
$root.dsl.element('input').val();
290+
expect($root.futures.pop()).toMatch(/element 'input' val/);
291+
});
292+
281293
it('should add all jQuery property methods', function() {
282294
var METHODS = [
283295
'val', 'text', 'html', 'height', 'innerHeight', 'outerHeight', 'width',
@@ -299,7 +311,7 @@ describe("angular.scenario.dsl", function() {
299311

300312
it('should use the selector as label if none is given', function() {
301313
$root.dsl.element('mySelector');
302-
expect($root.label).toEqual(' mySelector');
314+
expect($root.label).toEqual('mySelector');
303315
});
304316

305317
it('should include the selector in paren when a label is given', function() {
@@ -342,7 +354,7 @@ describe("angular.scenario.dsl", function() {
342354
});
343355

344356
it('should use the selector as label if none is given', function() {
345-
expect($root.label).toEqual(' ul li');
357+
expect($root.label).toEqual('ul li');
346358
});
347359

348360
it('should include the selector in paren when a label is given', function() {
@@ -398,7 +410,7 @@ describe("angular.scenario.dsl", function() {
398410

399411
it('should use the selector as label if none is given', function() {
400412
$root.dsl.using('mySelector');
401-
expect($root.label).toEqual(' mySelector');
413+
expect($root.label).toEqual('mySelector');
402414
});
403415

404416
it('should include the selector in paren when a label is given', function() {

0 commit comments

Comments
 (0)