|
| 1 | +var Plotly = require('@lib/index'); |
1 | 2 | var attributes = require('@src/traces/sankey/attributes');
|
2 | 3 | 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'); |
4 | 7 | var Plots = require('@src/plots/plots');
|
5 | 8 | var Sankey = require('@src/traces/sankey');
|
6 | 9 |
|
| 10 | +var createGraphDiv = require('../assets/create_graph_div'); |
| 11 | +var destroyGraphDiv = require('../assets/destroy_graph_div'); |
| 12 | + |
7 | 13 | describe('sankey tests', function() {
|
8 | 14 |
|
9 | 15 | 'use strict';
|
@@ -248,4 +254,61 @@ describe('sankey tests', function() {
|
248 | 254 | });
|
249 | 255 | });
|
250 | 256 | });
|
| 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 | + }); |
251 | 314 | });
|
0 commit comments