Skip to content

Commit 222f396

Browse files
committed
cleanup in sliders_test
1 parent f9fbbc6 commit 222f396

File tree

2 files changed

+38
-31
lines changed

2 files changed

+38
-31
lines changed

test/jasmine/assets/delay.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
* like the `delay` module.
66
*
77
* Promise.resolve().then(delay(50)).then(...);
8+
*
9+
* or:
10+
*
11+
* delay(50)().then(...);
812
*/
913
module.exports = function delay(duration) {
1014
return function(value) {

test/jasmine/tests/sliders_test.js

Lines changed: 34 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ var Plotly = require('@lib');
66
var Lib = require('@src/lib');
77
var createGraphDiv = require('../assets/create_graph_div');
88
var destroyGraphDiv = require('../assets/destroy_graph_div');
9-
var fail = require('../assets/fail_test');
9+
var failTest = require('../assets/fail_test');
10+
var delay = require('../assets/delay');
1011

1112
describe('sliders defaults', function() {
1213
'use strict';
@@ -166,7 +167,7 @@ describe('sliders defaults', function() {
166167
});
167168
});
168169

169-
it('allow the `skip` method', function() {
170+
it('allows the `skip` method', function() {
170171
layoutIn.sliders = [{
171172
steps: [{
172173
method: 'skip',
@@ -295,7 +296,7 @@ describe('ugly internal manipulation of steps', function() {
295296
// The selected option no longer exists, so confirm it's
296297
// been fixed during the process of updating/drawing it:
297298
expect(gd._fullLayout.sliders[0].active).toEqual(0);
298-
}).catch(fail).then(done);
299+
}).catch(failTest).then(done);
299300
});
300301
});
301302

@@ -366,7 +367,8 @@ describe('sliders interactions', function() {
366367
expect(gd._fullLayout._pushmargin['slider-0']).toBeDefined();
367368
expect(gd._fullLayout._pushmargin['slider-1']).toBeDefined();
368369
})
369-
.catch(fail).then(done);
370+
.catch(failTest)
371+
.then(done);
370372
});
371373

372374
it('should respond to mouse clicks', function(done) {
@@ -396,17 +398,18 @@ describe('sliders interactions', function() {
396398
var mousemoveFill = firstGrip.node().style.fill;
397399
expect(mousemoveFill).toEqual(mousedownFill);
398400

399-
setTimeout(function() {
401+
delay(100)()
402+
.then(function() {
400403
expect(mockCopy.layout.sliders[0].active).toEqual(0);
401404

402405
gd.dispatchEvent(new MouseEvent('mouseup'));
403406

404407
var mouseupFill = firstGrip.node().style.fill;
405408
expect(mouseupFill).toEqual(originalFill);
406409
expect(mockCopy.layout.sliders[0].active).toEqual(0);
407-
408-
done();
409-
}, 100);
410+
})
411+
.catch(failTest)
412+
.then(done);
410413
});
411414

412415
it('should issue events on interaction', function(done) {
@@ -427,15 +430,14 @@ describe('sliders interactions', function() {
427430
cntEnd++;
428431
});
429432

430-
function assertEventCounts(starts, interactions, noninteractions, ends) {
431-
expect(
432-
[cntStart, cntInteraction, cntNonInteraction, cntEnd]
433-
).toEqual(
434-
[starts, interactions, noninteractions, ends]
435-
);
433+
function assertEventCounts(starts, interactions, noninteractions, ends, msg) {
434+
expect(cntStart).toBe(starts, 'starts: ' + msg);
435+
expect(cntInteraction).toBe(interactions, 'interactions: ' + msg);
436+
expect(cntNonInteraction).toBe(noninteractions, 'noninteractions: ' + msg);
437+
expect(cntEnd).toBe(ends, 'ends: ' + msg);
436438
}
437439

438-
assertEventCounts(0, 0, 0, 0);
440+
assertEventCounts(0, 0, 0, 0, 'initial');
439441

440442
var firstGroup = gd._fullLayout._infolayer.select('.' + constants.railTouchRectClass);
441443
var railNode = firstGroup.node();
@@ -447,30 +449,31 @@ describe('sliders interactions', function() {
447449
clientX: touchRect.left + touchRect.width - 5,
448450
}));
449451

450-
setTimeout(function() {
452+
delay(50)()
453+
.then(function() {
451454
// One slider received a mousedown, one received an interaction, and one received a change:
452-
assertEventCounts(1, 1, 1, 0);
455+
assertEventCounts(1, 1, 1, 0, 'mousedown');
453456

454457
// Drag to the left side:
455458
gd.dispatchEvent(new MouseEvent('mousemove', {
456459
clientY: touchRect.top + 5,
457460
clientX: touchRect.left + 5,
458461
}));
462+
})
463+
.then(delay(50))
464+
.then(function() {
465+
// On move, now to changes for the each slider, and no ends:
466+
assertEventCounts(1, 2, 2, 0, 'mousemove');
459467

460-
setTimeout(function() {
461-
// On move, now to changes for the each slider, and no ends:
462-
assertEventCounts(1, 2, 2, 0);
463-
464-
gd.dispatchEvent(new MouseEvent('mouseup'));
465-
466-
setTimeout(function() {
467-
// Now an end:
468-
assertEventCounts(1, 2, 2, 1);
469-
470-
done();
471-
}, 50);
472-
}, 50);
473-
}, 50);
468+
gd.dispatchEvent(new MouseEvent('mouseup'));
469+
})
470+
.then(delay(50))
471+
.then(function() {
472+
// Now an end:
473+
assertEventCounts(1, 2, 2, 1, 'mouseup');
474+
})
475+
.catch(failTest)
476+
.then(done);
474477
});
475478

476479
function assertNodeCount(query, cnt) {

0 commit comments

Comments
 (0)