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' ) ;
2
6
3
- describe ( 'Test Snapshot.clone ' , function ( ) {
7
+ describe ( 'Plotly.Snapshot ' , function ( ) {
4
8
'use strict' ;
5
9
6
- describe ( 'Test clone' , function ( ) {
10
+ describe ( 'clone' , function ( ) {
7
11
8
12
var data ,
9
13
layout ,
@@ -76,7 +80,7 @@ describe('Test Snapshot.clone', function() {
76
80
setBackground : 'opaque'
77
81
} ;
78
82
79
- var themeTile = Snapshot . clone ( dummyGraphObj , themeOptions ) ;
83
+ var themeTile = Plotly . Snapshot . clone ( dummyGraphObj , themeOptions ) ;
80
84
expect ( themeTile . layout . height ) . toEqual ( THEMETILE_DEFAULT_LAYOUT . height ) ;
81
85
expect ( themeTile . layout . width ) . toEqual ( THEMETILE_DEFAULT_LAYOUT . width ) ;
82
86
expect ( themeTile . td . defaultLayout ) . toEqual ( THEMETILE_DEFAULT_LAYOUT ) ;
@@ -101,7 +105,7 @@ describe('Test Snapshot.clone', function() {
101
105
'annotations' : [ ]
102
106
} ;
103
107
104
- var thumbTile = Snapshot . clone ( dummyGraphObj , thumbnailOptions ) ;
108
+ var thumbTile = Plotly . Snapshot . clone ( dummyGraphObj , thumbnailOptions ) ;
105
109
expect ( thumbTile . layout . hidesources ) . toEqual ( THUMBNAIL_DEFAULT_LAYOUT . hidesources ) ;
106
110
expect ( thumbTile . layout . showlegend ) . toEqual ( THUMBNAIL_DEFAULT_LAYOUT . showlegend ) ;
107
111
expect ( thumbTile . layout . borderwidth ) . toEqual ( THUMBNAIL_DEFAULT_LAYOUT . borderwidth ) ;
@@ -115,7 +119,7 @@ describe('Test Snapshot.clone', function() {
115
119
width : 888
116
120
} ;
117
121
118
- var customTile = Snapshot . clone ( dummyGraphObj , customOptions ) ;
122
+ var customTile = Plotly . Snapshot . clone ( dummyGraphObj , customOptions ) ;
119
123
expect ( customTile . layout . height ) . toEqual ( customOptions . height ) ;
120
124
expect ( customTile . layout . width ) . toEqual ( customOptions . width ) ;
121
125
} ) ;
@@ -125,23 +129,54 @@ describe('Test Snapshot.clone', function() {
125
129
tileClass : 'notarealclass'
126
130
} ;
127
131
128
- var vanillaPlotTile = Snapshot . clone ( dummyGraphObj , vanillaOptions ) ;
132
+ var vanillaPlotTile = Plotly . Snapshot . clone ( dummyGraphObj , vanillaOptions ) ;
129
133
expect ( vanillaPlotTile . data [ 0 ] . x ) . toEqual ( data [ 0 ] . x ) ;
130
134
expect ( vanillaPlotTile . layout ) . toEqual ( layout ) ;
131
135
expect ( vanillaPlotTile . layout . height ) . toEqual ( layout . height ) ;
132
136
expect ( vanillaPlotTile . layout . width ) . toEqual ( layout . width ) ;
133
137
} ) ;
134
138
135
139
it ( 'should set the background parameter appropriately' , function ( ) {
136
- var pt = Snapshot . clone ( dummyGraphObj , {
140
+ var pt = Plotly . Snapshot . clone ( dummyGraphObj , {
137
141
setBackground : 'transparent'
138
142
} ) ;
139
143
expect ( pt . config . setBackground ) . not . toBeDefined ( ) ;
140
144
141
- pt = Snapshot . clone ( dummyGraphObj , {
145
+ pt = Plotly . Snapshot . clone ( dummyGraphObj , {
142
146
setBackground : 'blue'
143
147
} ) ;
144
148
expect ( pt . config . setBackground ) . toEqual ( 'blue' ) ;
145
149
} ) ;
146
150
} ) ;
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
+ } ) ;
147
182
} ) ;
0 commit comments