@@ -61,6 +61,24 @@ describe('Plotly.downloadImage', function() {
6161 downloadTest ( gd , 'svg' , done ) ;
6262 } , LONG_TIMEOUT_INTERVAL ) ;
6363
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+
6482 it ( 'should produce the right SVG output in IE' , function ( done ) {
6583 // mock up IE behavior
6684 spyOn ( Lib , 'isIE' ) . and . callFake ( function ( ) { return true ; } ) ;
@@ -127,16 +145,26 @@ function downloadTest(gd, format, done) {
127145 } ) ;
128146 } ) ;
129147
130- Plotly . plot ( gd , textchartMock . data , textchartMock . layout ) . then ( function ( gd ) {
148+ Plotly . plot ( gd , textchartMock . data , textchartMock . layout ) . then ( function ( _gd ) {
131149 // start observing dom
132150 // configuration of the observer:
133151 var config = { childList : true } ;
134152
135153 // pass in the target node and observer options
136154 observer . observe ( target , config ) ;
137155
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 ) {
140168 // stop observing
141169 observer . disconnect ( ) ;
142170 // look for an added and removed link
@@ -150,11 +178,11 @@ function downloadTest(gd, format, done) {
150178
151179 // check that link removed
152180 expect ( linkadded ) . toBe ( linkdeleted ) ;
153- done ( ) ;
154- } ) ;
181+ } )
182+ . catch ( failTest )
183+ . then ( done ) ;
155184}
156185
157-
158186// Only chrome supports webp at the time of writing
159187function checkWebp ( cb ) {
160188 var img = new Image ( ) ;
0 commit comments