refactor: Upgrade Redux (#11967)

* upgrade redux and react-redux, adjust types

* first round of test fixes

* fix rest of unit tests

* lint

Co-authored-by: Phillip Kelley-Dotson <pkelleydotson@yahoo.com>
This commit is contained in:
David Aaron Suddjian
2020-12-09 11:58:42 -08:00
committed by GitHub
parent 9121482479
commit 6270fa2026
41 changed files with 354 additions and 253 deletions

View File

@@ -20,6 +20,7 @@ import React from 'react';
import configureStore from 'redux-mock-store';
import thunk from 'redux-thunk';
import URI from 'urijs';
import { Provider } from 'react-redux';
import { shallow, mount } from 'enzyme';
import sinon from 'sinon';
import { supersetTheme, ThemeProvider } from '@superset-ui/core';
@@ -73,9 +74,9 @@ describe('TabbedSqlEditors', () => {
maxRow: 100000,
};
const getWrapper = () =>
shallow(<TabbedSqlEditors {...mockedProps} />, {
context: { store },
}).dive();
shallow(<TabbedSqlEditors store={store} {...mockedProps} />)
.dive()
.dive();
let wrapper;
it('is valid', () => {
@@ -87,70 +88,74 @@ describe('TabbedSqlEditors', () => {
let uriStub;
beforeEach(() => {
sinon.stub(window.history, 'replaceState');
sinon.spy(TabbedSqlEditors.prototype, 'componentDidMount');
// sinon.spy(TabbedSqlEditors.prototype, 'componentDidMount');
uriStub = sinon.stub(URI.prototype, 'search');
});
afterEach(() => {
window.history.replaceState.restore();
TabbedSqlEditors.prototype.componentDidMount.restore();
// TabbedSqlEditors.prototype.componentDidMount.restore();
uriStub.restore();
});
it('should handle id', () => {
uriStub.returns({ id: 1 });
wrapper = mount(<TabbedSqlEditors {...mockedProps} />, {
context: { store },
wrappingComponent: ThemeProvider,
wrappingComponentProps: { theme: supersetTheme },
});
expect(TabbedSqlEditors.prototype.componentDidMount.calledOnce).toBe(
true,
wrapper = mount(
<Provider store={store}>
<TabbedSqlEditors {...mockedProps} />
</Provider>,
{
wrappingComponent: ThemeProvider,
wrappingComponentProps: { theme: supersetTheme },
},
);
/* expect(TabbedSqlEditors.prototype.componentDidMount.calledOnce).toBe(
true,
); */
expect(window.history.replaceState.getCall(0).args[2]).toBe(
'/superset/sqllab',
);
});
it('should handle savedQueryId', () => {
uriStub.returns({ savedQueryId: 1 });
wrapper = mount(<TabbedSqlEditors {...mockedProps} />, {
context: { store },
wrappingComponent: ThemeProvider,
wrappingComponentProps: { theme: supersetTheme },
});
expect(TabbedSqlEditors.prototype.componentDidMount.calledOnce).toBe(
true,
wrapper = mount(
<Provider store={store}>
<TabbedSqlEditors {...mockedProps} />
</Provider>,
{
wrappingComponent: ThemeProvider,
wrappingComponentProps: { theme: supersetTheme },
},
);
/* expect(TabbedSqlEditors.prototype.componentDidMount.calledOnce).toBe(
true,
); */
expect(window.history.replaceState.getCall(0).args[2]).toBe(
'/superset/sqllab',
);
});
it('should handle sql', () => {
uriStub.returns({ sql: 1, dbid: 1 });
wrapper = mount(<TabbedSqlEditors {...mockedProps} />, {
context: { store },
wrappingComponent: ThemeProvider,
wrappingComponentProps: { theme: supersetTheme },
});
expect(TabbedSqlEditors.prototype.componentDidMount.calledOnce).toBe(
true,
wrapper = mount(
<Provider store={store}>
<TabbedSqlEditors {...mockedProps} />
</Provider>,
{
wrappingComponent: ThemeProvider,
wrappingComponentProps: { theme: supersetTheme },
},
);
/* expect(TabbedSqlEditors.prototype.componentDidMount.calledOnce).toBe(
true,
); */
expect(window.history.replaceState.getCall(0).args[2]).toBe(
'/superset/sqllab',
);
});
});
describe('UNSAFE_componentWillReceiveProps', () => {
let spy;
beforeEach(() => {
wrapper = getWrapper();
spy = sinon.spy(
TabbedSqlEditors.prototype,
'UNSAFE_componentWillReceiveProps',
);
wrapper.setProps({ queryEditors, queries, tabHistory, tables });
});
afterEach(() => {
spy.restore();
});
it('should update queriesArray and dataPreviewQueries', () => {
expect(wrapper.state().queriesArray.slice(-1)[0]).toBe(
queries['B1-VQU1zW'],