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

Skip to content

Commit d31006d

Browse files
committed
replace _has??? by mocking _has() and _basePlotModules
1 parent 2c81e35 commit d31006d

8 files changed

+64
-81
lines changed

test/jasmine/tests/axes_test.js

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,10 @@ describe('Test axes', function() {
171171
var layoutIn, layoutOut, fullData;
172172

173173
beforeEach(function() {
174-
layoutOut = {};
174+
layoutOut = {
175+
_has: Plots._hasPlotType,
176+
_basePlotModules: []
177+
};
175178
fullData = [];
176179
});
177180

@@ -267,7 +270,7 @@ describe('Test axes', function() {
267270
fullData = [];
268271

269272
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
270-
expect(layoutOut._hasCartesian).toBe(true);
273+
expect(layoutOut._basePlotModules[0].name).toEqual('cartesian');
271274
});
272275

273276
it('should detect orphan axes (gl2d trace conflict case)', function() {
@@ -282,7 +285,7 @@ describe('Test axes', function() {
282285
}];
283286

284287
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
285-
expect(layoutOut._hasCartesian).toBe(undefined);
288+
expect(layoutOut._basePlotModules).toEqual([]);
286289
});
287290

288291
it('should detect orphan axes (gl2d + cartesian case)', function() {
@@ -297,29 +300,29 @@ describe('Test axes', function() {
297300
}];
298301

299302
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
300-
expect(layoutOut._hasCartesian).toBe(true);
303+
expect(layoutOut._basePlotModules[0].name).toEqual('cartesian');
301304
});
302305

303306
it('should detect orphan axes (gl3d present case)', function() {
304307
layoutIn = {
305308
xaxis: {},
306309
yaxis: {}
307310
};
308-
layoutOut._hasGL3D = true;
311+
layoutOut._basePlotModules = [ { name: 'gl3d' }];
309312

310313
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
311-
expect(layoutOut._hasCartesian).toBe(undefined);
314+
expect(layoutOut._basePlotModules).toEqual([ { name: 'gl3d' }]);
312315
});
313316

314-
it('should detect orphan axes (gl3d present case)', function() {
317+
it('should detect orphan axes (geo present case)', function() {
315318
layoutIn = {
316319
xaxis: {},
317320
yaxis: {}
318321
};
319-
layoutOut._hasGeo = true;
322+
layoutOut._basePlotModules = [ { name: 'geo' }];
320323

321324
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
322-
expect(layoutOut._hasCartesian).toBe(undefined);
325+
expect(layoutOut._basePlotModules).toEqual([ { name: 'geo' }]);
323326
});
324327

325328
it('should use \'axis.color\' as default for \'axis.titlefont.color\'', function() {

test/jasmine/tests/fx_test.js

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
var Fx = require('@src/plots/cartesian/graph_interact');
2+
var Plots = require('@src/plots/plots');
23

34

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

78
describe('defaults', function() {
89

9-
it('should default (blank version)', function() {
10-
var layoutIn = {};
11-
var layoutOut = {};
12-
var fullData = [{}];
10+
var layoutIn, layoutOut, fullData;
11+
12+
beforeEach(function() {
13+
layoutIn = {};
14+
layoutOut = {
15+
_has: Plots._hasPlotType
16+
};
17+
fullData = [{}];
18+
})
1319

20+
21+
it('should default (blank version)', function() {
1422
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
1523
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest');
1624
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
1725
});
1826

1927
it('should default (cartesian version)', function() {
20-
var layoutIn = {};
21-
var layoutOut = {
22-
_hasCartesian: true
23-
};
24-
var fullData = [{}];
28+
layoutOut._basePlotModules = [{ name: 'cartesian' }];
2529

2630
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
2731
expect(layoutOut.hovermode).toBe('x', 'hovermode to x');
@@ -30,13 +34,8 @@ describe('Test FX', function() {
3034
});
3135

3236
it('should default (cartesian horizontal version)', function() {
33-
var layoutIn = {};
34-
var layoutOut = {
35-
_hasCartesian: true
36-
};
37-
var fullData = [{
38-
orientation: 'h'
39-
}];
37+
layoutOut._basePlotModules = [{ name: 'cartesian' }];
38+
fullData[0] = { orientation: 'h' };
4039

4140
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
4241
expect(layoutOut.hovermode).toBe('y', 'hovermode to y');
@@ -45,36 +44,23 @@ describe('Test FX', function() {
4544
});
4645

4746
it('should default (gl3d version)', function() {
48-
var layoutIn = {};
49-
var layoutOut = {
50-
_hasGL3D: true
51-
};
52-
var fullData = [{}];
47+
layoutOut._basePlotModules = [{ name: 'gl3d' }];
5348

5449
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
5550
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest');
5651
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
5752
});
5853

5954
it('should default (geo version)', function() {
60-
var layoutIn = {};
61-
var layoutOut = {
62-
_hasGeo: true
63-
};
64-
var fullData = [{}];
55+
layoutOut._basePlotModules = [{ name: 'geo' }];
6556

6657
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
6758
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest');
6859
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
6960
});
7061

7162
it('should default (multi plot type version)', function() {
72-
var layoutIn = {};
73-
var layoutOut = {
74-
_hasCartesian: true,
75-
_hasGL3D: true
76-
};
77-
var fullData = [{}];
63+
layoutOut._basePlotModules = [{ name: 'cartesian' }, { name: 'gl3d' }];
7864

7965
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
8066
expect(layoutOut.hovermode).toBe('x', 'hovermode to x');

test/jasmine/tests/geolayout_test.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ describe('Test Geo layout defaults', function() {
1111
var layoutIn, layoutOut, fullData;
1212

1313
beforeEach(function() {
14-
// if hasGeo is not at this stage, the default step is skipped
15-
layoutOut = { _hasGeo: true };
14+
layoutOut = {};
1615

1716
// needs a geo-ref in a trace in order to be detected
1817
fullData = [{ type: 'scattergeo', geo: 'geo' }];

test/jasmine/tests/gl3dlayout_test.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
var Gl3d = require('@src/plots/gl3d');
2+
var Plots = require('@src/plots/plots');
23

34
var tinycolor = require('tinycolor2');
45
var Color = require('@src/components/color');
@@ -13,8 +14,9 @@ describe('Test Gl3d layout defaults', function() {
1314
var supplyLayoutDefaults = Gl3d.supplyLayoutDefaults;
1415

1516
beforeEach(function() {
16-
// if hasGL3D is not at this stage, the default step is skipped
17-
layoutOut = { _hasGL3D: true };
17+
layoutOut = {
18+
_has: Plots._hasPlotType
19+
};
1820

1921
// needs a scene-ref in a trace in order to be detected
2022
fullData = [ { type: 'scatter3d', scene: 'scene' }];
@@ -173,7 +175,7 @@ describe('Test Gl3d layout defaults', function() {
173175
.toBe('orbit', 'to user layout val if valid and 3d only');
174176

175177
layoutIn = { scene: {}, dragmode: 'orbit' };
176-
layoutOut._hasCartesian = true;
178+
layoutOut._basePlotModules = [{ name: 'cartesian' }];
177179
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
178180
expect(layoutOut.scene.dragmode)
179181
.toBe('turntable', 'to default if not 3d only');
@@ -201,7 +203,7 @@ describe('Test Gl3d layout defaults', function() {
201203
.toBe(false, 'to user layout val if valid and 3d only');
202204

203205
layoutIn = { scene: {}, hovermode: false };
204-
layoutOut._hasCartesian = true;
206+
layoutOut._basePlotModules = [{ name: 'cartesian' }];
205207
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
206208
expect(layoutOut.scene.hovermode)
207209
.toBe('closest', 'to default if not 3d only');

test/jasmine/tests/gl_plot_interact_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,15 +159,15 @@ describe('Test gl plot interactions', function() {
159159
expect(gd.layout.scene).toEqual(sceneLayout);
160160
expect(gd.layout.xaxis).toBeUndefined();
161161
expect(gd.layout.yaxis).toBeUndefined();
162-
expect(gd._fullLayout._hasGL3D).toBe(true);
162+
expect(gd._fullLayout._has('gl3d')).toBe(true);
163163
expect(gd._fullLayout.scene._scene).toBeDefined();
164164

165165
Plotly.restyle(gd, 'type', 'scatter').then(function() {
166166
expect(countCanvases()).toEqual(0);
167167
expect(gd.layout.scene).toEqual(sceneLayout);
168168
expect(gd.layout.xaxis).toBeDefined();
169169
expect(gd.layout.yaxis).toBeDefined();
170-
expect(gd._fullLayout._hasGL3D).toBe(false);
170+
expect(gd._fullLayout._has('gl3d')).toBe(false);
171171
expect(gd._fullLayout.scene).toBeUndefined();
172172

173173
return Plotly.restyle(gd, 'type', 'scatter3d');
@@ -176,7 +176,7 @@ describe('Test gl plot interactions', function() {
176176
expect(gd.layout.scene).toEqual(sceneLayout);
177177
expect(gd.layout.xaxis).toBeDefined();
178178
expect(gd.layout.yaxis).toBeDefined();
179-
expect(gd._fullLayout._hasGL3D).toBe(true);
179+
expect(gd._fullLayout._has('gl3d')).toBe(true);
180180
expect(gd._fullLayout.scene._scene).toBeDefined();
181181

182182
done();
@@ -186,7 +186,7 @@ describe('Test gl plot interactions', function() {
186186
it('should be able to delete the last trace', function(done) {
187187
Plotly.deleteTraces(gd, [0]).then(function() {
188188
expect(countCanvases()).toEqual(0);
189-
expect(gd._fullLayout._hasGL3D).toBe(false);
189+
expect(gd._fullLayout._has('gl3d')).toBe(false);
190190
expect(gd._fullLayout.scene).toBeUndefined();
191191

192192
done();

0 commit comments

Comments
 (0)