@@ -6,8 +6,6 @@ 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 getRectCenter = require ( '../assets/get_rect_center' ) ;
10
- var mouseEvent = require ( '../assets/mouse_event' ) ;
11
9
var TRANSITION_DELAY = 100 ;
12
10
13
11
describe ( 'update menus defaults' , function ( ) {
@@ -201,51 +199,51 @@ describe('update menus interactions', function() {
201
199
} ) ;
202
200
203
201
it ( 'should drop/fold buttons when clicking on header' , function ( done ) {
204
- var pos0 = getHeaderPos ( 0 ) ,
205
- pos1 = getHeaderPos ( 1 ) ;
202
+ var header0 = selectHeader ( 0 ) ,
203
+ header1 = selectHeader ( 1 ) ;
206
204
207
- click ( pos0 ) . then ( function ( ) {
205
+ click ( header0 ) . then ( function ( ) {
208
206
assertMenus ( [ 3 , 0 ] ) ;
209
- return click ( pos0 ) ;
207
+ return click ( header0 ) ;
210
208
} ) . then ( function ( ) {
211
209
assertMenus ( [ 0 , 0 ] ) ;
212
- return click ( pos1 ) ;
210
+ return click ( header1 ) ;
213
211
} ) . then ( function ( ) {
214
212
assertMenus ( [ 0 , 4 ] ) ;
215
- return click ( pos1 ) ;
213
+ return click ( header1 ) ;
216
214
} ) . then ( function ( ) {
217
215
assertMenus ( [ 0 , 0 ] ) ;
218
- return click ( pos0 ) ;
216
+ return click ( header0 ) ;
219
217
} ) . then ( function ( ) {
220
218
assertMenus ( [ 3 , 0 ] ) ;
221
- return click ( pos1 ) ;
219
+ return click ( header1 ) ;
222
220
} ) . then ( function ( ) {
223
221
assertMenus ( [ 0 , 4 ] ) ;
224
- return click ( pos0 ) ;
222
+ return click ( header0 ) ;
225
223
} ) . then ( function ( ) {
226
224
assertMenus ( [ 3 , 0 ] ) ;
227
225
done ( ) ;
228
226
} ) ;
229
227
} ) ;
230
228
231
229
it ( 'should apply update on button click' , function ( done ) {
232
- var pos0 = getHeaderPos ( 0 ) ,
233
- pos1 = getHeaderPos ( 1 ) ;
230
+ var header0 = selectHeader ( 0 ) ,
231
+ header1 = selectHeader ( 1 ) ;
234
232
235
233
assertActive ( gd , [ 1 , 2 ] ) ;
236
234
237
- click ( pos0 ) . then ( function ( ) {
235
+ click ( header0 ) . then ( function ( ) {
238
236
assertItemColor ( selectButton ( 1 ) , activeColor ) ;
239
237
240
- return click ( getButtonPos ( 0 ) ) ;
238
+ return click ( selectButton ( 0 ) ) ;
241
239
} ) . then ( function ( ) {
242
240
assertActive ( gd , [ 0 , 2 ] ) ;
243
241
244
- return click ( pos1 ) ;
242
+ return click ( header1 ) ;
245
243
} ) . then ( function ( ) {
246
244
assertItemColor ( selectButton ( 2 ) , activeColor ) ;
247
245
248
- return click ( getButtonPos ( 0 ) ) ;
246
+ return click ( selectButton ( 0 ) ) ;
249
247
} ) . then ( function ( ) {
250
248
assertActive ( gd , [ 0 , 0 ] ) ;
251
249
@@ -254,37 +252,34 @@ describe('update menus interactions', function() {
254
252
} ) ;
255
253
256
254
it ( 'should change color on mouse over' , function ( done ) {
257
- var header0 = selectHeader ( 0 ) ,
258
- pos0 = getHeaderPos ( 0 ) ;
255
+ var INDEX_0 = 2 ,
256
+ INDEX_1 = gd . layout . updatemenus [ 1 ] . active ;
257
+
258
+ var header0 = selectHeader ( 0 ) ;
259
259
260
260
assertItemColor ( header0 , bgColor ) ;
261
- mouseEvent ( 'mouseover' , pos0 [ 0 ] , pos0 [ 1 ] ) ;
261
+ mouseEvent ( 'mouseover' , header0 ) ;
262
262
assertItemColor ( header0 , activeColor ) ;
263
- mouseEvent ( 'mouseout' , pos0 [ 0 ] , pos0 [ 1 ] ) ;
263
+ mouseEvent ( 'mouseout' , header0 ) ;
264
264
assertItemColor ( header0 , bgColor ) ;
265
265
266
- click ( pos0 ) . then ( function ( ) {
267
- var index = 2 ,
268
- button = selectButton ( index ) ,
269
- pos = getButtonPos ( index ) ;
266
+ click ( header0 ) . then ( function ( ) {
267
+ var button = selectButton ( INDEX_0 ) ;
270
268
271
269
assertItemColor ( button , bgColor ) ;
272
- mouseEvent ( 'mouseover' , pos [ 0 ] , pos [ 1 ] ) ;
270
+ mouseEvent ( 'mouseover' , button ) ;
273
271
assertItemColor ( button , activeColor ) ;
274
- mouseEvent ( 'mouseout' , pos [ 0 ] , pos [ 1 ] ) ;
272
+ mouseEvent ( 'mouseout' , button ) ;
275
273
assertItemColor ( button , bgColor ) ;
276
274
277
- var pos1 = getHeaderPos ( 1 ) ;
278
- return click ( pos1 ) ;
275
+ return click ( selectHeader ( 1 ) ) ;
279
276
} ) . then ( function ( ) {
280
- var index = gd . layout . updatemenus [ 1 ] . active ,
281
- button = selectButton ( index ) ,
282
- pos = getButtonPos ( index ) ;
277
+ var button = selectButton ( INDEX_1 ) ;
283
278
284
279
assertItemColor ( button , activeColor ) ;
285
- mouseEvent ( 'mouseover' , pos [ 0 ] , pos [ 1 ] ) ;
280
+ mouseEvent ( 'mouseover' , button ) ;
286
281
assertItemColor ( button , activeColor ) ;
287
- mouseEvent ( 'mouseout' , pos [ 0 ] , pos [ 1 ] ) ;
282
+ mouseEvent ( 'mouseout' , button ) ;
288
283
assertItemColor ( button , activeColor ) ;
289
284
290
285
done ( ) ;
@@ -298,7 +293,7 @@ describe('update menus interactions', function() {
298
293
Plotly . relayout ( gd , 'updatemenus[0].bgcolor' , 'red' ) . then ( function ( ) {
299
294
assertItemColor ( selectHeader ( 0 ) , 'rgb(255, 0, 0)' ) ;
300
295
301
- return click ( getHeaderPos ( 0 ) ) ;
296
+ return click ( selectHeader ( 0 ) ) ;
302
297
} ) . then ( function ( ) {
303
298
assertMenus ( [ 3 , 0 ] ) ;
304
299
@@ -312,7 +307,7 @@ describe('update menus interactions', function() {
312
307
} ) . then ( function ( ) {
313
308
assertItemDims ( selectHeader ( 1 ) , 179 , 34.2 ) ;
314
309
315
- return click ( getHeaderPos ( 1 ) ) ;
310
+ return click ( selectHeader ( 1 ) ) ;
316
311
} ) . then ( function ( ) {
317
312
assertMenus ( [ 0 , 4 ] ) ;
318
313
@@ -321,7 +316,7 @@ describe('update menus interactions', function() {
321
316
// and delete buttons
322
317
assertMenus ( [ 0 ] ) ;
323
318
324
- return click ( getHeaderPos ( 0 ) ) ;
319
+ return click ( selectHeader ( 0 ) ) ;
325
320
} ) . then ( function ( ) {
326
321
assertMenus ( [ 3 ] ) ;
327
322
@@ -375,39 +370,44 @@ describe('update menus interactions', function() {
375
370
}
376
371
377
372
function assertItemDims ( node , width , height ) {
378
- var rect = node . select ( 'rect' ) ;
379
- expect ( + rect . attr ( 'width' ) ) . toEqual ( width ) ;
373
+ var rect = node . select ( 'rect' ) ,
374
+ actualWidth = + rect . attr ( 'width' ) ;
375
+
376
+ // must compare with a tolerance as the exact result
377
+ // is browser/font dependent (via getBBox)
378
+ expect ( Math . abs ( actualWidth - width ) ) . toBeLessThan ( 11 ) ;
379
+
380
+ // height is determined by 'fontsize',
381
+ // so no such tolerance is needed
380
382
expect ( + rect . attr ( 'height' ) ) . toEqual ( height ) ;
381
383
}
382
384
383
- function click ( pos ) {
385
+ function click ( selection ) {
384
386
return new Promise ( function ( resolve ) {
385
387
setTimeout ( function ( ) {
386
- mouseEvent ( 'click' , pos [ 0 ] , pos [ 1 ] ) ;
388
+ mouseEvent ( 'click' , selection ) ;
387
389
resolve ( ) ;
388
390
} , TRANSITION_DELAY ) ;
389
391
} ) ;
390
392
}
391
393
394
+ // For some reason, ../assets/mouse_event.js fails
395
+ // to detect the button elements in FF38 (like on CircleCI 2016/08/02),
396
+ // so dispatch the mouse event directly about the nodes instead.
397
+ function mouseEvent ( type , selection ) {
398
+ var ev = new window . MouseEvent ( type , { bubbles : true } ) ;
399
+ selection . node ( ) . dispatchEvent ( ev ) ;
400
+ }
401
+
392
402
function selectHeader ( menuIndex ) {
393
403
var headers = d3 . selectAll ( '.' + constants . headerClassName ) ,
394
404
header = d3 . select ( headers [ 0 ] [ menuIndex ] ) ;
395
405
return header ;
396
406
}
397
407
398
- function getHeaderPos ( menuIndex ) {
399
- var header = selectHeader ( menuIndex ) ;
400
- return getRectCenter ( header . select ( 'rect' ) . node ( ) ) ;
401
- }
402
-
403
408
function selectButton ( buttonIndex ) {
404
409
var buttons = d3 . selectAll ( '.' + constants . buttonClassName ) ,
405
410
button = d3 . select ( buttons [ 0 ] [ buttonIndex ] ) ;
406
411
return button ;
407
412
}
408
-
409
- function getButtonPos ( buttonIndex ) {
410
- var button = selectButton ( buttonIndex ) ;
411
- return getRectCenter ( button . select ( 'rect' ) . node ( ) ) ;
412
- }
413
413
} ) ;
0 commit comments