Skip to content

Commit bf2658a

Browse files
committed
add surface defaults tests
1 parent b07c429 commit bf2658a

File tree

1 file changed

+137
-0
lines changed

1 file changed

+137
-0
lines changed

test/jasmine/tests/surface_test.js

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
var Surface = require('@src/traces/surface');
2+
3+
4+
describe('Test surface', function() {
5+
'use strict';
6+
7+
describe('supplyDefaults', function() {
8+
var supplyDefaults = Surface.supplyDefaults;
9+
10+
var defaultColor = '#444',
11+
layout = {};
12+
13+
var traceIn, traceOut;
14+
15+
beforeEach(function() {
16+
traceOut = {};
17+
});
18+
19+
it('should set \'visible\' to false if \'z\' isn\'t provided', function() {
20+
traceIn = {};
21+
22+
supplyDefaults(traceIn, traceOut, defaultColor, layout);
23+
expect(traceOut.visible).toBe(false);
24+
});
25+
26+
it('should fill \'x\' and \'y\' if not provided', function() {
27+
traceIn = {
28+
z: [[1,2,3], [2,1,2]]
29+
};
30+
31+
supplyDefaults(traceIn, traceOut, defaultColor, layout);
32+
expect(traceOut.x).toEqual([0,1,2]);
33+
expect(traceOut.y).toEqual([0,1]);
34+
});
35+
36+
it('should coerce \'project\' if contours or highlight lines are enabled', function() {
37+
traceIn = {
38+
z: [[1,2,3], [2,1,2]],
39+
contours: {
40+
x: { show: true }
41+
}
42+
};
43+
44+
supplyDefaults(traceIn, traceOut, defaultColor, layout);
45+
expect(traceOut.contours.x.project).toEqual({ x: false, y: false, z: false });
46+
expect(traceOut.contours.y).toEqual({ show: false, highlight: false });
47+
expect(traceOut.contours.z).toEqual({ show: false, highlight: false });
48+
});
49+
50+
it('should coerce contour style attributes if contours lines are enabled', function() {
51+
traceIn = {
52+
z: [[1,2,3], [2,1,2]],
53+
contours: {
54+
x: { show: true }
55+
}
56+
};
57+
58+
supplyDefaults(traceIn, traceOut, defaultColor, layout);
59+
expect(traceOut.contours.x.color).toEqual('#000');
60+
expect(traceOut.contours.x.width).toEqual(2);
61+
expect(traceOut.contours.x.usecolormap).toEqual(false);
62+
63+
['y', 'z'].forEach(function(ax) {
64+
expect(traceOut.contours[ax].color).toBeUndefined();
65+
expect(traceOut.contours[ax].width).toBeUndefined();
66+
expect(traceOut.contours[ax].usecolormap).toBeUndefined();
67+
});
68+
});
69+
70+
it('should coerce colorscale and colorbar attributes', function() {
71+
traceIn = {
72+
z: [[1,2,3], [2,1,2]]
73+
};
74+
75+
supplyDefaults(traceIn, traceOut, defaultColor, layout);
76+
expect(traceOut.cauto).toBe(true);
77+
expect(traceOut.cmin).toBeUndefined();
78+
expect(traceOut.cmax).toBeUndefined();
79+
expect(traceOut.colorscale).toEqual([
80+
[0, 'rgb(5,10,172)'],
81+
[0.35, 'rgb(106,137,247)'],
82+
[0.5, 'rgb(190,190,190)'],
83+
[0.6, 'rgb(220,170,132)'],
84+
[0.7, 'rgb(230,145,90)'],
85+
[1, 'rgb(178,10,28)']
86+
]);
87+
expect(traceOut.showscale).toBe(true);
88+
expect(traceOut.colorbar).toBeDefined();
89+
});
90+
91+
it('should coerce \'c\' attributes with \'z\' if \'c\' isn\'t present', function() {
92+
traceIn = {
93+
z: [[1,2,3], [2,1,2]],
94+
zauto: false,
95+
zmin: 0,
96+
zmax: 10
97+
};
98+
99+
supplyDefaults(traceIn, traceOut, defaultColor, layout);
100+
expect(traceOut.cauto).toEqual(false);
101+
expect(traceOut.cmin).toEqual(0);
102+
expect(traceOut.cmax).toEqual(10);
103+
});
104+
105+
it('should coerce \'c\' attributes with \'c\' values regardless of `\'z\' if \'c\' is present', function() {
106+
traceIn = {
107+
z: [[1,2,3], [2,1,2]],
108+
zauto: false,
109+
zmin: 0,
110+
zmax: 10,
111+
cauto: true,
112+
cmin: -10,
113+
cmax: 20
114+
};
115+
116+
supplyDefaults(traceIn, traceOut, defaultColor, layout);
117+
expect(traceOut.cauto).toEqual(true);
118+
expect(traceOut.cmin).toEqual(-10);
119+
expect(traceOut.cmax).toEqual(20);
120+
});
121+
122+
it('should default \'c\' attributes with if \'surfacecolor\' is present', function() {
123+
traceIn = {
124+
z: [[1,2,3], [2,1,2]],
125+
surfacecolor: [[2,1,2], [1,2,3]],
126+
zauto: false,
127+
zmin: 0,
128+
zmax: 10
129+
};
130+
131+
supplyDefaults(traceIn, traceOut, defaultColor, layout);
132+
expect(traceOut.cauto).toEqual(true);
133+
expect(traceOut.cmin).toBeUndefined();
134+
expect(traceOut.cmax).toBeUndefined();
135+
});
136+
});
137+
});

0 commit comments

Comments
 (0)