@@ -7,6 +7,8 @@ var manageModebar = require('@src/components/modebar/manage');
7
7
describe ( 'Modebar' , function ( ) {
8
8
'use strict' ;
9
9
10
+ function noop ( ) { } ;
11
+
10
12
function getMockContainerTree ( ) {
11
13
var root = document . createElement ( 'div' ) ;
12
14
root . className = 'plot-container' ;
@@ -44,7 +46,14 @@ describe('Modebar', function() {
44
46
}
45
47
46
48
47
- var buttons = [ [ 'toImage' , 'sendDataToCloud' ] ] ;
49
+ var buttons = [ [ {
50
+ name : 'button 1' ,
51
+ click : noop
52
+ } , {
53
+ name : 'button 2' ,
54
+ click : noop
55
+ } ] ] ;
56
+
48
57
var modebar = createModebar ( getMockGraphInfo ( ) , buttons ) ;
49
58
50
59
describe ( 'createModebar' , function ( ) {
@@ -53,6 +62,32 @@ describe('Modebar', function() {
53
62
expect ( countButtons ( modebar ) ) . toEqual ( 3 ) ;
54
63
expect ( countLogo ( modebar ) ) . toEqual ( 1 ) ;
55
64
} ) ;
65
+
66
+ it ( 'throws when button config does not have name' , function ( ) {
67
+ expect ( function ( ) {
68
+ createModebar ( getMockGraphInfo ( ) , [ [
69
+ { click : function ( ) { console . log ( 'not gonna work' ) ; } }
70
+ ] ] ) ;
71
+ } ) . toThrowError ( ) ;
72
+ } ) ;
73
+
74
+ it ( 'throws when button name is not unique' , function ( ) {
75
+ expect ( function ( ) {
76
+ createModebar ( getMockGraphInfo ( ) , [ [
77
+ { name : 'A' , click : function ( ) { console . log ( 'not gonna' ) ; } } ,
78
+ { name : 'A' , click : function ( ) { console . log ( '... work' ) ; } }
79
+ ] ] ) ;
80
+ } ) . toThrowError ( ) ;
81
+ } ) ;
82
+
83
+ it ( 'throws when button config does not have a click handler' , function ( ) {
84
+ expect ( function ( ) {
85
+ createModebar ( getMockGraphInfo ( ) , [ [
86
+ { name : 'not gonna work' }
87
+ ] ] ) ;
88
+ } ) . toThrowError ( ) ;
89
+ } ) ;
90
+
56
91
} ) ;
57
92
58
93
describe ( 'modebar.removeAllButtons' , function ( ) {
@@ -76,13 +111,25 @@ describe('Modebar', function() {
76
111
77
112
describe ( 'manageModebar' , function ( ) {
78
113
114
+ function getButtons ( list ) {
115
+ for ( var i = 0 ; i < list . length ; i ++ ) {
116
+ for ( var j = 0 ; j < list [ i ] . length ; j ++ ) {
117
+ list [ i ] [ j ] = {
118
+ name : list [ i ] [ j ] ,
119
+ click : noop
120
+ } ;
121
+ }
122
+ }
123
+ return list ;
124
+ }
125
+
79
126
it ( 'creates modebar (cartesian version)' , function ( ) {
80
- var buttons = [
127
+ var buttons = getButtons ( [
81
128
[ 'toImage' , 'sendDataToCloud' ] ,
82
129
[ 'zoom2d' , 'pan2d' ] ,
83
130
[ 'zoomIn2d' , 'zoomOut2d' , 'autoScale2d' , 'resetScale2d' ] ,
84
- [ 'hoverClosest2d ' , 'hoverCompare2d ' ]
85
- ] ;
131
+ [ 'hoverClosestCartesian ' , 'hoverCompareCartesian ' ]
132
+ ] ) ;
86
133
87
134
var gd = getMockGraphInfo ( ) ;
88
135
gd . _fullLayout . _hasCartesian = true ;
@@ -98,10 +145,10 @@ describe('Modebar', function() {
98
145
} ) ;
99
146
100
147
it ( 'creates modebar (cartesian fixed-axes version)' , function ( ) {
101
- var buttons = [
148
+ var buttons = getButtons ( [
102
149
[ 'toImage' , 'sendDataToCloud' ] ,
103
- [ 'hoverClosest2d ' , 'hoverCompare2d ' ]
104
- ] ;
150
+ [ 'hoverClosestCartesian ' , 'hoverCompareCartesian ' ]
151
+ ] ) ;
105
152
106
153
var gd = getMockGraphInfo ( ) ;
107
154
gd . _fullLayout . _hasCartesian = true ;
@@ -116,12 +163,12 @@ describe('Modebar', function() {
116
163
} ) ;
117
164
118
165
it ( 'creates modebar (gl3d version)' , function ( ) {
119
- var buttons = [
166
+ var buttons = getButtons ( [
120
167
[ 'toImage' , 'sendDataToCloud' ] ,
121
168
[ 'zoom3d' , 'pan3d' , 'orbitRotation' , 'tableRotation' ] ,
122
169
[ 'resetCameraDefault3d' , 'resetCameraLastSave3d' ] ,
123
170
[ 'hoverClosest3d' ]
124
- ] ;
171
+ ] ) ;
125
172
126
173
var gd = getMockGraphInfo ( ) ;
127
174
gd . _fullLayout . _hasGL3D = true ;
@@ -136,11 +183,11 @@ describe('Modebar', function() {
136
183
} ) ;
137
184
138
185
it ( 'creates modebar (geo version)' , function ( ) {
139
- var buttons = [
186
+ var buttons = getButtons ( [
140
187
[ 'toImage' , 'sendDataToCloud' ] ,
141
188
[ 'zoomInGeo' , 'zoomOutGeo' , 'resetGeo' ] ,
142
189
[ 'hoverClosestGeo' ]
143
- ] ;
190
+ ] ) ;
144
191
145
192
var gd = getMockGraphInfo ( ) ;
146
193
gd . _fullLayout . _hasGeo = true ;
@@ -155,15 +202,16 @@ describe('Modebar', function() {
155
202
} ) ;
156
203
157
204
it ( 'creates modebar (gl2d version)' , function ( ) {
158
- var buttons = [
205
+ var buttons = getButtons ( [
159
206
[ 'toImage' , 'sendDataToCloud' ] ,
160
207
[ 'zoom2d' , 'pan2d' ] ,
161
208
[ 'zoomIn2d' , 'zoomOut2d' , 'autoScale2d' , 'resetScale2d' ] ,
162
209
[ 'hoverClosestGl2d' ]
163
- ] ;
210
+ ] ) ;
164
211
165
212
var gd = getMockGraphInfo ( ) ;
166
213
gd . _fullLayout . _hasGL2D = true ;
214
+ gd . _fullLayout . xaxis = { fixedrange : false } ;
167
215
168
216
manageModebar ( gd ) ;
169
217
var modebar = gd . _fullLayout . _modebar ;
@@ -175,10 +223,10 @@ describe('Modebar', function() {
175
223
} ) ;
176
224
177
225
it ( 'creates modebar (pie version)' , function ( ) {
178
- var buttons = [
226
+ var buttons = getButtons ( [
179
227
[ 'toImage' , 'sendDataToCloud' ] ,
180
228
[ 'hoverClosestPie' ]
181
- ] ;
229
+ ] ) ;
182
230
183
231
var gd = getMockGraphInfo ( ) ;
184
232
gd . _fullLayout . _hasPie = true ;
0 commit comments