Skip to content

Add plotlyServerUrl to baseUrl #2760

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 27, 2018
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();
});
});
});
});