Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions test/jasmine/tests/config_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,13 @@ describe('config argument', function() {

describe('plotlyServerUrl:', function() {
var gd;
var form;

beforeEach(function() {
gd = createGraphDiv();
spyOn(HTMLFormElement.prototype, 'submit').and.callFake(function() {
form = this;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you @alexcjohnson for the tip!

});
});

afterEach(destroyGraphDiv);
Expand All @@ -485,6 +489,10 @@ describe('config argument', function() {
Plotly.plot(gd, [], {})
.then(function() {
expect(gd._context.plotlyServerUrl).toBe('https://plot.ly');

Plotly.Plots.sendDataToCloud(gd);
expect(form.action).toBe('https://plot.ly/external');
expect(form.method).toBe('post');
})
.catch(failTest)
.then(done);
Expand All @@ -494,9 +502,31 @@ describe('config argument', function() {
Plotly.plot(gd, [], {}, {plotlyServerUrl: 'dummy'})
.then(function() {
expect(gd._context.plotlyServerUrl).toBe('dummy');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests aren't great, but I couldn't find an easy way to mock the form submit in

plots.sendDataToCloud = function(gd) {
gd.emit('plotly_beforeexport');
var baseUrl = (window.PLOTLYENV && window.PLOTLYENV.BASE_URL) || 'https://plot.ly';
var hiddenformDiv = d3.select(gd)
.append('div')
.attr('id', 'hiddenform')
.style('display', 'none');
var hiddenform = hiddenformDiv
.append('form')
.attr({
action: baseUrl + '/external',
method: 'post',
target: '_blank'
});
var hiddenformInput = hiddenform
.append('input')
.attr({
type: 'text',
name: 'data'
});
hiddenformInput.node().value = plots.graphJson(gd, false, 'keepdata');
hiddenform.node().submit();
hiddenformDiv.remove();
gd.emit('plotly_afterexport');
return false;
};


Plotly.Plots.sendDataToCloud(gd);
expect(form.action).toContain('/dummy/external');
expect(form.method).toBe('post');
})
.catch(failTest)
.then(done);
});

it('has lesser priotiy then window env', function(done) {
window.PLOTLYENV = {BASE_URL: 'yo'};

Plotly.plot(gd, [], {}, {plotlyServerUrl: 'dummy'})
.then(function() {
expect(gd._context.plotlyServerUrl).toBe('dummy');

Plotly.Plots.sendDataToCloud(gd);
expect(form.action).toContain('/yo/external');
expect(form.method).toBe('post');
})
.catch(failTest)
.then(function() {
delete window.PLOTLY_ENV;
done();
});
});
});
});