Skip to content

Commit 7eab8cc

Browse files
committed
clean up download_test suite
1 parent 795220f commit 7eab8cc

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed

test/jasmine/tests/download_test.js

+21-14
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ var Lib = require('@src/lib');
99
var LONG_TIMEOUT_INTERVAL = 2 * jasmine.DEFAULT_TIMEOUT_INTERVAL;
1010

1111
describe('Plotly.downloadImage', function() {
12-
'use strict';
1312
var gd;
1413

1514
var createElement = document.createElement;
@@ -32,37 +31,47 @@ describe('Plotly.downloadImage', function() {
3231

3332
afterEach(function() {
3433
destroyGraphDiv();
35-
delete navigator.msSaveBlob;
34+
delete window.navigator.msSaveBlob;
3635
});
3736

3837
it('should be attached to Plotly', function() {
3938
expect(Plotly.downloadImage).toBeDefined();
4039
});
4140

4241
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);
4445
}, LONG_TIMEOUT_INTERVAL);
4546

4647
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);
4851
}, LONG_TIMEOUT_INTERVAL);
4952

5053
it('should create link, remove link, accept options', function(done) {
5154
checkWebp(function(supported) {
5255
if(supported) {
53-
downloadTest(gd, 'webp', done);
56+
downloadTest(gd, 'webp')
57+
.catch(failTest)
58+
.then(done);
5459
} else {
5560
done();
5661
}
5762
});
5863
}, LONG_TIMEOUT_INTERVAL);
5964

6065
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);
6269
}, LONG_TIMEOUT_INTERVAL);
6370

6471
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);
6675
}, LONG_TIMEOUT_INTERVAL);
6776

6877
it('should work when passing a figure object', function(done) {
@@ -87,7 +96,7 @@ describe('Plotly.downloadImage', function() {
8796
.replace(/(\(#)([^")]*)(\))/gi, '(\"#$2\")');
8897
});
8998
var savedBlob;
90-
navigator.msSaveBlob = function(blob) { savedBlob = blob; };
99+
window.navigator.msSaveBlob = function(blob) { savedBlob = blob; };
91100

92101
var expectedStart = '<svg class=\'main-svg\' xmlns=\'http://www.w3.org/2000/svg\' xmlns:xlink=\'http://www.w3.org/1999/xlink\'';
93102
var plotClip = /clip-path='url\("#clip[0-9a-f]{6}xyplot"\)/;
@@ -129,7 +138,7 @@ describe('Plotly.downloadImage', function() {
129138
}, LONG_TIMEOUT_INTERVAL);
130139
});
131140

132-
function downloadTest(gd, format, done) {
141+
function downloadTest(gd, format) {
133142
// use MutationObserver to monitor the DOM
134143
// for changes
135144
// code modeled after
@@ -145,7 +154,7 @@ function downloadTest(gd, format, done) {
145154
});
146155
});
147156

148-
Plotly.plot(gd, textchartMock.data, textchartMock.layout).then(function(_gd) {
157+
return Plotly.plot(gd, textchartMock.data, textchartMock.layout).then(function(_gd) {
149158
// start observing dom
150159
// configuration of the observer:
151160
var config = { childList: true };
@@ -165,8 +174,8 @@ function downloadTest(gd, format, done) {
165174
return promise;
166175
})
167176
.then(function(filename) {
168-
// stop observing
169177
observer.disconnect();
178+
170179
// look for an added and removed link
171180
var linkadded = domchanges[domchanges.length - 2].addedNodes[0];
172181
var linkdeleted = domchanges[domchanges.length - 1].removedNodes[0];
@@ -178,9 +187,7 @@ function downloadTest(gd, format, done) {
178187

179188
// check that link removed
180189
expect(linkadded).toBe(linkdeleted);
181-
})
182-
.catch(failTest)
183-
.then(done);
190+
});
184191
}
185192

186193
// Only chrome supports webp at the time of writing

0 commit comments

Comments
 (0)