@@ -186,13 +186,14 @@ describe('update sliders interactions', function() {
186186 'use strict' ;
187187
188188 var mock = require ( '@mocks/sliders.json' ) ;
189+ var mockCopy ;
189190
190191 var gd ;
191192
192193 beforeEach ( function ( done ) {
193194 gd = createGraphDiv ( ) ;
194195
195- var mockCopy = Lib . extendDeep ( { } , mock ) ;
196+ mockCopy = Lib . extendDeep ( { } , mock ) ;
196197
197198 Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( done ) ;
198199 } ) ;
@@ -249,6 +250,46 @@ describe('update sliders interactions', function() {
249250 . catch ( fail ) . then ( done ) ;
250251 } ) ;
251252
253+ it ( 'should respond to mouse clicks' , function ( done ) {
254+ var firstGroup = gd . _fullLayout . _infolayer . select ( '.' + constants . railTouchRectClass ) ;
255+ var firstGrip = gd . _fullLayout . _infolayer . select ( '.' + constants . gripRectClass ) ;
256+ var railNode = firstGroup . node ( ) ;
257+ var touchRect = railNode . getBoundingClientRect ( ) ;
258+
259+ var originalFill = firstGrip . style ( 'fill' ) ;
260+
261+ // Dispatch a click on the right side of the bar:
262+ railNode . dispatchEvent ( new MouseEvent ( 'mousedown' , {
263+ clientY : touchRect . top + 5 ,
264+ clientX : touchRect . left + touchRect . width - 5 ,
265+ } ) ) ;
266+
267+ expect ( mockCopy . layout . sliders [ 0 ] . active ) . toEqual ( 5 ) ;
268+ var mousedownFill = firstGrip . style ( 'fill' ) ;
269+ expect ( mousedownFill ) . not . toEqual ( originalFill ) ;
270+
271+ // Drag to the left side:
272+ gd . dispatchEvent ( new MouseEvent ( 'mousemove' , {
273+ clientY : touchRect . top + 5 ,
274+ clientX : touchRect . left + 5 ,
275+ } ) ) ;
276+
277+ var mousemoveFill = firstGrip . style ( 'fill' ) ;
278+ expect ( mousemoveFill ) . toEqual ( mousedownFill ) ;
279+
280+ setTimeout ( function ( ) {
281+ expect ( mockCopy . layout . sliders [ 0 ] . active ) . toEqual ( 0 ) ;
282+
283+ gd . dispatchEvent ( new MouseEvent ( 'mouseup' ) ) ;
284+
285+ var mouseupFill = firstGrip . style ( 'fill' ) ;
286+ expect ( mouseupFill ) . toEqual ( originalFill ) ;
287+ expect ( mockCopy . layout . sliders [ 0 ] . active ) . toEqual ( 0 ) ;
288+
289+ done ( ) ;
290+ } , 100 ) ;
291+ } ) ;
292+
252293 function assertNodeCount ( query , cnt ) {
253294 expect ( d3 . selectAll ( query ) . size ( ) ) . toEqual ( cnt ) ;
254295 }
0 commit comments