@@ -186,13 +186,14 @@ describe('update sliders interactions', function() {
186
186
'use strict' ;
187
187
188
188
var mock = require ( '@mocks/sliders.json' ) ;
189
+ var mockCopy ;
189
190
190
191
var gd ;
191
192
192
193
beforeEach ( function ( done ) {
193
194
gd = createGraphDiv ( ) ;
194
195
195
- var mockCopy = Lib . extendDeep ( { } , mock ) ;
196
+ mockCopy = Lib . extendDeep ( { } , mock ) ;
196
197
197
198
Plotly . plot ( gd , mockCopy . data , mockCopy . layout ) . then ( done ) ;
198
199
} ) ;
@@ -249,6 +250,46 @@ describe('update sliders interactions', function() {
249
250
. catch ( fail ) . then ( done ) ;
250
251
} ) ;
251
252
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
+
252
293
function assertNodeCount ( query , cnt ) {
253
294
expect ( d3 . selectAll ( query ) . size ( ) ) . toEqual ( cnt ) ;
254
295
}
0 commit comments