Skip to content

Commit 74f178a

Browse files
committed
Update tests per new Cloud Upload feature
1 parent 8d7324d commit 74f178a

1 file changed

Lines changed: 28 additions & 56 deletions

File tree

test/jasmine/tests/config_test.js

Lines changed: 28 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -520,73 +520,45 @@ describe('config argument', function() {
520520
});
521521

522522
describe('plotlyServerURL:', function() {
523-
var gd;
524-
var form;
525-
526-
beforeEach(function() {
527-
gd = createGraphDiv();
528-
spyOn(HTMLFormElement.prototype, 'submit').and.callFake(function() {
529-
form = this;
530-
});
531-
});
523+
let gd;
532524

525+
beforeEach(() => { gd = createGraphDiv(); });
533526
afterEach(destroyGraphDiv);
534527

535-
it('should not default to an external plotly cloud', function(done) {
536-
Plotly.newPlot(gd, [], {})
537-
.then(function() {
538-
expect(gd._context.plotlyServerURL).not.toBe('https://plot.ly');
539-
expect(gd._context.plotlyServerURL).not.toBe('https://chart-studio.plotly.com');
540-
expect(gd._context.plotlyServerURL).toBe('');
541-
542-
Plotly.Plots.sendDataToCloud(gd);
543-
expect(form).toBe(undefined);
544-
})
545-
.then(done, done.fail);
528+
it('should default to an empty string', async() => {
529+
await Plotly.newPlot(gd, [], {});
530+
expect(gd._context.plotlyServerURL).toBe('');
546531
});
547532

548-
it('should be able to connect to Chart Studio Cloud when set to https://chart-studio.plotly.com', function(done) {
549-
Plotly.newPlot(gd, [], {}, {
550-
plotlyServerURL: 'https://chart-studio.plotly.com'
551-
})
552-
.then(function() {
553-
expect(gd._context.plotlyServerURL).toBe('https://chart-studio.plotly.com');
554-
555-
Plotly.Plots.sendDataToCloud(gd);
556-
expect(form.action).toBe('https://chart-studio.plotly.com/external');
557-
expect(form.method).toBe('post');
558-
})
559-
.then(done, done.fail);
533+
it('can be configured via the config argument', async() => {
534+
await Plotly.newPlot(gd, [], {}, { plotlyServerURL: 'https://cloud.plotly.com' });
535+
expect(gd._context.plotlyServerURL).toBe('https://cloud.plotly.com');
560536
});
537+
});
561538

562-
it('can be set to other base urls', function(done) {
563-
Plotly.newPlot(gd, [], {}, {plotlyServerURL: 'dummy'})
564-
.then(function() {
565-
expect(gd._context.plotlyServerURL).toBe('dummy');
539+
describe('Plotly.Plots.sendDataToCloud', function() {
540+
let gd;
541+
let openSpy;
566542

567-
Plotly.Plots.sendDataToCloud(gd);
568-
expect(form.action).toContain('/dummy/external');
569-
expect(form.method).toBe('post');
570-
})
571-
.then(done, done.fail);
543+
beforeEach(() => {
544+
gd = createGraphDiv();
545+
openSpy = spyOn(window, 'open').and.returnValue({ postMessage: () => {} });
572546
});
547+
afterEach(destroyGraphDiv);
573548

574-
it('has lesser priotiy then window env', function(done) {
575-
window.PLOTLYENV = {BASE_URL: 'yo'};
576-
577-
Plotly.newPlot(gd, [], {}, {plotlyServerURL: 'dummy'})
578-
.then(function() {
579-
expect(gd._context.plotlyServerURL).toBe('dummy');
549+
it('opens the given serverURL in a new tab', async() => {
550+
await Plotly.newPlot(gd, [], {});
551+
Plotly.Plots.sendDataToCloud(gd, 'https://cloud.plotly.com');
552+
expect(openSpy).toHaveBeenCalledWith('https://cloud.plotly.com', '_blank');
553+
});
580554

581-
Plotly.Plots.sendDataToCloud(gd);
582-
expect(form.action).toContain('/yo/external');
583-
expect(form.method).toBe('post');
584-
})
585-
.catch(failTest)
586-
.then(function() {
587-
delete window.PLOTLY_ENV;
588-
done();
589-
});
555+
it('emits plotly_exportfail when the popup is blocked', async() => {
556+
openSpy.and.returnValue(null);
557+
let failed = false;
558+
await Plotly.newPlot(gd, [], {});
559+
gd.on('plotly_exportfail', () => { failed = true; });
560+
Plotly.Plots.sendDataToCloud(gd, 'https://cloud.plotly.com');
561+
expect(failed).toBe(true);
590562
});
591563
});
592564

0 commit comments

Comments
 (0)