Skip to content

Commit 0504083

Browse files
committed
test(sankey): drive pad-warning tests by explicit layout size
The karma viewport size does not determine the plot size, so the small-figure case rendered at default dimensions and never clamped. Set explicit layout width/height (and small margins) instead, and use the standard createGraphDiv() helper.
1 parent ab41bbe commit 0504083

1 file changed

Lines changed: 30 additions & 18 deletions

File tree

test/jasmine/tests/sankey_test.js

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -100,30 +100,39 @@ describe('sankey tests', function() {
100100
// not by reading `sankey.nodePadding()` back, which since
101101
// @plotly/d3-sankey@0.12.x returns the configured value instead of
102102
// the clamped one - see #7832.
103-
var padMock = [{
104-
type: 'sankey',
105-
layoutversion: 2,
106-
domain: {x: [0, 1], y: [0, 1]},
107-
node: {
108-
label: Array.from({length: 24}, function(_, i) { return 'n' + i; }),
109-
pad: 30,
110-
thickness: 10
111-
},
112-
link: {
113-
source: Array.from({length: 23}, function(_, i) { return i; }),
114-
target: Array.from({length: 23}, function(_, i) { return i + 1; }),
115-
value: Array.from({length: 23}, function() { return 1; })
103+
var padMock = {
104+
data: [{
105+
type: 'sankey',
106+
layoutversion: 2,
107+
node: {
108+
label: Array.from({length: 24}, function(_, i) { return 'n' + i; }),
109+
pad: 30,
110+
thickness: 10
111+
},
112+
link: {
113+
source: Array.from({length: 23}, function(_, i) { return i; }),
114+
target: Array.from({length: 23}, function(_, i) { return i + 1; }),
115+
value: Array.from({length: 23}, function() { return 1; })
116+
}
117+
}],
118+
layout: {
119+
width: 500,
120+
height: 500,
121+
margin: {l: 10, r: 10, t: 10, b: 10}
116122
}
117-
}];
123+
};
118124

119125
it('warns when the figure is too small for node.pad', function(done) {
120126
var warnings = [];
121127
spyOn(Lib, 'warn').and.callFake(function(msg) {
122128
warnings.push(msg);
123129
});
124130

125-
var gd = createGraphDiv('pad-warn-small', 300, 100);
126-
Plotly.newPlot(gd, Lib.extendDeep([], padMock))
131+
var fig = Lib.extendDeep({}, padMock);
132+
fig.layout.width = 200;
133+
fig.layout.height = 100;
134+
var gd = createGraphDiv();
135+
Plotly.newPlot(gd, fig)
127136
.then(function() {
128137
expect(warnings.length).toEqual(1);
129138
expect(warnings[0][0]).toBe('node.pad was reduced to ');
@@ -140,8 +149,11 @@ describe('sankey tests', function() {
140149
warnings.push(msg);
141150
});
142151

143-
var gd = createGraphDiv('pad-warn-large', 700, 900);
144-
Plotly.newPlot(gd, Lib.extendDeep([], padMock))
152+
var fig = Lib.extendDeep({}, padMock);
153+
fig.layout.width = 700;
154+
fig.layout.height = 900;
155+
var gd = createGraphDiv();
156+
Plotly.newPlot(gd, fig)
145157
.then(function() {
146158
expect(warnings.length).toEqual(0);
147159
return Plotly.purge(gd);

0 commit comments

Comments
 (0)