Skip to content

Commit 3e2a455

Browse files
committed
jasmine tests for Sankey - warning / error test (and defaults.js improv)
1 parent a2a416e commit 3e2a455

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

src/traces/sankey/defaults.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout
8383
};
8484

8585
if(traceOut.node.label.some(missing)) {
86-
Lib.log('Some of the nodes are neither sources nor targets, please remove them.');
86+
Lib.warn('Some of the nodes are neither sources nor targets, please remove them.');
8787
}
8888

8989
if(circularityPresent(traceOut.node.label, traceOut.link.source, traceOut.link.target)) {
90-
Lib.log('Circularity is present in the Sankey data. Removing all nodes and links.');
90+
Lib.error('Circularity is present in the Sankey data. Removing all nodes and links.');
9191
traceOut.link.label = [];
9292
traceOut.link.source = [];
9393
traceOut.link.target = [];

test/jasmine/tests/sankey_test.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ var Lib = require('@src/lib');
22
var Sankey = require('@src/traces/sankey');
33
var attributes = require('@src/traces/sankey/attributes');
44

5-
describe('sankey initialization tests', function() {
5+
describe('sankey tests', function() {
66

77
'use strict';
88

@@ -88,6 +88,54 @@ describe('sankey initialization tests', function() {
8888

8989
});
9090

91+
describe('log warning if issue is encountered with graph structure',
92+
function() {
93+
94+
it('some nodes are not linked', function() {
95+
96+
var warnings = [];
97+
spyOn(Lib, 'warn').and.callFake(function(msg) {
98+
warnings.push(msg);
99+
});
100+
101+
_supply({
102+
node: {
103+
label: ['a', 'b', 'c']
104+
},
105+
link: {
106+
value: [1],
107+
source: [0],
108+
target: [1]
109+
}
110+
});
111+
112+
expect(warnings.length).toEqual(1);
113+
});
114+
115+
it('circularity is detected', function() {
116+
117+
var errors = [];
118+
spyOn(Lib, 'error').and.callFake(function(msg) {
119+
errors.push(msg);
120+
});
121+
122+
_supply({
123+
node: {
124+
label: ['a', 'b', 'c']
125+
},
126+
link: {
127+
value: [1, 1, 1],
128+
source: [0, 1, 2],
129+
target: [1, 2, 0]
130+
}
131+
});
132+
133+
expect(errors.length).toEqual(1);
134+
});
135+
136+
137+
});
138+
91139
describe('sankey defaults', function() {
92140

93141
it('\'Sankey\' specification should have proper arrays where mandatory',

0 commit comments

Comments
 (0)