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,57 @@ 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 parser = new DOMParser ( ) ,
154+ gd ;
155+
156+ beforeEach ( function ( ) {
157+ gd = createGraphDiv ( ) ;
158+ } ) ;
159+
160+ afterEach ( destroyGraphDiv ) ;
161+
162+
163+ it ( 'should not return any nested svg tags of plots' , function ( done ) {
164+ Plotly . plot ( gd , subplotMock . data , subplotMock . layout ) . then ( function ( ) {
165+ return Plotly . Snapshot . toSVG ( gd ) ;
166+ } ) . then ( function ( svg ) {
167+ var svgDOM = parser . parseFromString ( svg , 'image/svg+xml' ) ,
168+ svgElements = svgDOM . getElementsByTagName ( 'svg' ) ;
169+
170+ expect ( svgElements . length ) . toBe ( 1 ) ;
171+ } ) . then ( done ) ;
172+ } ) ;
173+
174+ it ( 'should not return any nested svg tags of annotations' , function ( done ) {
175+ Plotly . plot ( gd , annotationMock . data , annotationMock . layout ) . then ( function ( ) {
176+ return Plotly . Snapshot . toSVG ( gd ) ;
177+ } ) . then ( function ( svg ) {
178+ var svgDOM = parser . parseFromString ( svg , 'image/svg+xml' ) ,
179+ svgElements = svgDOM . getElementsByTagName ( 'svg' ) ;
180+
181+ expect ( svgElements . length ) . toBe ( 1 ) ;
182+ } ) . then ( done ) ;
183+ } ) ;
184+ } ) ;
147185} ) ;
0 commit comments