mirror of
https://github.com/apache/superset.git
synced 2026-04-17 23:25:05 +00:00
[superset-client][datasource editor] replace ajax with SupersetClient (#6134)
* [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
This commit is contained in:
@@ -2,7 +2,8 @@ import React from 'react';
|
||||
import { Modal } from 'react-bootstrap';
|
||||
import configureStore from 'redux-mock-store';
|
||||
import { shallow } from 'enzyme';
|
||||
import $ from 'jquery';
|
||||
import fetchMock from 'fetch-mock';
|
||||
import thunk from 'redux-thunk';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import DatasourceModal from '../../../src/datasource/DatasourceModal';
|
||||
@@ -13,31 +14,30 @@ const props = {
|
||||
datasource: mockDatasource['7__table'],
|
||||
addSuccessToast: () => {},
|
||||
addDangerToast: () => {},
|
||||
onChange: sinon.spy(),
|
||||
onChange: () => {},
|
||||
show: true,
|
||||
onHide: () => {},
|
||||
onDatasourceSave: sinon.spy(),
|
||||
};
|
||||
|
||||
const SAVE_ENDPOINT = 'glob:*/datasource/save/';
|
||||
const SAVE_PAYLOAD = { new: 'data' };
|
||||
|
||||
describe('DatasourceModal', () => {
|
||||
const mockStore = configureStore([]);
|
||||
const mockStore = configureStore([thunk]);
|
||||
const store = mockStore({});
|
||||
fetchMock.post(SAVE_ENDPOINT, SAVE_PAYLOAD);
|
||||
|
||||
let wrapper;
|
||||
let el;
|
||||
let ajaxStub;
|
||||
let inst;
|
||||
|
||||
beforeEach(() => {
|
||||
ajaxStub = sinon.stub($, 'ajax');
|
||||
el = <DatasourceModal {...props} />;
|
||||
wrapper = shallow(el, { context: { store } }).dive();
|
||||
inst = wrapper.instance();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
ajaxStub.restore();
|
||||
});
|
||||
|
||||
it('is valid', () => {
|
||||
expect(React.isValidElement(el)).toBe(true);
|
||||
});
|
||||
@@ -50,8 +50,13 @@ describe('DatasourceModal', () => {
|
||||
expect(wrapper.find(DatasourceEditor)).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('saves on confirm', () => {
|
||||
it('saves on confirm', (done) => {
|
||||
inst.onConfirmSave();
|
||||
expect(ajaxStub.calledOnce).toBe(true);
|
||||
setTimeout(() => {
|
||||
expect(fetchMock.calls(SAVE_ENDPOINT)).toHaveLength(1);
|
||||
expect(props.onDatasourceSave.getCall(0).args[0]).toEqual(SAVE_PAYLOAD);
|
||||
fetchMock.reset();
|
||||
done();
|
||||
}, 0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user