Skip to content

Commit 0634111

Browse files
committed
Add test for nested svg tags
1 parent 38736a2 commit 0634111

File tree

1 file changed

+44
-9
lines changed

1 file changed

+44
-9
lines changed

test/jasmine/tests/snapshot_clone_test.js renamed to test/jasmine/tests/snapshot_test.js

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
var Snapshot = require('@src/snapshot');
1+
var Plotly = require('@lib/index');
2+
var createGraphDiv = require('../assets/create_graph_div');
3+
var destroyGraphDiv = require('../assets/destroy_graph_div');
4+
var subplotMock = require('../../image/mocks/multiple_subplots.json');
5+
var annotationMock = require('../../image/mocks/annotations.json');
26

3-
describe('Test Snapshot.clone', function() {
7+
describe('Plotly.Snapshot', function() {
48
'use strict';
59

6-
describe('Test clone', function() {
10+
describe('clone', function() {
711

812
var data,
913
layout,
@@ -76,7 +80,7 @@ describe('Test Snapshot.clone', function() {
7680
setBackground: 'opaque'
7781
};
7882

79-
var themeTile = Snapshot.clone(dummyGraphObj, themeOptions);
83+
var themeTile = Plotly.Snapshot.clone(dummyGraphObj, themeOptions);
8084
expect(themeTile.layout.height).toEqual(THEMETILE_DEFAULT_LAYOUT.height);
8185
expect(themeTile.layout.width).toEqual(THEMETILE_DEFAULT_LAYOUT.width);
8286
expect(themeTile.td.defaultLayout).toEqual(THEMETILE_DEFAULT_LAYOUT);
@@ -101,7 +105,7 @@ describe('Test Snapshot.clone', function() {
101105
'annotations': []
102106
};
103107

104-
var thumbTile = Snapshot.clone(dummyGraphObj, thumbnailOptions);
108+
var thumbTile = Plotly.Snapshot.clone(dummyGraphObj, thumbnailOptions);
105109
expect(thumbTile.layout.hidesources).toEqual(THUMBNAIL_DEFAULT_LAYOUT.hidesources);
106110
expect(thumbTile.layout.showlegend).toEqual(THUMBNAIL_DEFAULT_LAYOUT.showlegend);
107111
expect(thumbTile.layout.borderwidth).toEqual(THUMBNAIL_DEFAULT_LAYOUT.borderwidth);
@@ -115,7 +119,7 @@ describe('Test Snapshot.clone', function() {
115119
width: 888
116120
};
117121

118-
var customTile = Snapshot.clone(dummyGraphObj, customOptions);
122+
var customTile = Plotly.Snapshot.clone(dummyGraphObj, customOptions);
119123
expect(customTile.layout.height).toEqual(customOptions.height);
120124
expect(customTile.layout.width).toEqual(customOptions.width);
121125
});
@@ -125,23 +129,54 @@ describe('Test Snapshot.clone', function() {
125129
tileClass: 'notarealclass'
126130
};
127131

128-
var vanillaPlotTile = Snapshot.clone(dummyGraphObj, vanillaOptions);
132+
var vanillaPlotTile = Plotly.Snapshot.clone(dummyGraphObj, vanillaOptions);
129133
expect(vanillaPlotTile.data[0].x).toEqual(data[0].x);
130134
expect(vanillaPlotTile.layout).toEqual(layout);
131135
expect(vanillaPlotTile.layout.height).toEqual(layout.height);
132136
expect(vanillaPlotTile.layout.width).toEqual(layout.width);
133137
});
134138

135139
it('should set the background parameter appropriately', function() {
136-
var pt = Snapshot.clone(dummyGraphObj, {
140+
var pt = Plotly.Snapshot.clone(dummyGraphObj, {
137141
setBackground: 'transparent'
138142
});
139143
expect(pt.config.setBackground).not.toBeDefined();
140144

141-
pt = Snapshot.clone(dummyGraphObj, {
145+
pt = Plotly.Snapshot.clone(dummyGraphObj, {
142146
setBackground: 'blue'
143147
});
144148
expect(pt.config.setBackground).toEqual('blue');
145149
});
146150
});
151+
152+
describe('toSVG', function() {
153+
var gd;
154+
155+
beforeEach(function() {
156+
gd = createGraphDiv();
157+
});
158+
159+
afterEach(destroyGraphDiv);
160+
161+
162+
it('should not return any nested svg tags of plots', function(done) {
163+
Plotly.plot(gd, subplotMock.data, subplotMock.layout).then(function() {
164+
return Plotly.Snapshot.toSVG(gd);
165+
}).then(function(svg) {
166+
var splitSVG = svg.split('<svg');
167+
168+
expect(splitSVG.length).toBe(2);
169+
}).then(done);
170+
});
171+
172+
it('should not return any nested svg tags of annotations', function(done) {
173+
Plotly.plot(gd, annotationMock.data, annotationMock.layout).then(function() {
174+
return Plotly.Snapshot.toSVG(gd);
175+
}).then(function(svg) {
176+
var splitSVG = svg.split('<svg');
177+
178+
expect(splitSVG.length).toBe(2);
179+
}).then(done);
180+
});
181+
});
147182
});

0 commit comments

Comments
 (0)