@@ -319,6 +319,70 @@ describe('sliders interactions', function() {
319
319
} , 100 ) ;
320
320
} ) ;
321
321
322
+ it ( 'should issue events on interaction' , function ( done ) {
323
+ var cntStart = 0 ;
324
+ var cntInteraction = 0 ;
325
+ var cntNonInteraction = 0 ;
326
+ var cntEnd = 0 ;
327
+
328
+ gd . on ( 'plotly_sliderstart' , function ( ) {
329
+ cntStart ++ ;
330
+ } ) . on ( 'plotly_sliderchange' , function ( datum ) {
331
+ if ( datum . interaction ) {
332
+ cntInteraction ++ ;
333
+ } else {
334
+ cntNonInteraction ++ ;
335
+ }
336
+ } ) . on ( 'plotly_sliderend' , function ( ) {
337
+ cntEnd ++ ;
338
+ } ) ;
339
+
340
+ function assertEventCounts ( starts , interactions , noninteractions , ends ) {
341
+ expect (
342
+ [ cntStart , cntInteraction , cntNonInteraction , cntEnd ]
343
+ ) . toEqual (
344
+ [ starts , interactions , noninteractions , ends ]
345
+ ) ;
346
+ }
347
+
348
+ assertEventCounts ( 0 , 0 , 0 , 0 ) ;
349
+
350
+ var firstGroup = gd . _fullLayout . _infolayer . select ( '.' + constants . railTouchRectClass ) ;
351
+ var railNode = firstGroup . node ( ) ;
352
+ var touchRect = railNode . getBoundingClientRect ( ) ;
353
+
354
+ // Dispatch a click on the right side of the bar:
355
+ railNode . dispatchEvent ( new MouseEvent ( 'mousedown' , {
356
+ clientY : touchRect . top + 5 ,
357
+ clientX : touchRect . left + touchRect . width - 5 ,
358
+ } ) ) ;
359
+
360
+ setTimeout ( function ( ) {
361
+ // One slider received a mousedown, one received an interaction, and one received a change:
362
+ assertEventCounts ( 1 , 1 , 1 , 0 ) ;
363
+
364
+ // Drag to the left side:
365
+ gd . dispatchEvent ( new MouseEvent ( 'mousemove' , {
366
+ clientY : touchRect . top + 5 ,
367
+ clientX : touchRect . left + 5 ,
368
+ } ) ) ;
369
+
370
+ setTimeout ( function ( ) {
371
+ // On move, now to changes for the each slider, and no ends:
372
+ assertEventCounts ( 1 , 2 , 2 , 0 ) ;
373
+
374
+ gd . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
375
+
376
+ setTimeout ( function ( ) {
377
+ // Now an end:
378
+ assertEventCounts ( 1 , 2 , 2 , 1 ) ;
379
+
380
+ done ( ) ;
381
+ } , 50 ) ;
382
+ } , 50 ) ;
383
+ } , 50 ) ;
384
+ } ) ;
385
+
322
386
function assertNodeCount ( query , cnt ) {
323
387
expect ( d3 . selectAll ( query ) . size ( ) ) . toEqual ( cnt ) ;
324
388
}
0 commit comments