@@ -25,6 +25,7 @@ describe('ModeBar', function() {
25
25
dragmode : 'zoom' ,
26
26
_paperdiv : d3 . select ( getMockContainerTree ( ) )
27
27
} ,
28
+ _fullData : [ ] ,
28
29
_context : {
29
30
displaylogo : true ,
30
31
displayModeBar : true ,
@@ -158,7 +159,38 @@ describe('ModeBar', function() {
158
159
return list ;
159
160
}
160
161
161
- it ( 'creates mode bar (cartesian version)' , function ( ) {
162
+ function checkButtons ( modeBar , buttons , logos ) {
163
+ var expectedGroupCount = buttons . length + logos ;
164
+ var expectedButtonCount = logos ;
165
+ buttons . forEach ( function ( group ) {
166
+ expectedButtonCount += group . length ;
167
+ } ) ;
168
+
169
+ expect ( modeBar . hasButtons ( buttons ) ) . toBe ( true ) ;
170
+ expect ( countGroups ( modeBar ) ) . toEqual ( expectedGroupCount ) ;
171
+ expect ( countButtons ( modeBar ) ) . toEqual ( expectedButtonCount ) ;
172
+ expect ( countLogo ( modeBar ) ) . toEqual ( 1 ) ;
173
+ }
174
+
175
+ it ( 'creates mode bar (unselectable cartesian version)' , function ( ) {
176
+ var buttons = getButtons ( [
177
+ [ 'toImage' , 'sendDataToCloud' ] ,
178
+ [ 'zoom2d' , 'pan2d' ] ,
179
+ [ 'zoomIn2d' , 'zoomOut2d' , 'autoScale2d' , 'resetScale2d' ] ,
180
+ [ 'hoverClosestCartesian' , 'hoverCompareCartesian' ]
181
+ ] ) ;
182
+
183
+ var gd = getMockGraphInfo ( ) ;
184
+ gd . _fullLayout . _hasCartesian = true ;
185
+ gd . _fullLayout . xaxis = { fixedrange : false } ;
186
+
187
+ manageModeBar ( gd ) ;
188
+ var modeBar = gd . _fullLayout . _modeBar ;
189
+
190
+ checkButtons ( modeBar , buttons , 1 ) ;
191
+ } ) ;
192
+
193
+ it ( 'creates mode bar (selectable cartesian version)' , function ( ) {
162
194
var buttons = getButtons ( [
163
195
[ 'toImage' , 'sendDataToCloud' ] ,
164
196
[ 'zoom2d' , 'pan2d' , 'select2d' , 'lasso2d' ] ,
@@ -169,20 +201,22 @@ describe('ModeBar', function() {
169
201
var gd = getMockGraphInfo ( ) ;
170
202
gd . _fullLayout . _hasCartesian = true ;
171
203
gd . _fullLayout . xaxis = { fixedrange : false } ;
204
+ gd . _fullData = [ {
205
+ type :'scatter' ,
206
+ visible : true ,
207
+ mode :'markers' ,
208
+ _module : { selectPoints : true }
209
+ } ] ;
172
210
173
211
manageModeBar ( gd ) ;
174
212
var modeBar = gd . _fullLayout . _modeBar ;
175
213
176
- expect ( modeBar . hasButtons ( buttons ) ) . toBe ( true ) ;
177
- expect ( countGroups ( modeBar ) ) . toEqual ( 5 ) ;
178
- expect ( countButtons ( modeBar ) ) . toEqual ( 13 ) ;
179
- expect ( countLogo ( modeBar ) ) . toEqual ( 1 ) ;
214
+ checkButtons ( modeBar , buttons , 1 ) ;
180
215
} ) ;
181
216
182
217
it ( 'creates mode bar (cartesian fixed-axes version)' , function ( ) {
183
218
var buttons = getButtons ( [
184
219
[ 'toImage' , 'sendDataToCloud' ] ,
185
- [ 'select2d' , 'lasso2d' ] ,
186
220
[ 'hoverClosestCartesian' , 'hoverCompareCartesian' ]
187
221
] ) ;
188
222
@@ -192,10 +226,7 @@ describe('ModeBar', function() {
192
226
manageModeBar ( gd ) ;
193
227
var modeBar = gd . _fullLayout . _modeBar ;
194
228
195
- expect ( modeBar . hasButtons ( buttons ) ) . toBe ( true ) ;
196
- expect ( countGroups ( modeBar ) ) . toEqual ( 4 ) ;
197
- expect ( countButtons ( modeBar ) ) . toEqual ( 7 ) ;
198
- expect ( countLogo ( modeBar ) ) . toEqual ( 1 ) ;
229
+ checkButtons ( modeBar , buttons , 1 ) ;
199
230
} ) ;
200
231
201
232
it ( 'creates mode bar (gl3d version)' , function ( ) {
@@ -212,10 +243,7 @@ describe('ModeBar', function() {
212
243
manageModeBar ( gd ) ;
213
244
var modeBar = gd . _fullLayout . _modeBar ;
214
245
215
- expect ( modeBar . hasButtons ( buttons ) ) . toBe ( true ) ;
216
- expect ( countGroups ( modeBar ) ) . toEqual ( 5 ) ;
217
- expect ( countButtons ( modeBar ) ) . toEqual ( 10 ) ;
218
- expect ( countLogo ( modeBar ) ) . toEqual ( 1 ) ;
246
+ checkButtons ( modeBar , buttons , 1 ) ;
219
247
} ) ;
220
248
221
249
it ( 'creates mode bar (geo version)' , function ( ) {
@@ -231,10 +259,7 @@ describe('ModeBar', function() {
231
259
manageModeBar ( gd ) ;
232
260
var modeBar = gd . _fullLayout . _modeBar ;
233
261
234
- expect ( modeBar . hasButtons ( buttons ) ) . toBe ( true ) ;
235
- expect ( countGroups ( modeBar ) ) . toEqual ( 4 ) ;
236
- expect ( countButtons ( modeBar ) ) . toEqual ( 7 ) ;
237
- expect ( countLogo ( modeBar ) ) . toEqual ( 1 ) ;
262
+ checkButtons ( modeBar , buttons , 1 ) ;
238
263
} ) ;
239
264
240
265
it ( 'creates mode bar (gl2d version)' , function ( ) {
@@ -252,10 +277,7 @@ describe('ModeBar', function() {
252
277
manageModeBar ( gd ) ;
253
278
var modeBar = gd . _fullLayout . _modeBar ;
254
279
255
- expect ( modeBar . hasButtons ( buttons ) ) . toBe ( true ) ;
256
- expect ( countGroups ( modeBar ) ) . toEqual ( 5 ) ;
257
- expect ( countButtons ( modeBar ) ) . toEqual ( 10 ) ;
258
- expect ( countLogo ( modeBar ) ) . toEqual ( 1 ) ;
280
+ checkButtons ( modeBar , buttons , 1 ) ;
259
281
} ) ;
260
282
261
283
it ( 'creates mode bar (pie version)' , function ( ) {
@@ -270,10 +292,7 @@ describe('ModeBar', function() {
270
292
manageModeBar ( gd ) ;
271
293
var modeBar = gd . _fullLayout . _modeBar ;
272
294
273
- expect ( modeBar . hasButtons ( buttons ) ) . toBe ( true ) ;
274
- expect ( countGroups ( modeBar ) ) . toEqual ( 3 ) ;
275
- expect ( countButtons ( modeBar ) ) . toEqual ( 4 ) ;
276
- expect ( countLogo ( modeBar ) ) . toEqual ( 1 ) ;
295
+ checkButtons ( modeBar , buttons , 1 ) ;
277
296
} ) ;
278
297
279
298
it ( 'throws an error if modeBarButtonsToRemove isn\'t an array' , function ( ) {
@@ -382,7 +401,7 @@ describe('ModeBar', function() {
382
401
383
402
var modeBar = gd . _fullLayout . _modeBar ;
384
403
expect ( countGroups ( modeBar ) ) . toEqual ( 6 ) ;
385
- expect ( countButtons ( modeBar ) ) . toEqual ( 12 ) ;
404
+ expect ( countButtons ( modeBar ) ) . toEqual ( 10 ) ;
386
405
} ) ;
387
406
388
407
it ( 'sets up buttons with modeBarButtonsToAdd and modeBarButtonToRemove (2)' , function ( ) {
@@ -402,7 +421,7 @@ describe('ModeBar', function() {
402
421
403
422
var modeBar = gd . _fullLayout . _modeBar ;
404
423
expect ( countGroups ( modeBar ) ) . toEqual ( 7 ) ;
405
- expect ( countButtons ( modeBar ) ) . toEqual ( 14 ) ;
424
+ expect ( countButtons ( modeBar ) ) . toEqual ( 12 ) ;
406
425
} ) ;
407
426
408
427
it ( 'sets up buttons with fully custom modeBarButtons' , function ( ) {
0 commit comments