Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 543fe14

Browse files
committed
update modebar tests
1 parent 933603c commit 543fe14

File tree

1 file changed

+63
-15
lines changed

1 file changed

+63
-15
lines changed

test/jasmine/tests/modebar_test.js

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var manageModebar = require('@src/components/modebar/manage');
77
describe('Modebar', function() {
88
'use strict';
99

10+
function noop() {};
11+
1012
function getMockContainerTree() {
1113
var root = document.createElement('div');
1214
root.className = 'plot-container';
@@ -44,7 +46,14 @@ describe('Modebar', function() {
4446
}
4547

4648

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+
4857
var modebar = createModebar(getMockGraphInfo(), buttons);
4958

5059
describe('createModebar', function() {
@@ -53,6 +62,32 @@ describe('Modebar', function() {
5362
expect(countButtons(modebar)).toEqual(3);
5463
expect(countLogo(modebar)).toEqual(1);
5564
});
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+
5691
});
5792

5893
describe('modebar.removeAllButtons', function() {
@@ -76,13 +111,25 @@ describe('Modebar', function() {
76111

77112
describe('manageModebar', function() {
78113

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+
79126
it('creates modebar (cartesian version)', function() {
80-
var buttons = [
127+
var buttons = getButtons([
81128
['toImage', 'sendDataToCloud'],
82129
['zoom2d', 'pan2d'],
83130
['zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d'],
84-
['hoverClosest2d', 'hoverCompare2d']
85-
];
131+
['hoverClosestCartesian', 'hoverCompareCartesian']
132+
]);
86133

87134
var gd = getMockGraphInfo();
88135
gd._fullLayout._hasCartesian = true;
@@ -98,10 +145,10 @@ describe('Modebar', function() {
98145
});
99146

100147
it('creates modebar (cartesian fixed-axes version)', function() {
101-
var buttons = [
148+
var buttons = getButtons([
102149
['toImage', 'sendDataToCloud'],
103-
['hoverClosest2d', 'hoverCompare2d']
104-
];
150+
['hoverClosestCartesian', 'hoverCompareCartesian']
151+
]);
105152

106153
var gd = getMockGraphInfo();
107154
gd._fullLayout._hasCartesian = true;
@@ -116,12 +163,12 @@ describe('Modebar', function() {
116163
});
117164

118165
it('creates modebar (gl3d version)', function() {
119-
var buttons = [
166+
var buttons = getButtons([
120167
['toImage', 'sendDataToCloud'],
121168
['zoom3d', 'pan3d', 'orbitRotation', 'tableRotation'],
122169
['resetCameraDefault3d', 'resetCameraLastSave3d'],
123170
['hoverClosest3d']
124-
];
171+
]);
125172

126173
var gd = getMockGraphInfo();
127174
gd._fullLayout._hasGL3D = true;
@@ -136,11 +183,11 @@ describe('Modebar', function() {
136183
});
137184

138185
it('creates modebar (geo version)', function() {
139-
var buttons = [
186+
var buttons = getButtons([
140187
['toImage', 'sendDataToCloud'],
141188
['zoomInGeo', 'zoomOutGeo', 'resetGeo'],
142189
['hoverClosestGeo']
143-
];
190+
]);
144191

145192
var gd = getMockGraphInfo();
146193
gd._fullLayout._hasGeo = true;
@@ -155,15 +202,16 @@ describe('Modebar', function() {
155202
});
156203

157204
it('creates modebar (gl2d version)', function() {
158-
var buttons = [
205+
var buttons = getButtons([
159206
['toImage', 'sendDataToCloud'],
160207
['zoom2d', 'pan2d'],
161208
['zoomIn2d', 'zoomOut2d', 'autoScale2d', 'resetScale2d'],
162209
['hoverClosestGl2d']
163-
];
210+
]);
164211

165212
var gd = getMockGraphInfo();
166213
gd._fullLayout._hasGL2D = true;
214+
gd._fullLayout.xaxis = {fixedrange: false};
167215

168216
manageModebar(gd);
169217
var modebar = gd._fullLayout._modebar;
@@ -175,10 +223,10 @@ describe('Modebar', function() {
175223
});
176224

177225
it('creates modebar (pie version)', function() {
178-
var buttons = [
226+
var buttons = getButtons([
179227
['toImage', 'sendDataToCloud'],
180228
['hoverClosestPie']
181-
];
229+
]);
182230

183231
var gd = getMockGraphInfo();
184232
gd._fullLayout._hasPie = true;

0 commit comments

Comments
 (0)