mirror of
https://github.com/apache/superset.git
synced 2026-04-08 19:05:46 +00:00
* [superset-client][datasource editor] replace ajax with SupersetClient * [superset-client][datasource control] replace ajax with SupersetClient * [superset-client][datasource editor] remove unused funcs in DatasourceControl * [superset-client][data source control] lint, remove toasts * [superset-client] fix DatasourceControl_spec * [superset-client] remove unneeded functional setState calls
63 lines
1.6 KiB
JavaScript
63 lines
1.6 KiB
JavaScript
import React from 'react';
|
|
import { Modal } from 'react-bootstrap';
|
|
import configureStore from 'redux-mock-store';
|
|
import { shallow } from 'enzyme';
|
|
import fetchMock from 'fetch-mock';
|
|
import thunk from 'redux-thunk';
|
|
import sinon from 'sinon';
|
|
|
|
import DatasourceModal from '../../../src/datasource/DatasourceModal';
|
|
import DatasourceEditor from '../../../src/datasource/DatasourceEditor';
|
|
import mockDatasource from '../../fixtures/mockDatasource';
|
|
|
|
const props = {
|
|
datasource: mockDatasource['7__table'],
|
|
addSuccessToast: () => {},
|
|
addDangerToast: () => {},
|
|
onChange: () => {},
|
|
show: true,
|
|
onHide: () => {},
|
|
onDatasourceSave: sinon.spy(),
|
|
};
|
|
|
|
const SAVE_ENDPOINT = 'glob:*/datasource/save/';
|
|
const SAVE_PAYLOAD = { new: 'data' };
|
|
|
|
describe('DatasourceModal', () => {
|
|
const mockStore = configureStore([thunk]);
|
|
const store = mockStore({});
|
|
fetchMock.post(SAVE_ENDPOINT, SAVE_PAYLOAD);
|
|
|
|
let wrapper;
|
|
let el;
|
|
let inst;
|
|
|
|
beforeEach(() => {
|
|
el = <DatasourceModal {...props} />;
|
|
wrapper = shallow(el, { context: { store } }).dive();
|
|
inst = wrapper.instance();
|
|
});
|
|
|
|
it('is valid', () => {
|
|
expect(React.isValidElement(el)).toBe(true);
|
|
});
|
|
|
|
it('renders a Modal', () => {
|
|
expect(wrapper.find(Modal)).toHaveLength(1);
|
|
});
|
|
|
|
it('renders a DatasourceEditor', () => {
|
|
expect(wrapper.find(DatasourceEditor)).toHaveLength(1);
|
|
});
|
|
|
|
it('saves on confirm', (done) => {
|
|
inst.onConfirmSave();
|
|
setTimeout(() => {
|
|
expect(fetchMock.calls(SAVE_ENDPOINT)).toHaveLength(1);
|
|
expect(props.onDatasourceSave.getCall(0).args[0]).toEqual(SAVE_PAYLOAD);
|
|
fetchMock.reset();
|
|
done();
|
|
}, 0);
|
|
});
|
|
});
|