@@ -61,6 +61,24 @@ describe('Plotly.downloadImage', function() {
61
61
downloadTest ( gd , 'svg' , done ) ;
62
62
} , LONG_TIMEOUT_INTERVAL ) ;
63
63
64
+ it ( 'should work when passing graph div id' , function ( done ) {
65
+ downloadTest ( 'graph' , 'svg' , done ) ;
66
+ } , LONG_TIMEOUT_INTERVAL ) ;
67
+
68
+ it ( 'should work when passing a figure object' , function ( done ) {
69
+ var fig = {
70
+ data : [ { y : [ 1 , 2 , 1 ] } ]
71
+ } ;
72
+ Plotly . downloadImage ( fig )
73
+ . then ( function ( ) {
74
+ expect ( document . createElement ) . toHaveBeenCalledWith ( 'canvas' ) ;
75
+ expect ( gd . _snapshotInProgress )
76
+ . toBe ( undefined , 'should not attach _snapshotInProgress to figure objects' ) ;
77
+ } )
78
+ . catch ( failTest )
79
+ . then ( done ) ;
80
+ } , LONG_TIMEOUT_INTERVAL ) ;
81
+
64
82
it ( 'should produce the right SVG output in IE' , function ( done ) {
65
83
// mock up IE behavior
66
84
spyOn ( Lib , 'isIE' ) . and . callFake ( function ( ) { return true ; } ) ;
@@ -127,16 +145,26 @@ function downloadTest(gd, format, done) {
127
145
} ) ;
128
146
} ) ;
129
147
130
- Plotly . plot ( gd , textchartMock . data , textchartMock . layout ) . then ( function ( gd ) {
148
+ Plotly . plot ( gd , textchartMock . data , textchartMock . layout ) . then ( function ( _gd ) {
131
149
// start observing dom
132
150
// configuration of the observer:
133
151
var config = { childList : true } ;
134
152
135
153
// pass in the target node and observer options
136
154
observer . observe ( target , config ) ;
137
155
138
- return Plotly . downloadImage ( gd , { format : format , height : 300 , width : 300 , filename : 'plotly_download' } ) ;
139
- } ) . then ( function ( filename ) {
156
+ var promise = Plotly . downloadImage ( gd , {
157
+ format : format ,
158
+ height : 300 ,
159
+ width : 300 ,
160
+ filename : 'plotly_download'
161
+ } ) ;
162
+
163
+ expect ( _gd . _snapshotInProgress ) . toBe ( true , 'should attach _snapshotInProgress to graph divs' ) ;
164
+
165
+ return promise ;
166
+ } )
167
+ . then ( function ( filename ) {
140
168
// stop observing
141
169
observer . disconnect ( ) ;
142
170
// look for an added and removed link
@@ -150,11 +178,11 @@ function downloadTest(gd, format, done) {
150
178
151
179
// check that link removed
152
180
expect ( linkadded ) . toBe ( linkdeleted ) ;
153
- done ( ) ;
154
- } ) ;
181
+ } )
182
+ . catch ( failTest )
183
+ . then ( done ) ;
155
184
}
156
185
157
-
158
186
// Only chrome supports webp at the time of writing
159
187
function checkWebp ( cb ) {
160
188
var img = new Image ( ) ;
0 commit comments