Skip to content

Commit 6e53762

Browse files
committed
Update tests to require trace modules directly
1 parent 2ac3605 commit 6e53762

7 files changed

+67
-63
lines changed

test/jasmine/tests/choropleth_test.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
var Plotly = require('@src/plotly');
2+
var Choropleth = require('@src/traces/choropleth');
23

34

45
describe('Test choropleth', function() {
56
'use strict';
67

7-
var Choropleth = Plotly.Choropleth;
8-
98
describe('supplyDefaults', function() {
109
var traceIn,
1110
traceOut;

test/jasmine/tests/colorscale_test.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
var Plotly = require('@src/plotly');
22
var Colorscale = require('@src/components/colorscale');
3+
var Heatmap = require('@src/traces/heatmap');
4+
var Scatter = require('@src/traces/scatter');
35

46

57
describe('Test colorscale:', function() {
@@ -191,7 +193,7 @@ describe('Test colorscale:', function() {
191193
var traceIn, traceOut;
192194

193195
function coerce(attr, dflt) {
194-
return Plotly.Lib.coerce(traceIn, traceOut, Plotly.Heatmap.attributes, attr, dflt);
196+
return Plotly.Lib.coerce(traceIn, traceOut, Heatmap.attributes, attr, dflt);
195197
}
196198

197199
beforeEach(function() {
@@ -261,7 +263,7 @@ describe('Test colorscale:', function() {
261263
var traceIn, traceOut;
262264

263265
function coerce(attr, dflt) {
264-
return Plotly.Lib.coerce(traceIn, traceOut, Plotly.Scatter.attributes, attr, dflt);
266+
return Plotly.Lib.coerce(traceIn, traceOut, Scatter.attributes, attr, dflt);
265267
}
266268

267269
beforeEach(function() {

test/jasmine/tests/contour_test.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
var Plotly = require('@src/plotly');
1+
var Plots = require('@src/plots/plots');
2+
var Contour = require('@src/traces/contour');
23

34

45
describe('Test contour', function() {
@@ -10,10 +11,10 @@ describe('Test contour', function() {
1011

1112
var defaultColor = '#444',
1213
layout = {
13-
font: Plotly.Plots.layoutAttributes.font
14+
font: Plots.layoutAttributes.font
1415
};
1516

16-
var supplyDefaults = Plotly.Contour.supplyDefaults;
17+
var supplyDefaults = Contour.supplyDefaults;
1718

1819
beforeEach(function() {
1920
traceOut = {};

test/jasmine/tests/heatmap_test.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
var Plotly = require('@src/plotly');
2-
var Heatmap = require('@src/traces/heatmap');
31
var convertColumnXYZ = require('@src/traces/heatmap/convert_column_xyz');
2+
var Heatmap = require('@src/traces/heatmap');
3+
var Plots = require('@src/plots/plots');
44

55

66
describe('Test heatmap', function() {
@@ -12,7 +12,7 @@ describe('Test heatmap', function() {
1212

1313
var defaultColor = '#444',
1414
layout = {
15-
font: Plotly.Plots.layoutAttributes.font
15+
font: Plots.layoutAttributes.font
1616
};
1717

1818
var supplyDefaults = Heatmap.supplyDefaults;
@@ -44,13 +44,13 @@ describe('Test heatmap', function() {
4444
type: 'heatmap',
4545
z: [[1, 2], []]
4646
};
47-
traceOut = Plotly.Plots.supplyDataDefaults(traceIn, 0, layout);
47+
traceOut = Plots.supplyDataDefaults(traceIn, 0, layout);
4848

4949
traceIn = {
5050
type: 'heatmap',
5151
z: [[], [1, 2], [1, 2, 3]]
5252
};
53-
traceOut = Plotly.Plots.supplyDataDefaults(traceIn, 0, layout);
53+
traceOut = Plots.supplyDataDefaults(traceIn, 0, layout);
5454
expect(traceOut.visible).toBe(true);
5555
expect(traceOut.visible).toBe(true);
5656
});

test/jasmine/tests/plot_api_test.js

+16-12
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,24 @@
11
var Plotly = require('@src/plotly');
2+
var Plots = require('@src/plots/plots');
3+
var Scatter = require('@src/traces/scatter');
4+
var Bar = require('@src/traces/bar');
5+
var Legend = require('@src/components/legend');
26

37
describe('Test graph_obj', function() {
48
'use strict';
59

610
describe('Plotly.restyle', function() {
711
beforeEach(function() {
8-
spyOn(Plotly.Plots, 'previousPromises');
912
spyOn(Plotly, 'plot');
10-
spyOn(Plotly.Scatter, 'arraysToCalcdata');
11-
spyOn(Plotly.Bar, 'arraysToCalcdata');
12-
spyOn(Plotly.Plots, 'style');
13-
spyOn(Plotly.Legend, 'draw');
13+
spyOn(Plots, 'previousPromises');
14+
spyOn(Scatter, 'arraysToCalcdata');
15+
spyOn(Bar, 'arraysToCalcdata');
16+
spyOn(Plots, 'style');
17+
spyOn(Legend, 'draw');
1418
});
1519

1620
function mockDefaultsAndCalc(gd) {
17-
Plotly.Plots.supplyDefaults(gd);
21+
Plots.supplyDefaults(gd);
1822
gd.calcdata = gd._fullData.map(function(trace) {
1923
return [{x: 1, y: 1, trace: trace}];
2024
});
@@ -27,9 +31,9 @@ describe('Test graph_obj', function() {
2731
};
2832
mockDefaultsAndCalc(gd);
2933
Plotly.restyle(gd, {'marker.color': 'red'});
30-
expect(Plotly.Scatter.arraysToCalcdata).toHaveBeenCalled();
31-
expect(Plotly.Bar.arraysToCalcdata).not.toHaveBeenCalled();
32-
expect(Plotly.Plots.style).toHaveBeenCalled();
34+
expect(Scatter.arraysToCalcdata).toHaveBeenCalled();
35+
expect(Bar.arraysToCalcdata).not.toHaveBeenCalled();
36+
expect(Plots.style).toHaveBeenCalled();
3337
expect(Plotly.plot).not.toHaveBeenCalled();
3438
// "docalc" deletes gd.calcdata - make sure this didn't happen
3539
expect(gd.calcdata).toBeDefined();
@@ -42,9 +46,9 @@ describe('Test graph_obj', function() {
4246
};
4347
mockDefaultsAndCalc(gd);
4448
Plotly.restyle(gd, {'marker.color': 'red'});
45-
expect(Plotly.Scatter.arraysToCalcdata).not.toHaveBeenCalled();
46-
expect(Plotly.Bar.arraysToCalcdata).toHaveBeenCalled();
47-
expect(Plotly.Plots.style).toHaveBeenCalled();
49+
expect(Scatter.arraysToCalcdata).not.toHaveBeenCalled();
50+
expect(Bar.arraysToCalcdata).toHaveBeenCalled();
51+
expect(Plots.style).toHaveBeenCalled();
4852
expect(Plotly.plot).not.toHaveBeenCalled();
4953
expect(gd.calcdata).toBeDefined();
5054
});

test/jasmine/tests/plots_test.js

+36-36
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
var Plotly = require('@src/plotly');
2+
var Plots = require('@src/plots/plots');
23
var createGraphDiv = require('../assets/create_graph_div');
34
var destroyGraphDiv = require('../assets/destroy_graph_div');
45

56

6-
describe('Test Plotly.Plots', function() {
7+
8+
describe('Test Plots', function() {
79
'use strict';
810

9-
describe('Plotly.Plots.supplyLayoutGlobalDefaults should', function() {
11+
describe('Plots.supplyLayoutGlobalDefaults should', function() {
1012
var layoutIn,
1113
layoutOut,
1214
expected;
1315

14-
var supplyLayoutDefaults = Plotly.Plots.supplyLayoutGlobalDefaults;
16+
var supplyLayoutDefaults = Plots.supplyLayoutGlobalDefaults;
1517

1618
beforeEach(function() {
1719
layoutOut = {};
@@ -65,8 +67,8 @@ describe('Test Plotly.Plots', function() {
6567

6668
});
6769

68-
describe('Plotly.Plots.supplyDataDefaults', function() {
69-
var supplyDataDefaults = Plotly.Plots.supplyDataDefaults,
70+
describe('Plots.supplyDataDefaults', function() {
71+
var supplyDataDefaults = Plots.supplyDataDefaults,
7072
layout = {};
7173

7274
var traceIn, traceOut;
@@ -98,8 +100,8 @@ describe('Test Plotly.Plots', function() {
98100
});
99101
});
100102

101-
describe('Plotly.Plots.getSubplotIds', function() {
102-
var getSubplotIds = Plotly.Plots.getSubplotIds;
103+
describe('Plots.getSubplotIds', function() {
104+
var getSubplotIds = Plots.getSubplotIds;
103105
var layout;
104106

105107
it('returns scene ids', function() {
@@ -143,8 +145,8 @@ describe('Test Plotly.Plots', function() {
143145
});
144146
});
145147

146-
describe('Plotly.Plots.getSubplotIdsInData', function() {
147-
var getSubplotIdsInData = Plotly.Plots.getSubplotIdsInData;
148+
describe('Plots.getSubplotIdsInData', function() {
149+
var getSubplotIdsInData = Plots.getSubplotIdsInData;
148150

149151
var ids, data;
150152

@@ -173,11 +175,11 @@ describe('Test Plotly.Plots', function() {
173175

174176
});
175177

176-
describe('Plotly.Plots.register, getModule, and traceIs', function() {
178+
describe('Plots.register, getModule, and traceIs', function() {
177179
beforeEach(function() {
178-
this.modulesKeys = Object.keys(Plotly.Plots.modules);
179-
this.allTypesKeys = Object.keys(Plotly.Plots.allTypes);
180-
this.allCategoriesKeys = Object.keys(Plotly.Plots.allCategories);
180+
this.modulesKeys = Object.keys(Plots.modules);
181+
this.allTypesKeys = Object.keys(Plots.allTypes);
182+
this.allCategoriesKeys = Object.keys(Plots.allCategories);
181183

182184
this.fakeModule = {
183185
calc: function() { return 42; },
@@ -187,7 +189,7 @@ describe('Test Plotly.Plots', function() {
187189
plot: function() { throw new Error('nope!'); }
188190
};
189191

190-
Plotly.Plots.register(this.fakeModule, 'newtype', ['red', 'green']);
192+
Plots.register(this.fakeModule, 'newtype', ['red', 'green']);
191193

192194
spyOn(console, 'warn');
193195
});
@@ -199,52 +201,50 @@ describe('Test Plotly.Plots', function() {
199201
});
200202
}
201203

202-
revertObj(Plotly.Plots.modules, this.modulesKeys);
203-
revertObj(Plotly.Plots.allTypes, this.allTypesKeys);
204-
revertObj(Plotly.Plots.allCategories, this.allCategoriesKeys);
204+
revertObj(Plots.modules, this.modulesKeys);
205+
revertObj(Plots.allTypes, this.allTypesKeys);
206+
revertObj(Plots.allCategories, this.allCategoriesKeys);
205207
});
206208

207-
it('should error on attempts to reregister a type', function() {
208-
var fm2 = this.fakeModule2;
209-
expect(function() { Plotly.Plots.register(fm2, 'newtype', ['yellow', 'blue']); })
210-
.toThrow(new Error('type newtype already registered'));
211-
expect(Plotly.Plots.allCategories.yellow).toBeUndefined();
209+
it('should warn on attempts to reregister a type', function() {
210+
Plots.register(this.fakeModule2, 'newtype', ['yellow', 'blue']);
211+
expect(Plots.allCategories.yellow).toBeUndefined();
212212
});
213213

214214
it('should find the module for a type', function() {
215-
expect(Plotly.Plots.getModule('newtype')).toBe(this.fakeModule);
216-
expect(Plotly.Plots.getModule({type: 'newtype'})).toBe(this.fakeModule);
215+
expect(Plots.getModule('newtype')).toBe(this.fakeModule);
216+
expect(Plots.getModule({type: 'newtype'})).toBe(this.fakeModule);
217217
});
218218

219219
it('should return false for types it doesn\'t know', function() {
220-
expect(Plotly.Plots.getModule('notatype')).toBe(false);
221-
expect(Plotly.Plots.getModule({type: 'notatype'})).toBe(false);
222-
expect(Plotly.Plots.getModule({type: 'newtype', r: 'this is polar'})).toBe(false);
220+
expect(Plots.getModule('notatype')).toBe(false);
221+
expect(Plots.getModule({type: 'notatype'})).toBe(false);
222+
expect(Plots.getModule({type: 'newtype', r: 'this is polar'})).toBe(false);
223223
});
224224

225225
it('should find the categories for this type', function() {
226-
expect(Plotly.Plots.traceIs('newtype', 'red')).toBe(true);
227-
expect(Plotly.Plots.traceIs({type: 'newtype'}, 'red')).toBe(true);
226+
expect(Plots.traceIs('newtype', 'red')).toBe(true);
227+
expect(Plots.traceIs({type: 'newtype'}, 'red')).toBe(true);
228228
});
229229

230230
it('should not find other real categories', function() {
231-
expect(Plotly.Plots.traceIs('newtype', 'cartesian')).toBe(false);
232-
expect(Plotly.Plots.traceIs({type: 'newtype'}, 'cartesian')).toBe(false);
231+
expect(Plots.traceIs('newtype', 'cartesian')).toBe(false);
232+
expect(Plots.traceIs({type: 'newtype'}, 'cartesian')).toBe(false);
233233
expect(console.warn).not.toHaveBeenCalled();
234234
});
235235
});
236236

237-
describe('Plotly.Plots.registerSubplot', function() {
237+
describe('Plots.registerSubplot', function() {
238238
var fake = {
239239
name: 'fake',
240240
attr: 'abc',
241241
idRoot: 'cba',
242242
attributes: { stuff: { 'more stuff': 102102 } }
243243
};
244244

245-
Plotly.Plots.registerSubplot(fake);
245+
Plots.registerSubplot(fake);
246246

247-
var subplotsRegistry = Plotly.Plots.subplotsRegistry;
247+
var subplotsRegistry = Plots.subplotsRegistry;
248248

249249
it('should register attr, idRoot and attributes', function() {
250250
expect(subplotsRegistry.fake.attr).toEqual('abc');
@@ -307,7 +307,7 @@ describe('Test Plotly.Plots', function() {
307307

308308
});
309309

310-
describe('Plotly.Plots.purge', function() {
310+
describe('Plots.purge', function() {
311311
var gd;
312312

313313
beforeEach(function(done) {
@@ -324,7 +324,7 @@ describe('Test Plotly.Plots', function() {
324324
'_hmpixcount', '_hmlumcount'
325325
];
326326

327-
Plotly.Plots.purge(gd);
327+
Plots.purge(gd);
328328
expect(Object.keys(gd)).toEqual(expectedKeys);
329329
expect(gd.data).toBeUndefined();
330330
expect(gd.layout).toBeUndefined();

test/jasmine/tests/scattergeo_test.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
var Plotly = require('@src/plotly');
1+
var ScatterGeo = require('@src/traces/scattergeo');
22

33
describe('Test scattergeo', function() {
44
'use strict';
55

6-
var ScatterGeo = Plotly.ScatterGeo;
7-
86
describe('supplyDefaults', function() {
97
var traceIn,
108
traceOut;

0 commit comments

Comments
 (0)