Skip to content

Commit 74e7e33

Browse files
committed
add fx and gl3d defaults tests
1 parent 91ce34f commit 74e7e33

File tree

2 files changed

+147
-13
lines changed

2 files changed

+147
-13
lines changed

test/jasmine/tests/fx_test.js

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
var Fx = require('@src/plots/cartesian/graph_interact');
2+
3+
4+
describe('Test FX', function() {
5+
'use strict';
6+
7+
describe('defaults', function() {
8+
9+
it('should default (blank version)', function() {
10+
var layoutIn = {};
11+
var layoutOut = {};
12+
var fullData = [{}];
13+
14+
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
15+
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest');
16+
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
17+
});
18+
19+
it('should default (cartesian version)', function() {
20+
var layoutIn = {};
21+
var layoutOut = {
22+
_hasCartesian: true
23+
};
24+
var fullData = [{}];
25+
26+
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
27+
expect(layoutOut.hovermode).toBe('x', 'hovermode to x');
28+
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
29+
expect(layoutOut._isHoriz).toBe(false, 'isHoriz to false');
30+
});
31+
32+
it('should default (cartesian horizontal version)', function() {
33+
var layoutIn = {};
34+
var layoutOut = {
35+
_hasCartesian: true
36+
};
37+
var fullData = [{
38+
orientation: 'h'
39+
}];
40+
41+
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
42+
expect(layoutOut.hovermode).toBe('y', 'hovermode to y');
43+
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
44+
expect(layoutOut._isHoriz).toBe(true, 'isHoriz to true');
45+
});
46+
47+
it('should default (gl3d version)', function() {
48+
var layoutIn = {};
49+
var layoutOut = {
50+
_hasGL3D: true
51+
};
52+
var fullData = [{}];
53+
54+
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
55+
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest');
56+
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
57+
});
58+
59+
it('should default (geo version)', function() {
60+
var layoutIn = {};
61+
var layoutOut = {
62+
_hasGeo: true
63+
};
64+
var fullData = [{}];
65+
66+
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
67+
expect(layoutOut.hovermode).toBe('closest', 'hovermode to closest');
68+
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
69+
});
70+
71+
it('should default (multi plot type version)', function() {
72+
var layoutIn = {};
73+
var layoutOut = {
74+
_hasCartesian: true,
75+
_hasGL3D: true
76+
};
77+
var fullData = [{}];
78+
79+
Fx.supplyLayoutDefaults(layoutIn, layoutOut, fullData);
80+
expect(layoutOut.hovermode).toBe('x', 'hovermode to x');
81+
expect(layoutOut.dragmode).toBe('zoom', 'dragmode to zoom');
82+
});
83+
});
84+
});

test/jasmine/tests/gl3dlayout_test.js

Lines changed: 63 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
var Gl3d = require('@src/plots/gl3d');
22

33

