@@ -9,7 +9,6 @@ var Lib = require('@src/lib');
9
9
var LONG_TIMEOUT_INTERVAL = 2 * jasmine . DEFAULT_TIMEOUT_INTERVAL ;
10
10
11
11
describe ( 'Plotly.downloadImage' , function ( ) {
12
- 'use strict' ;
13
12
var gd ;
14
13
15
14
var createElement = document . createElement ;
@@ -32,37 +31,47 @@ describe('Plotly.downloadImage', function() {
32
31
33
32
afterEach ( function ( ) {
34
33
destroyGraphDiv ( ) ;
35
- delete navigator . msSaveBlob ;
34
+ delete window . navigator . msSaveBlob ;
36
35
} ) ;
37
36
38
37
it ( 'should be attached to Plotly' , function ( ) {
39
38
expect ( Plotly . downloadImage ) . toBeDefined ( ) ;
40
39
} ) ;
41
40
42
41
it ( 'should create link, remove link, accept options' , function ( done ) {
43
- downloadTest ( gd , 'jpeg' , done ) ;
42
+ downloadTest ( gd , 'jpeg' )
43
+ . catch ( failTest )
44
+ . then ( done ) ;
44
45
} , LONG_TIMEOUT_INTERVAL ) ;
45
46
46
47
it ( 'should create link, remove link, accept options' , function ( done ) {
47
- downloadTest ( gd , 'png' , done ) ;
48
+ downloadTest ( gd , 'png' )
49
+ . catch ( failTest )
50
+ . then ( done ) ;
48
51
} , LONG_TIMEOUT_INTERVAL ) ;
49
52
50
53
it ( 'should create link, remove link, accept options' , function ( done ) {
51
54
checkWebp ( function ( supported ) {
52
55
if ( supported ) {
53
- downloadTest ( gd , 'webp' , done ) ;
56
+ downloadTest ( gd , 'webp' )
57
+ . catch ( failTest )
58
+ . then ( done ) ;
54
59
} else {
55
60
done ( ) ;
56
61
}
57
62
} ) ;
58
63
} , LONG_TIMEOUT_INTERVAL ) ;
59
64
60
65
it ( 'should create link, remove link, accept options' , function ( done ) {
61
- downloadTest ( gd , 'svg' , done ) ;
66
+ downloadTest ( gd , 'svg' )
67
+ . catch ( failTest )
68
+ . then ( done ) ;
62
69
} , LONG_TIMEOUT_INTERVAL ) ;
63
70
64
71
it ( 'should work when passing graph div id' , function ( done ) {
65
- downloadTest ( 'graph' , 'svg' , done ) ;
72
+ downloadTest ( 'graph' , 'svg' )
73
+ . catch ( failTest )
74
+ . then ( done ) ;
66
75
} , LONG_TIMEOUT_INTERVAL ) ;
67
76
68
77
it ( 'should work when passing a figure object' , function ( done ) {
@@ -87,7 +96,7 @@ describe('Plotly.downloadImage', function() {
87
96
. replace ( / ( \( # ) ( [ ^ " ) ] * ) ( \) ) / gi, '(\"#$2\")' ) ;
88
97
} ) ;
89
98
var savedBlob ;
90
- navigator . msSaveBlob = function ( blob ) { savedBlob = blob ; } ;
99
+ window . navigator . msSaveBlob = function ( blob ) { savedBlob = blob ; } ;
91
100
92
101
var expectedStart = '<svg class=\'main-svg\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'' ;
93
102
var plotClip = / c l i p - p a t h = ' u r l \( " # c l i p [ 0 - 9 a - f ] { 6 } x y p l o t " \) / ;
@@ -129,7 +138,7 @@ describe('Plotly.downloadImage', function() {
129
138
} , LONG_TIMEOUT_INTERVAL ) ;
130
139
} ) ;
131
140
132
- function downloadTest ( gd , format , done ) {
141
+ function downloadTest ( gd , format ) {
133
142
// use MutationObserver to monitor the DOM
134
143
// for changes
135
144
// code modeled after
@@ -145,7 +154,7 @@ function downloadTest(gd, format, done) {
145
154
} ) ;
146
155
} ) ;
147
156
148
- Plotly . plot ( gd , textchartMock . data , textchartMock . layout ) . then ( function ( _gd ) {
157
+ return Plotly . plot ( gd , textchartMock . data , textchartMock . layout ) . then ( function ( _gd ) {
149
158
// start observing dom
150
159
// configuration of the observer:
151
160
var config = { childList : true } ;
@@ -165,8 +174,8 @@ function downloadTest(gd, format, done) {
165
174
return promise ;
166
175
} )
167
176
. then ( function ( filename ) {
168
- // stop observing
169
177
observer . disconnect ( ) ;
178
+
170
179
// look for an added and removed link
171
180
var linkadded = domchanges [ domchanges . length - 2 ] . addedNodes [ 0 ] ;
172
181
var linkdeleted = domchanges [ domchanges . length - 1 ] . removedNodes [ 0 ] ;
@@ -178,9 +187,7 @@ function downloadTest(gd, format, done) {
178
187
179
188
// check that link removed
180
189
expect ( linkadded ) . toBe ( linkdeleted ) ;
181
- } )
182
- . catch ( failTest )
183
- . then ( done ) ;
190
+ } ) ;
184
191
}
185
192
186
193
// Only chrome supports webp at the time of writing
0 commit comments