Skip to content

Commit a2a416e

Browse files
committed
jasmine tests for Sankey
1 parent 3d10714 commit a2a416e

File tree

1 file changed

+178
-0
lines changed

1 file changed

+178
-0
lines changed

test/jasmine/tests/sankey_test.js

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
var Lib = require('@src/lib');
2+
var Sankey = require('@src/traces/sankey');
3+
var attributes = require('@src/traces/sankey/attributes');
4+
5+
describe('sankey initialization tests', function() {
6+
7+
'use strict';
8+
9+
function _supply(traceIn) {
10+
var traceOut = { visible: true },
11+
defaultColor = '#444',
12+
layout = { };
13+
14+
Sankey.supplyDefaults(traceIn, traceOut, defaultColor, layout);
15+
16+
return traceOut;
17+
}
18+
19+
function _supplyWithLayout(traceIn, layout) {
20+
var traceOut = { visible: true },
21+
defaultColor = '#444';
22+
23+
Sankey.supplyDefaults(traceIn, traceOut, defaultColor, layout);
24+
25+
return traceOut;
26+
}
27+
28+
describe('don\'t remove nodes if encountering no circularity', function() {
29+
30+
it('removing a single self-pointing node', function() {
31+
var fullTrace = _supply({
32+
node: {
33+
label: ['a', 'b']
34+
},
35+
link: {
36+
value: [1],
37+
source: [1],
38+
target: [0]
39+
}
40+
});
41+
42+
expect(fullTrace.node.label).toEqual(['a', 'b'], 'node labels retained');
43+
expect(fullTrace.link.value).toEqual([1], 'link value(s) retained');
44+
expect(fullTrace.link.source).toEqual([1], 'link source(s) retained');
45+
expect(fullTrace.link.target).toEqual([0], 'link target(s) retained');
46+
});
47+
});
48+
49+
describe('remove nodes if encountering circularity', function() {
50+
51+
it('removing a single self-pointing node', function() {
52+
var fullTrace = _supply({
53+
node: {
54+
label: ['a']
55+
},
56+
link: {
57+
value: [1],
58+
source: [0],
59+
target: [0]
60+
}
61+
});
62+
63+
expect(fullTrace.node.label).toEqual([], 'node label(s) removed');
64+
expect(fullTrace.link.value).toEqual([], 'link value(s) removed');
65+
expect(fullTrace.link.source).toEqual([], 'link source(s) removed');
66+
expect(fullTrace.link.target).toEqual([], 'link target(s) removed');
67+
68+
});
69+
70+
it('removing everything if detecting a circle', function() {
71+
var fullTrace = _supply({
72+
node: {
73+
label: ['a', 'b', 'c', 'd', 'e']
74+
},
75+
link: {
76+
value: [1, 1, 1, 1, 1, 1, 1, 1],
77+
source: [0, 1, 2, 3],
78+
target: [1, 2, 0, 4]
79+
}
80+
});
81+
82+
expect(fullTrace.node.label).toEqual([], 'node label(s) removed');
83+
expect(fullTrace.link.value).toEqual([], 'link value(s) removed');
84+
expect(fullTrace.link.source).toEqual([], 'link source(s) removed');
85+
expect(fullTrace.link.target).toEqual([], 'link target(s) removed');
86+
87+
});
88+
89+
});
90+
91+
describe('sankey defaults', function() {
92+
93+
it('\'Sankey\' specification should have proper arrays where mandatory',
94+
function() {
95+
96+
var fullTrace = _supply({});
97+
98+
expect(fullTrace.node.label)
99+
.toEqual([], 'presence of node label array is guaranteed');
100+
101+
expect(fullTrace.link.value)
102+
.toEqual([], 'presence of link value array is guaranteed');
103+
104+
expect(fullTrace.link.source)
105+
.toEqual([], 'presence of link source array is guaranteed');
106+
107+
expect(fullTrace.link.target)
108+
.toEqual([], 'presence of link target array is guaranteed');
109+
110+
});
111+
112+
it('\'Sankey\' specification should have proper types',
113+
function() {
114+
115+
var fullTrace = _supply({});
116+
117+
expect(fullTrace.orientation)
118+
.toEqual(attributes.orientation.dflt, 'use orientation by default');
119+
120+
expect(fullTrace.valueformat)
121+
.toEqual(attributes.valueformat.dflt, 'valueformat by default');
122+
123+
expect(fullTrace.valuesuffix)
124+
.toEqual(attributes.valuesuffix.dflt, 'valuesuffix by default');
125+
126+
expect(fullTrace.arrangement)
127+
.toEqual(attributes.arrangement.dflt, 'arrangement by default');
128+
129+
expect(fullTrace.domain.x)
130+
.toEqual(attributes.domain.x.dflt, 'x domain by default');
131+
132+
expect(fullTrace.domain.y)
133+
.toEqual(attributes.domain.y.dflt, 'y domain by default');
134+
});
135+
136+
it('\'Sankey\' layout dependent specification should have proper types',
137+
function() {
138+
139+
var fullTrace = _supplyWithLayout({}, {font: {family: 'Arial'}});
140+
expect(fullTrace.textfont)
141+
.toEqual({family: 'Arial'}, 'textfont is defined');
142+
});
143+
144+
it('\'line\' specifications should yield the default values',
145+
function() {
146+
147+
var fullTrace = _supply({});
148+
149+
expect(fullTrace.node.line.color)
150+
.toEqual('#444', 'default node line color');
151+
expect(fullTrace.node.line.width)
152+
.toEqual(0.5, 'default node line thickness');
153+
154+
expect(fullTrace.link.line.color)
155+
.toEqual('#444', 'default link line color');
156+
expect(fullTrace.link.line.width)
157+
.toEqual(0, 'default link line thickness');
158+
});
159+
160+
it('fills \'node\' colors if not specified', function() {
161+
162+
var fullTrace = _supply({
163+
node: {
164+
label: ['a', 'b']
165+
},
166+
link: {
167+
source: [0],
168+
target: [1],
169+
value: [1]
170+
}
171+
});
172+
173+
expect(Lib.isArray(fullTrace.node.color)).toBe(true, 'set up color array');
174+
175+
});
176+
177+
});
178+
});

0 commit comments

Comments
 (0)