mirror of
https://github.com/apache/superset.git
synced 2026-04-18 07:35:09 +00:00
[explore] DatasourceControl to pick datasource in modal (#3210)
* [explore] DatasourceControl to pick datasource in modal Makes it easier to change datasource, also makes it such that the list of all datasources doesn't need to be loaded upfront. * Adding more metadata
This commit is contained in:
committed by
GitHub
parent
48821b5101
commit
62fcdf2a92
@@ -0,0 +1,32 @@
|
||||
import React from 'react';
|
||||
import sinon from 'sinon';
|
||||
import { expect } from 'chai';
|
||||
import { describe, it, beforeEach } from 'mocha';
|
||||
import { shallow } from 'enzyme';
|
||||
import { Modal } from 'react-bootstrap';
|
||||
import DatasourceControl from '../../../../javascripts/explore/components/controls/DatasourceControl';
|
||||
|
||||
const defaultProps = {
|
||||
name: 'datasource',
|
||||
label: 'Datasource',
|
||||
value: '1__table',
|
||||
datasource: {
|
||||
name: 'birth_names',
|
||||
type: 'table',
|
||||
uid: '1__table',
|
||||
id: 1,
|
||||
},
|
||||
onChange: sinon.spy(),
|
||||
};
|
||||
|
||||
describe('DatasourceControl', () => {
|
||||
let wrapper;
|
||||
|
||||
beforeEach(() => {
|
||||
wrapper = shallow(<DatasourceControl {...defaultProps} />);
|
||||
});
|
||||
|
||||
it('renders a Modal', () => {
|
||||
expect(wrapper.find(Modal)).to.have.lengthOf(1);
|
||||
});
|
||||
});
|
||||
@@ -82,44 +82,6 @@ describe('fetching actions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchDatasources', () => {
|
||||
const makeRequest = () => {
|
||||
request = actions.fetchDatasources();
|
||||
request(dispatch);
|
||||
};
|
||||
|
||||
it('calls fetchDatasourcesStarted', () => {
|
||||
makeRequest();
|
||||
expect(dispatch.args[0][0].type).to.equal(actions.FETCH_DATASOURCES_STARTED);
|
||||
});
|
||||
|
||||
it('makes the ajax request', () => {
|
||||
makeRequest();
|
||||
expect(ajaxStub.calledOnce).to.be.true;
|
||||
});
|
||||
|
||||
it('calls correct url', () => {
|
||||
const url = '/superset/datasources/';
|
||||
makeRequest();
|
||||
expect(ajaxStub.getCall(0).args[0].url).to.equal(url);
|
||||
});
|
||||
|
||||
it('calls correct actions on error', () => {
|
||||
ajaxStub.yieldsTo('error', { responseJSON: { error: 'error text' } });
|
||||
makeRequest();
|
||||
expect(dispatch.callCount).to.equal(2);
|
||||
expect(dispatch.getCall(1).args[0].type).to.equal(actions.FETCH_DATASOURCES_FAILED);
|
||||
});
|
||||
|
||||
it('calls correct actions on success', () => {
|
||||
ajaxStub.yieldsTo('success', { data: '' });
|
||||
makeRequest();
|
||||
expect(dispatch.callCount).to.equal(3);
|
||||
expect(dispatch.getCall(1).args[0].type).to.equal(actions.SET_DATASOURCES);
|
||||
expect(dispatch.getCall(2).args[0].type).to.equal(actions.FETCH_DATASOURCES_SUCCEEDED);
|
||||
});
|
||||
});
|
||||
|
||||
describe('fetchDashboards', () => {
|
||||
const userID = 1;
|
||||
const mockDashboardData = {
|
||||
|
||||
Reference in New Issue
Block a user