mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
[Explore view] Use POST method for charting requests (#3993)
* [Explore view] Use POST method for charting requests * fix per code review comments * more code review fixes * code review fix: remove duplicated calls for getting values from request * [Explore view] Use POST method for charting requests * fix per code review comments * more code review fixes * code review fix: remove duplicated calls for getting values from request
This commit is contained in:
@@ -13,7 +13,8 @@ describe('chart actions', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
dispatch = sinon.spy();
|
||||
urlStub = sinon.stub(exploreUtils, 'getExploreUrl').callsFake(() => ('mockURL'));
|
||||
urlStub = sinon.stub(exploreUtils, 'getExploreUrlAndPayload')
|
||||
.callsFake(() => ({ url: 'mockURL', payload: {} }));
|
||||
ajaxStub = sinon.stub($, 'ajax');
|
||||
});
|
||||
|
||||
|
||||
@@ -3,16 +3,14 @@ import { expect } from 'chai';
|
||||
import { describe, it } from 'mocha';
|
||||
import { shallow, mount } from 'enzyme';
|
||||
import { OverlayTrigger } from 'react-bootstrap';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import EmbedCodeButton from '../../../../javascripts/explore/components/EmbedCodeButton';
|
||||
import * as exploreUtils from '../../../../javascripts/explore/exploreUtils';
|
||||
|
||||
describe('EmbedCodeButton', () => {
|
||||
const defaultProps = {
|
||||
slice: {
|
||||
data: {
|
||||
standalone_endpoint: 'endpoint_url',
|
||||
},
|
||||
},
|
||||
latestQueryFormData: { datasource: '107__table' },
|
||||
};
|
||||
|
||||
it('renders', () => {
|
||||
@@ -25,11 +23,11 @@ describe('EmbedCodeButton', () => {
|
||||
});
|
||||
|
||||
it('returns correct embed code', () => {
|
||||
const stub = sinon.stub(exploreUtils, 'getExploreLongUrl').callsFake(() => ('endpoint_url'));
|
||||
const wrapper = mount(<EmbedCodeButton {...defaultProps} />);
|
||||
wrapper.setState({
|
||||
height: '1000',
|
||||
width: '2000',
|
||||
srcLink: 'http://localhost/endpoint_url',
|
||||
});
|
||||
const embedHTML = (
|
||||
'<iframe\n' +
|
||||
@@ -43,5 +41,6 @@ describe('EmbedCodeButton', () => {
|
||||
'</iframe>'
|
||||
);
|
||||
expect(wrapper.instance().generateEmbedHTML()).to.equal(embedHTML);
|
||||
stub.restore();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -38,7 +38,7 @@ describe('SaveModal', () => {
|
||||
const defaultProps = {
|
||||
onHide: () => ({}),
|
||||
actions: saveModalActions,
|
||||
form_data: {},
|
||||
form_data: { datasource: '107__table' },
|
||||
};
|
||||
const mockEvent = {
|
||||
target: {
|
||||
@@ -117,7 +117,7 @@ describe('SaveModal', () => {
|
||||
|
||||
describe('saveOrOverwrite', () => {
|
||||
beforeEach(() => {
|
||||
sinon.stub(exploreUtils, 'getExploreUrl').callsFake(() => ('mockURL'));
|
||||
sinon.stub(exploreUtils, 'getExploreUrlAndPayload').callsFake(() => ({ url: 'mockURL', payload: defaultProps.form_data }));
|
||||
sinon.stub(saveModalActions, 'saveSlice').callsFake(() => {
|
||||
const d = $.Deferred();
|
||||
d.resolve('done');
|
||||
@@ -125,14 +125,15 @@ describe('SaveModal', () => {
|
||||
});
|
||||
});
|
||||
afterEach(() => {
|
||||
exploreUtils.getExploreUrl.restore();
|
||||
exploreUtils.getExploreUrlAndPayload.restore();
|
||||
saveModalActions.saveSlice.restore();
|
||||
});
|
||||
|
||||
it('should save slice', () => {
|
||||
const wrapper = getWrapper();
|
||||
wrapper.instance().saveOrOverwrite(true);
|
||||
expect(saveModalActions.saveSlice.getCall(0).args[0]).to.equal('mockURL');
|
||||
const args = saveModalActions.saveSlice.getCall(0).args;
|
||||
expect(args[0]).to.deep.equal(defaultProps.form_data);
|
||||
});
|
||||
it('existing dashboard', () => {
|
||||
const wrapper = getWrapper();
|
||||
@@ -144,8 +145,8 @@ describe('SaveModal', () => {
|
||||
|
||||
wrapper.setState({ saveToDashboardId });
|
||||
wrapper.instance().saveOrOverwrite(true);
|
||||
const args = exploreUtils.getExploreUrl.getCall(0).args;
|
||||
expect(args[4].save_to_dashboard_id).to.equal(saveToDashboardId);
|
||||
const args = saveModalActions.saveSlice.getCall(0).args;
|
||||
expect(args[1].save_to_dashboard_id).to.equal(saveToDashboardId);
|
||||
});
|
||||
it('new dashboard', () => {
|
||||
const wrapper = getWrapper();
|
||||
@@ -157,8 +158,8 @@ describe('SaveModal', () => {
|
||||
|
||||
wrapper.setState({ newDashboardName });
|
||||
wrapper.instance().saveOrOverwrite(true);
|
||||
const args = exploreUtils.getExploreUrl.getCall(0).args;
|
||||
expect(args[4].new_dashboard_name).to.equal(newDashboardName);
|
||||
const args = saveModalActions.saveSlice.getCall(0).args;
|
||||
expect(args[1].new_dashboard_name).to.equal(newDashboardName);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
import { it, describe } from 'mocha';
|
||||
import { expect } from 'chai';
|
||||
import URI from 'urijs';
|
||||
import { getExploreUrl } from '../../../javascripts/explore/exploreUtils';
|
||||
import { getExploreUrlAndPayload, getExploreLongUrl } from '../../../javascripts/explore/exploreUtils';
|
||||
|
||||
describe('utils', () => {
|
||||
const location = window.location;
|
||||
const formData = {
|
||||
datasource: '1__table',
|
||||
};
|
||||
@@ -12,48 +13,129 @@ describe('utils', () => {
|
||||
expect(uri1.toString()).to.equal(uri2.toString());
|
||||
}
|
||||
|
||||
it('getExploreUrl generates proper base url', () => {
|
||||
// This assertion is to show clearly the value of location.href
|
||||
// in the context of unit tests.
|
||||
expect(location.href).to.equal('about:blank');
|
||||
describe('getExploreUrlAndPayload', () => {
|
||||
it('generates proper base url', () => {
|
||||
// This assertion is to show clearly the value of location.href
|
||||
// in the context of unit tests.
|
||||
expect(location.href).to.equal('about:blank');
|
||||
|
||||
compareURI(
|
||||
URI(getExploreUrl(formData, 'base', false, 'http://superset.com')),
|
||||
URI('/superset/explore/table/1/').search({ form_data: sFormData }),
|
||||
);
|
||||
});
|
||||
it('getExploreUrl generates proper json url', () => {
|
||||
compareURI(
|
||||
URI(getExploreUrl(formData, 'json', false, 'superset.com')),
|
||||
URI('/superset/explore_json/table/1/').search({ form_data: sFormData }),
|
||||
);
|
||||
});
|
||||
it('getExploreUrl generates proper json forced url', () => {
|
||||
compareURI(
|
||||
URI(getExploreUrl(formData, 'json', true, 'superset.com')),
|
||||
const { url, payload } = getExploreUrlAndPayload({
|
||||
formData,
|
||||
endpointType: 'base',
|
||||
force: false,
|
||||
curUrl: 'http://superset.com',
|
||||
});
|
||||
compareURI(
|
||||
URI(url),
|
||||
URI('/superset/explore/table/1/'),
|
||||
);
|
||||
expect(payload).to.deep.equals(formData);
|
||||
});
|
||||
it('generates proper json url', () => {
|
||||
const { url, payload } = getExploreUrlAndPayload({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
force: false,
|
||||
curUrl: 'http://superset.com',
|
||||
});
|
||||
compareURI(
|
||||
URI(url),
|
||||
URI('/superset/explore_json/table/1/'),
|
||||
);
|
||||
expect(payload).to.deep.equals(formData);
|
||||
});
|
||||
it('generates proper json forced url', () => {
|
||||
const { url, payload } = getExploreUrlAndPayload({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
force: true,
|
||||
curUrl: 'superset.com',
|
||||
});
|
||||
compareURI(
|
||||
URI(url),
|
||||
URI('/superset/explore_json/table/1/')
|
||||
.search({ form_data: sFormData, force: 'true' }),
|
||||
);
|
||||
});
|
||||
it('getExploreUrl generates proper csv URL', () => {
|
||||
compareURI(
|
||||
URI(getExploreUrl(formData, 'csv', false, 'superset.com')),
|
||||
.search({ force: 'true' }),
|
||||
);
|
||||
expect(payload).to.deep.equals(formData);
|
||||
});
|
||||
it('generates proper csv URL', () => {
|
||||
const { url, payload } = getExploreUrlAndPayload({
|
||||
formData,
|
||||
endpointType: 'csv',
|
||||
force: false,
|
||||
curUrl: 'superset.com',
|
||||
});
|
||||
compareURI(
|
||||
URI(url),
|
||||
URI('/superset/explore_json/table/1/')
|
||||
.search({ form_data: sFormData, csv: 'true' }),
|
||||
);
|
||||
});
|
||||
it('getExploreUrl generates proper standalone URL', () => {
|
||||
compareURI(
|
||||
URI(getExploreUrl(formData, 'standalone', false, 'superset.com')),
|
||||
.search({ csv: 'true' }),
|
||||
);
|
||||
expect(payload).to.deep.equals(formData);
|
||||
});
|
||||
it('generates proper standalone URL', () => {
|
||||
const { url, payload } = getExploreUrlAndPayload({
|
||||
formData,
|
||||
endpointType: 'standalone',
|
||||
force: false,
|
||||
curUrl: 'superset.com',
|
||||
});
|
||||
compareURI(
|
||||
URI(url),
|
||||
URI('/superset/explore/table/1/')
|
||||
.search({ form_data: sFormData, standalone: 'true' }),
|
||||
);
|
||||
});
|
||||
it('getExploreUrl preserves main URLs params', () => {
|
||||
compareURI(
|
||||
URI(getExploreUrl(formData, 'json', false, 'superset.com?foo=bar')),
|
||||
.search({ standalone: 'true' }),
|
||||
);
|
||||
expect(payload).to.deep.equals(formData);
|
||||
});
|
||||
it('preserves main URLs params', () => {
|
||||
const { url, payload } = getExploreUrlAndPayload({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
force: false,
|
||||
curUrl: 'superset.com?foo=bar',
|
||||
});
|
||||
compareURI(
|
||||
URI(url),
|
||||
URI('/superset/explore_json/table/1/')
|
||||
.search({ foo: 'bar', form_data: sFormData }),
|
||||
);
|
||||
.search({ foo: 'bar' }),
|
||||
);
|
||||
expect(payload).to.deep.equals(formData);
|
||||
});
|
||||
it('generate proper save slice url', () => {
|
||||
const { url, payload } = getExploreUrlAndPayload({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
force: false,
|
||||
curUrl: 'superset.com?foo=bar',
|
||||
});
|
||||
compareURI(
|
||||
URI(url),
|
||||
URI('/superset/explore_json/table/1/')
|
||||
.search({ foo: 'bar' }),
|
||||
);
|
||||
expect(payload).to.deep.equals(formData);
|
||||
});
|
||||
it('generate proper saveas slice url', () => {
|
||||
const { url, payload } = getExploreUrlAndPayload({
|
||||
formData,
|
||||
endpointType: 'json',
|
||||
force: false,
|
||||
curUrl: 'superset.com?foo=bar',
|
||||
});
|
||||
compareURI(
|
||||
URI(url),
|
||||
URI('/superset/explore_json/table/1/')
|
||||
.search({ foo: 'bar' }),
|
||||
);
|
||||
expect(payload).to.deep.equals(formData);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getExploreLongUrl', () => {
|
||||
it('generates proper base url with form_data', () => {
|
||||
compareURI(
|
||||
URI(getExploreLongUrl(formData, 'base')),
|
||||
URI('/superset/explore/table/1/').search({ form_data: sFormData }),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user