4-
describe('Test Gl3d layout defaults', function() {
4+
fdescribe('Test Gl3d layout defaults', function() {
55
'use strict';
66

77
describe('supplyLayoutDefaults', function() {
8-
var layoutIn,
9-
layoutOut;
10-
118
var supplyLayoutDefaults = Gl3d.supplyLayoutDefaults;
9+
var layoutIn, layoutOut, fullData;
1210

1311
beforeEach(function() {
14-
layoutOut = {
15-
_hasGL3D: true
16-
};
12+
layoutOut = {_hasGL3D: true};
13+
fullData = [{scene: 'scene', type: 'scatter3d'}];
1714
});
1815

1916
it('should coerce aspectmode=ratio when ratio data is valid', function() {
@@ -39,7 +36,7 @@ describe('Test Gl3d layout defaults', function() {
3936
}
4037
};
4138

42-
supplyLayoutDefaults(layoutIn, layoutOut, [{scene: 'scene', type: 'scatter3d'}]);
39+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
4340
expect(layoutOut.scene.aspectmode).toBe(expected.scene.aspectmode);
4441
expect(layoutOut.scene.aspectratio).toEqual(expected.scene.aspectratio);
4542
expect(layoutOut.scene.bgcolor).toBe(expected.scene.bgcolor);
@@ -68,7 +65,7 @@ describe('Test Gl3d layout defaults', function() {
6865
}
6966
};
7067

71-
supplyLayoutDefaults(layoutIn, layoutOut, [{scene: 'scene', type: 'scatter3d'}]);
68+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
7269
expect(layoutOut.scene.aspectmode).toBe(expected.scene.aspectmode);
7370
expect(layoutOut.scene.aspectratio).toEqual(expected.scene.aspectratio);
7471
});
@@ -96,7 +93,7 @@ describe('Test Gl3d layout defaults', function() {
9693
}
9794
};
9895

99-
supplyLayoutDefaults(layoutIn, layoutOut, [{scene: 'scene', type: 'scatter3d'}]);
96+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
10097
expect(layoutOut.scene.aspectmode).toBe(expected.scene.aspectmode);
10198
expect(layoutOut.scene.aspectratio).toEqual(expected.scene.aspectratio);
10299
});
@@ -124,7 +121,7 @@ describe('Test Gl3d layout defaults', function() {
124121
}
125122
};
126123

127-
supplyLayoutDefaults(layoutIn, layoutOut, [{scene: 'scene', type: 'scatter3d'}]);
124+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
128125
expect(layoutOut.scene.aspectmode).toBe(expected.scene.aspectmode);
129126
expect(layoutOut.scene.aspectratio).toEqual(expected.scene.aspectratio);
130127
});
@@ -152,12 +149,65 @@ describe('Test Gl3d layout defaults', function() {
152149
}
153150
};
154151

155-
supplyLayoutDefaults(layoutIn, layoutOut, [{scene: 'scene', type: 'scatter3d'}]);
152+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
156153
expect(layoutOut.scene.aspectmode).toBe(expected.scene.aspectmode);
157154
expect(layoutOut.scene.aspectratio).toEqual(expected.scene.aspectratio);
158155
});
159156

157+
it('should coerce dragmode', function() {
158+
layoutIn = {};
159+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
160+
expect(layoutOut.scene.dragmode)
161+
.toBe('turntable', 'to turntable by default');
162+
163+
layoutIn = { scene: { dragmode: 'orbit' } };
164+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
165+
expect(layoutOut.scene.dragmode)
166+
.toBe('orbit', 'to user val if valid');
167+
168+
layoutIn = { dragmode: 'orbit' };
169+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
170+
expect(layoutOut.scene.dragmode)
171+
.toBe('orbit', 'to user layout val if valid and 3d only');
172+
173+
layoutIn = { dragmode: 'orbit' };
174+
layoutOut._hasCartesian = true;
175+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
176+
expect(layoutOut.scene.dragmode)
177+
.toBe('turntable', 'to default if not 3d only');
178+
179+
layoutIn = { dragmode: 'not gonna work' };
180+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
181+
expect(layoutOut.scene.dragmode)
182+
.toBe('turntable', 'to default if not valid');
183+
});
160184

161-
185+
it('should coerce hovermode', function() {
186+
layoutIn = {};
187+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
188+
expect(layoutOut.scene.hovermode)
189+
.toBe('closest', 'to closest by default');
190+
191+
layoutIn = { scene: { hovermode: false } };
192+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
193+
expect(layoutOut.scene.hovermode)
194+
.toBe(false, 'to user val if valid');
195+
196+
layoutIn = { hovermode: false };
197+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
198+
expect(layoutOut.scene.hovermode)
199+
.toBe(false, 'to user layout val if valid and 3d only');
200+
201+
layoutIn = { hovermode: false };
202+
layoutOut._hasCartesian = true;
203+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
204+
expect(layoutOut.scene.hovermode)
205+
.toBe('closest', 'to default if not 3d only');
206+
207+
layoutIn = { hovermode: 'not gonna work' };
208+
supplyLayoutDefaults(layoutIn, layoutOut, fullData);
209+
expect(layoutOut.scene.hovermode)
210+
.toBe('closest', 'to default if not valid');
211+
});
162212
});
163213
});

0 commit comments

Comments
 (0)