@@ -25,6 +25,7 @@ describe('ModeBar', function() {
2525 dragmode : 'zoom' ,
2626 _paperdiv : d3 . select ( getMockContainerTree ( ) )
2727 } ,
28+ _fullData : [ ] ,
2829 _context : {
2930 displaylogo : true ,
3031 displayModeBar : true ,
@@ -158,7 +159,38 @@ describe('ModeBar', function() {
158159 return list ;
159160 }
160161
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 ( ) {
162194 var buttons = getButtons ( [
163195 [ 'toImage' , 'sendDataToCloud' ] ,
164196 [ 'zoom2d' , 'pan2d' , 'select2d' , 'lasso2d' ] ,
@@ -169,20 +201,22 @@ describe('ModeBar', function() {
169201 var gd = getMockGraphInfo ( ) ;
170202 gd . _fullLayout . _hasCartesian = true ;
171203 gd . _fullLayout . xaxis = { fixedrange : false } ;
204+ gd . _fullData = [ {
205+ type :'scatter' ,
206+ visible : true ,
207+ mode :'markers' ,
208+ _module : { selectPoints : true }
209+ } ] ;
172210
173211 manageModeBar ( gd ) ;
174212 var modeBar = gd . _fullLayout . _modeBar ;
175213
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 ) ;
180215 } ) ;
181216
182217 it ( 'creates mode bar (cartesian fixed-axes version)' , function ( ) {
183218 var buttons = getButtons ( [
184219 [ 'toImage' , 'sendDataToCloud' ] ,
185- [ 'select2d' , 'lasso2d' ] ,
186220 [ 'hoverClosestCartesian' , 'hoverCompareCartesian' ]
187221 ] ) ;
188222
@@ -192,10 +226,7 @@ describe('ModeBar', function() {
192226 manageModeBar ( gd ) ;
193227 var modeBar = gd . _fullLayout . _modeBar ;
194228
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 ) ;
199230 } ) ;
200231
201232 it ( 'creates mode bar (gl3d version)' , function ( ) {
@@ -212,10 +243,7 @@ describe('ModeBar', function() {
212243 manageModeBar ( gd ) ;
213244 var modeBar = gd . _fullLayout . _modeBar ;
214245
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 ) ;
219247 } ) ;
220248
221249 it ( 'creates mode bar (geo version)' , function ( ) {
@@ -231,10 +259,7 @@ describe('ModeBar', function() {
231259 manageModeBar ( gd ) ;
232260 var modeBar = gd . _fullLayout . _modeBar ;
233261
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 ) ;
238263 } ) ;
239264
240265 it ( 'creates mode bar (gl2d version)' , function ( ) {
@@ -252,10 +277,7 @@ describe('ModeBar', function() {
252277 manageModeBar ( gd ) ;
253278 var modeBar = gd . _fullLayout . _modeBar ;
254279
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 ) ;
259281 } ) ;
260282
261283 it ( 'creates mode bar (pie version)' , function ( ) {
@@ -270,10 +292,7 @@ describe('ModeBar', function() {
270292 manageModeBar ( gd ) ;
271293 var modeBar = gd . _fullLayout . _modeBar ;
272294
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 ) ;
277296 } ) ;
278297
279298 it ( 'throws an error if modeBarButtonsToRemove isn\'t an array' , function ( ) {
@@ -382,7 +401,7 @@ describe('ModeBar', function() {
382401
383402 var modeBar = gd . _fullLayout . _modeBar ;
384403 expect ( countGroups ( modeBar ) ) . toEqual ( 6 ) ;
385- expect ( countButtons ( modeBar ) ) . toEqual ( 12 ) ;
404+ expect ( countButtons ( modeBar ) ) . toEqual ( 10 ) ;
386405 } ) ;
387406
388407 it ( 'sets up buttons with modeBarButtonsToAdd and modeBarButtonToRemove (2)' , function ( ) {
@@ -402,7 +421,7 @@ describe('ModeBar', function() {
402421
403422 var modeBar = gd . _fullLayout . _modeBar ;
404423 expect ( countGroups ( modeBar ) ) . toEqual ( 7 ) ;
405- expect ( countButtons ( modeBar ) ) . toEqual ( 14 ) ;
424+ expect ( countButtons ( modeBar ) ) . toEqual ( 12 ) ;
406425 } ) ;
407426
408427 it ( 'sets up buttons with fully custom modeBarButtons' , function ( ) {
0 commit comments