Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

Commit aa83612

Browse files
committed
PR feedback: testing lifecycle methods and visible; file rename
1 parent 9214c92 commit aa83612

File tree

5 files changed

+64
-1
lines changed

5 files changed

+64
-1
lines changed
File renamed without changes.

test/jasmine/tests/sankey_test.js

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1+
var Plotly = require('@lib/index');
12
var attributes = require('@src/traces/sankey/attributes');
23
var Lib = require('@src/lib');
3-
var mock = require('@mocks/energy.json');
4+
var d3 = require('d3');
5+
var mock = require('@mocks/sankey_energy.json');
6+
var mockDark = require('@mocks/sankey_energy_dark.json');
47
var Plots = require('@src/plots/plots');
58
var Sankey = require('@src/traces/sankey');
69

10+
var createGraphDiv = require('../assets/create_graph_div');
11+
var destroyGraphDiv = require('../assets/destroy_graph_div');
12+
713
describe('sankey tests', function() {
814

915
'use strict';
@@ -248,4 +254,61 @@ describe('sankey tests', function() {
248254
});
249255
});
250256
});
257+
258+
describe('lifecycle methods', function() {
259+
260+
afterEach(destroyGraphDiv);
261+
262+
it('Plotly.deleteTraces with two traces removes the deleted plot', function(done) {
263+
264+
var gd = createGraphDiv();
265+
var mockCopy = Lib.extendDeep({}, mock);
266+
var mockCopy2 = Lib.extendDeep({}, mockDark);
267+
268+
Plotly.plot(gd, mockCopy)
269+
.then(function() {
270+
expect(gd.data.length).toEqual(1);
271+
expect(d3.selectAll('.sankey').size()).toEqual(1);
272+
return Plotly.plot(gd, mockCopy2);
273+
})
274+
.then(function() {
275+
expect(gd.data.length).toEqual(2);
276+
expect(d3.selectAll('.sankey').size()).toEqual(2);
277+
return Plotly.deleteTraces(gd, [0]);
278+
})
279+
.then(function() {
280+
expect(gd.data.length).toEqual(1);
281+
expect(d3.selectAll('.sankey').size()).toEqual(1);
282+
return Plotly.deleteTraces(gd, 0);
283+
})
284+
.then(function() {
285+
expect(gd.data.length).toEqual(0);
286+
expect(d3.selectAll('.sankey').size()).toEqual(0);
287+
done();
288+
});
289+
});
290+
291+
it('Plotly.plot does not show Sankey if \'visible\' is false', function(done) {
292+
293+
var gd = createGraphDiv();
294+
var mockCopy = Lib.extendDeep({}, mock);
295+
296+
Plotly.plot(gd, mockCopy)
297+
.then(function() {
298+
expect(gd.data.length).toEqual(1);
299+
expect(d3.selectAll('.sankey').size()).toEqual(1);
300+
return Plotly.restyle(gd, 'visible', false);
301+
})
302+
.then(function() {
303+
expect(gd.data.length).toEqual(1);
304+
expect(d3.selectAll('.sankey').size()).toEqual(0);
305+
return Plotly.restyle(gd, 'visible', true);
306+
})
307+
.then(function() {
308+
expect(gd.data.length).toEqual(1);
309+
expect(d3.selectAll('.sankey').size()).toEqual(1);
310+
done();
311+
});
312+
});
313+
});
251314
});

0 commit comments

Comments
 (0)