@@ -6,7 +6,8 @@ var Plotly = require('@lib');
6
6
var Lib = require ( '@src/lib' ) ;
7
7
var createGraphDiv = require ( '../assets/create_graph_div' ) ;
8
8
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' ) ;
10
11
11
12
describe ( 'sliders defaults' , function ( ) {
12
13
'use strict' ;
@@ -166,7 +167,7 @@ describe('sliders defaults', function() {
166
167
} ) ;
167
168
} ) ;
168
169
169
- it ( 'allow the `skip` method' , function ( ) {
170
+ it ( 'allows the `skip` method' , function ( ) {
170
171
layoutIn . sliders = [ {
171
172
steps : [ {
172
173
method : 'skip' ,
@@ -295,7 +296,7 @@ describe('ugly internal manipulation of steps', function() {
295
296
// The selected option no longer exists, so confirm it's
296
297
// been fixed during the process of updating/drawing it:
297
298
expect ( gd . _fullLayout . sliders [ 0 ] . active ) . toEqual ( 0 ) ;
298
- } ) . catch ( fail ) . then ( done ) ;
299
+ } ) . catch ( failTest ) . then ( done ) ;
299
300
} ) ;
300
301
} ) ;
301
302
@@ -366,7 +367,8 @@ describe('sliders interactions', function() {
366
367
expect ( gd . _fullLayout . _pushmargin [ 'slider-0' ] ) . toBeDefined ( ) ;
367
368
expect ( gd . _fullLayout . _pushmargin [ 'slider-1' ] ) . toBeDefined ( ) ;
368
369
} )
369
- . catch ( fail ) . then ( done ) ;
370
+ . catch ( failTest )
371
+ . then ( done ) ;
370
372
} ) ;
371
373
372
374
it ( 'should respond to mouse clicks' , function ( done ) {
@@ -396,17 +398,18 @@ describe('sliders interactions', function() {
396
398
var mousemoveFill = firstGrip . node ( ) . style . fill ;
397
399
expect ( mousemoveFill ) . toEqual ( mousedownFill ) ;
398
400
399
- setTimeout ( function ( ) {
401
+ delay ( 100 ) ( )
402
+ . then ( function ( ) {
400
403
expect ( mockCopy . layout . sliders [ 0 ] . active ) . toEqual ( 0 ) ;
401
404
402
405
gd . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
403
406
404
407
var mouseupFill = firstGrip . node ( ) . style . fill ;
405
408
expect ( mouseupFill ) . toEqual ( originalFill ) ;
406
409
expect ( mockCopy . layout . sliders [ 0 ] . active ) . toEqual ( 0 ) ;
407
-
408
- done ( ) ;
409
- } , 100 ) ;
410
+ } )
411
+ . catch ( failTest )
412
+ . then ( done ) ;
410
413
} ) ;
411
414
412
415
it ( 'should issue events on interaction' , function ( done ) {
@@ -427,15 +430,14 @@ describe('sliders interactions', function() {
427
430
cntEnd ++ ;
428
431
} ) ;
429
432
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 ) ;
436
438
}
437
439
438
- assertEventCounts ( 0 , 0 , 0 , 0 ) ;
440
+ assertEventCounts ( 0 , 0 , 0 , 0 , 'initial' ) ;
439
441
440
442
var firstGroup = gd . _fullLayout . _infolayer . select ( '.' + constants . railTouchRectClass ) ;
441
443
var railNode = firstGroup . node ( ) ;
@@ -447,30 +449,31 @@ describe('sliders interactions', function() {
447
449
clientX : touchRect . left + touchRect . width - 5 ,
448
450
} ) ) ;
449
451
450
- setTimeout ( function ( ) {
452
+ delay ( 50 ) ( )
453
+ . then ( function ( ) {
451
454
// 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' ) ;
453
456
454
457
// Drag to the left side:
455
458
gd . dispatchEvent ( new MouseEvent ( 'mousemove' , {
456
459
clientY : touchRect . top + 5 ,
457
460
clientX : touchRect . left + 5 ,
458
461
} ) ) ;
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' ) ;
459
467
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 ) ;
474
477
} ) ;
475
478
476
479
function assertNodeCount ( query , cnt ) {
0 commit comments