@@ -28,7 +28,8 @@ describe('ModeBar', function() {
28
28
_context : {
29
29
displaylogo : true ,
30
30
displayModeBar : true ,
31
- modeBarButtonsToRemove : [ ]
31
+ modeBarButtonsToRemove : [ ] ,
32
+ modeBarButtonsToAdd : [ ]
32
33
}
33
34
} ;
34
35
}
@@ -144,10 +145,9 @@ describe('ModeBar', function() {
144
145
function getButtons ( list ) {
145
146
for ( var i = 0 ; i < list . length ; i ++ ) {
146
147
for ( var j = 0 ; j < list [ i ] . length ; j ++ ) {
147
- list [ i ] [ j ] = {
148
- name : list [ i ] [ j ] ,
149
- click : noop
150
- } ;
148
+
149
+ // minimal button config object
150
+ list [ i ] [ j ] = { name : list [ i ] [ j ] , click : noop } ;
151
151
}
152
152
}
153
153
return list ;
@@ -277,6 +277,13 @@ describe('ModeBar', function() {
277
277
expect ( function ( ) { manageModeBar ( gd ) ; } ) . toThrowError ( ) ;
278
278
} ) ;
279
279
280
+ it ( 'throws an error if modeBarButtonsToAdd isn\'t an array' , function ( ) {
281
+ var gd = getMockGraphInfo ( ) ;
282
+ gd . _context . modeBarButtonsToAdd = 'not gonna work' ;
283
+
284
+ expect ( function ( ) { manageModeBar ( gd ) ; } ) . toThrowError ( ) ;
285
+ } ) ;
286
+
280
287
it ( 'displays or not mode bar according to displayModeBar config arg' , function ( ) {
281
288
var gd = getMockGraphInfo ( ) ;
282
289
manageModeBar ( gd ) ;
@@ -297,31 +304,108 @@ describe('ModeBar', function() {
297
304
expect ( countLogo ( gd . _fullLayout . _modeBar ) ) . toEqual ( 0 ) ;
298
305
} ) ;
299
306
300
- it ( 'updates mode bar buttons if plot type changes' , function ( ) {
307
+ // gives 11 buttons in 5 groups by default
308
+ function setupGraphInfo ( ) {
301
309
var gd = getMockGraphInfo ( ) ;
302
310
gd . _fullLayout . _hasCartesian = true ;
303
311
gd . _fullLayout . xaxis = { fixedrange : false } ;
312
+ return gd ;
313
+ }
314
+
315
+ it ( 'updates mode bar buttons if plot type changes' , function ( ) {
316
+ var gd = setupGraphInfo ( ) ;
317
+ manageModeBar ( gd ) ;
304
318
305
- manageModeBar ( gd ) ; // gives 11 buttons
306
319
gd . _fullLayout . _hasCartesian = false ;
307
320
gd . _fullLayout . _hasGL3D = true ;
308
321
manageModeBar ( gd ) ;
309
322
310
323
expect ( countButtons ( gd . _fullLayout . _modeBar ) ) . toEqual ( 10 ) ;
311
324
} ) ;
312
325
313
- it ( 'updates mode bar buttons if plot type changes' , function ( ) {
314
- var gd = getMockGraphInfo ( ) ;
315
- gd . _fullLayout . _hasCartesian = true ;
316
- gd . _fullLayout . xaxis = { fixedrange : false } ;
326
+ it ( 'updates mode bar buttons if modeBarButtonsToRemove changes' , function ( ) {
327
+ var gd = setupGraphInfo ( ) ;
328
+ manageModeBar ( gd ) ;
317
329
318
- manageModeBar ( gd ) ; // gives 11 buttons
319
330
gd . _context . modeBarButtonsToRemove = [ 'toImage' , 'sendDataToCloud' ] ;
320
331
manageModeBar ( gd ) ;
321
332
322
333
expect ( countButtons ( gd . _fullLayout . _modeBar ) ) . toEqual ( 9 ) ;
323
334
} ) ;
324
335
336
+ it ( 'updates mode bar buttons if modeBarButtonsToAdd changes' , function ( ) {
337
+ var gd = setupGraphInfo ( ) ;
338
+ manageModeBar ( gd ) ;
339
+
340
+ gd . _context . modeBarButtonsToAdd = [ {
341
+ name : 'some button' ,
342
+ click : noop
343
+ } ] ;
344
+ manageModeBar ( gd ) ;
345
+
346
+ expect ( countGroups ( gd . _fullLayout . _modeBar ) ) . toEqual ( 6 ) ;
347
+ expect ( countButtons ( gd . _fullLayout . _modeBar ) ) . toEqual ( 12 ) ;
348
+ } ) ;
349
+
350
+ it ( 'sets up buttons with modeBarButtonsToAdd and modeBarButtonToRemove' , function ( ) {
351
+ var gd = setupGraphInfo ( ) ;
352
+ gd . _context . modeBarButtonsToRemove = [
353
+ 'toImage' , 'pan2d' , 'hoverCompareCartesian'
354
+ ] ;
355
+ gd . _context . modeBarButtonsToAdd = [
356
+ { name : 'some button' , click : noop } ,
357
+ { name : 'some other button' , click : noop }
358
+ ] ;
359
+
360
+ manageModeBar ( gd ) ;
361
+
362
+ var modeBar = gd . _fullLayout . _modeBar ;
363
+ expect ( countGroups ( modeBar ) ) . toEqual ( 6 ) ;
364
+ expect ( countButtons ( modeBar ) ) . toEqual ( 10 ) ;
365
+ } ) ;
366
+
367
+ it ( 'sets up buttons with fully custom modeBarButtons' , function ( ) {
368
+ var gd = setupGraphInfo ( ) ;
369
+ gd . _context . modeBarButtons = [ [
370
+ { name : 'some button' , click : noop } ,
371
+ { name : 'some other button' , click : noop }
372
+ ] , [
373
+ { name : 'some button in another group' , click : noop } ,
374
+ { name : 'some other button in another group' , click : noop }
375
+ ] ] ;
376
+
377
+ manageModeBar ( gd ) ;
378
+
379
+ var modeBar = gd . _fullLayout . _modeBar ;
380
+ expect ( countGroups ( modeBar ) ) . toEqual ( 3 ) ;
381
+ expect ( countButtons ( modeBar ) ) . toEqual ( 5 ) ;
382
+ } ) ;
383
+
384
+ it ( 'sets up buttons with custom modeBarButtons + default name' , function ( ) {
385
+ var gd = setupGraphInfo ( ) ;
386
+ gd . _context . modeBarButtons = [ [
387
+ { name : 'some button' , click : noop } ,
388
+ { name : 'some other button' , click : noop }
389
+ ] , [
390
+ 'toImage' , 'pan2d' , 'hoverCompareCartesian'
391
+ ] ] ;
392
+
393
+ manageModeBar ( gd ) ;
394
+
395
+ var modeBar = gd . _fullLayout . _modeBar ;
396
+ expect ( countGroups ( modeBar ) ) . toEqual ( 3 ) ;
397
+ expect ( countButtons ( modeBar ) ) . toEqual ( 6 ) ;
398
+ } ) ;
399
+
400
+ it ( 'throw error when modeBarButtons contains invalid name' , function ( ) {
401
+ var gd = setupGraphInfo ( ) ;
402
+ gd . _context . modeBarButtons = [ [
403
+ 'toImage' , 'pan2d' , 'no gonna work'
404
+ ] ] ;
405
+
406
+ expect ( function ( ) { manageModeBar ( gd ) ; } ) . toThrowError ( ) ;
407
+ } ) ;
408
+
325
409
} ) ;
326
410
327
411
} ) ;
0 commit comments