Skip to content

Commit d30bd1c

Browse files
committed
add tests for Plotly.purge and Plots.cleanPlot
1 parent 01fe3b2 commit d30bd1c

File tree

2 files changed

+70
-3
lines changed

2 files changed

+70
-3
lines changed

test/jasmine/tests/gl_plot_interact_test.js

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,19 @@ describe('Test gl plot interactions', function() {
3636

3737
sceneIds = Plots.getSubplotIds(fullLayout, 'gl3d');
3838
sceneIds.forEach(function(id) {
39-
fullLayout[id]._scene.destroy();
39+
var scene = fullLayout[id]._scene;
40+
41+
if(scene.glplot) scene.destroy();
4042
});
4143

4244
sceneIds = Plots.getSubplotIds(fullLayout, 'gl2d');
4345
sceneIds.forEach(function(id) {
4446
var scene2d = fullLayout._plots[id]._scene2d;
45-
scene2d.stopped = true;
46-
scene2d.destroy();
47+
48+
if(scene2d.glplot) {
49+
scene2d.stopped = true;
50+
scene2d.destroy();
51+
}
4752
});
4853

4954
destroyGraphDiv();
@@ -369,4 +374,43 @@ describe('Test gl plot interactions', function() {
369374
});
370375

371376
});
377+
378+
describe('Plots.cleanPlot', function() {
379+
380+
it('should remove gl context from the graph div of a gl3d plot', function(done) {
381+
gd = createGraphDiv();
382+
383+
var mockData = [{
384+
type: 'scatter3d'
385+
}];
386+
387+
Plotly.plot(gd, mockData).then(function() {
388+
expect(gd._fullLayout.scene._scene.glplot).toBeDefined();
389+
390+
Plots.cleanPlot([], {}, gd._fullData, gd._fullLayout);
391+
expect(gd._fullLayout.scene._scene.glplot).toBe(null);
392+
393+
done();
394+
});
395+
});
396+
397+
it('should remove gl context from the graph div of a gl2d plot', function(done) {
398+
gd = createGraphDiv();
399+
400+
var mockData = [{
401+
type: 'scattergl',
402+
x: [1,2,3],
403+
y: [1,2,3]
404+
}];
405+
406+
Plotly.plot(gd, mockData).then(function() {
407+
expect(gd._fullLayout._plots.xy._scene2d.glplot).toBeDefined();
408+
409+
Plots.cleanPlot([], {}, gd._fullData, gd._fullLayout);
410+
expect(gd._fullLayout._plots.xy._scene2d.glplot).toBe(null);
411+
412+
done();
413+
});
414+
});
415+
});
372416
});

test/jasmine/tests/plot_api_test.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ var Bar = require('@src/traces/bar');
77
var Legend = require('@src/components/legend');
88
var pkg = require('../../../package.json');
99

10+
var createGraphDiv = require('../assets/create_graph_div');
11+
var destroyGraphDiv = require('../assets/destroy_graph_div');
1012

1113
describe('Test plot api', function() {
1214
'use strict';
@@ -616,4 +618,25 @@ describe('Test plot api', function() {
616618
expect(gd.data).toEqual(cachedData);
617619
});
618620
});
621+
622+
describe('Plotly.purge', function() {
623+
624+
afterEach(destroyGraphDiv);
625+
626+
it('should return the graph div in its original state', function(done) {
627+
var gd = createGraphDiv();
628+
var initialKeys = Object.keys(gd);
629+
var intialHTML = gd.innerHTML;
630+
var mockData = [{ x: [1,2,3], y: [2,3,4] }];
631+
632+
Plotly.plot(gd, mockData).then(function() {
633+
Plotly.purge(gd);
634+
635+
expect(Object.keys(gd)).toEqual(initialKeys);
636+
expect(gd.innerHTML).toEqual(intialHTML);
637+
638+
done();
639+
});
640+
});
641+
});
619642
});

0 commit comments

Comments
 (0)