get rid of global notify (#5355)

* [toasts] get rid of notify globals, refactor messageToasts for use by entire app

* [remove notify] use arrow func in ajax call

* fix lint + tests

* actually fix tests from messageToast refactor

* add 'test:one' npm script

* debugger

* [toasts] convert bootstrap flash messages to toasts in explore + sqllab

* [toasts][tests] import from right file
This commit is contained in:
Chris Williams
2018-07-12 11:50:25 -07:00
committed by GitHub
parent f9352af80e
commit 19ac6e1231
72 changed files with 657 additions and 524 deletions

View File

@@ -17,17 +17,16 @@ import { VISUALIZE_VALIDATION_ERRORS } from '../../../src/SqlLab/constants';
import VisualizeModal from '../../../src/SqlLab/components/VisualizeModal';
import * as exploreUtils from '../../../src/explore/exploreUtils';
global.notify = {
info: () => {},
error: () => {},
};
describe('VisualizeModal', () => {
const middlewares = [thunk];
const mockStore = configureStore(middlewares);
const initialState = sqlLabReducer({}, {});
initialState.common = {
conf: { SUPERSET_WEBSERVER_TIMEOUT: 45 },
const initialState = {
sqlLab: {
...sqlLabReducer(undefined, {}),
common: {
conf: { SUPERSET_WEBSERVER_TIMEOUT: 45 },
},
},
};
const store = mockStore(initialState);
const mockedProps = {
@@ -277,7 +276,7 @@ describe('VisualizeModal', () => {
});
it('should build visualize advise for long query', () => {
const longQuery = Object.assign({}, queries[0], { endDttm: 1476910666798 });
const longQuery = { ...queries[0], endDttm: 1476910666798 };
const props = {
show: true,
query: longQuery,
@@ -334,29 +333,46 @@ describe('VisualizeModal', () => {
expect(spyCall.args[0].data.data).to.equal(JSON.stringify(mockOptions));
});
it('should open new window', () => {
const infoToastSpy = sinon.spy();
datasourceSpy.callsFake(() => {
const d = $.Deferred();
d.resolve('done');
return d.promise();
});
wrapper.setProps({ actions: { createDatasource: datasourceSpy } });
wrapper.setProps({
actions: {
createDatasource: datasourceSpy,
addInfoToast: infoToastSpy,
},
});
wrapper.instance().visualize();
expect(exploreUtils.exportChart.callCount).to.equal(1);
expect(exploreUtils.exportChart.getCall(0).args[0].datasource).to.equal('107__table');
expect(infoToastSpy.callCount).to.equal(1);
});
it('should notify error', () => {
it('should add error toast', () => {
const dangerToastSpy = sinon.spy();
datasourceSpy.callsFake(() => {
const d = $.Deferred();
d.reject('error message');
return d.promise();
});
wrapper.setProps({ actions: { createDatasource: datasourceSpy } });
sinon.spy(notify, 'error');
wrapper.setProps({
actions: {
createDatasource: datasourceSpy,
addDangerToast: dangerToastSpy,
},
});
wrapper.instance().visualize();
expect(exploreUtils.exportChart.callCount).to.equal(0);
expect(notify.error.callCount).to.equal(1);
expect(dangerToastSpy.callCount).to.equal(1);
});
});
});