-
Notifications
You must be signed in to change notification settings - Fork 14.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[superset-client] replace misc ajax calls (#6135)
* [superset-client][misc] replace ajax calls in DashboardTable, TableLoader, utils, common * [superset-client][misc] replace ajax calls in AsyncSelect, HeaderActions, Deck.gl * [superset-client][misc] fix tests * [superset-client] remove unneeded functional setState calls * [superset-client] make welcome a redux app for toasts * [superset-client] make Profile a redux app for toasts * [superset-client] TableLoader don't pass toast props to dom nodes * tweak deckgl Multi syntax
- Loading branch information
1 parent
96228ad
commit a71e6eb
Showing
16 changed files
with
300 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 11 additions & 8 deletions
19
superset/assets/spec/javascripts/profile/CreatedContent_spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { shallow } from 'enzyme'; | ||
import thunk from 'redux-thunk'; | ||
import configureStore from 'redux-mock-store'; | ||
|
||
import { user } from './fixtures'; | ||
import CreatedContent from '../../../src/profile/components/CreatedContent'; | ||
import TableLoader from '../../../src/components/TableLoader'; | ||
|
||
// store needed for withToasts(TableLoader) | ||
const mockStore = configureStore([thunk]); | ||
const store = mockStore({}); | ||
|
||
describe('CreatedContent', () => { | ||
const mockedProps = { | ||
user, | ||
}; | ||
it('is valid', () => { | ||
expect( | ||
React.isValidElement(<CreatedContent {...mockedProps} />), | ||
).toBe(true); | ||
}); | ||
|
||
it('renders 2 TableLoader', () => { | ||
const wrapper = mount(<CreatedContent {...mockedProps} />); | ||
const wrapper = shallow(<CreatedContent {...mockedProps} />, { context: { store } }); | ||
expect(wrapper.find(TableLoader)).toHaveLength(2); | ||
}); | ||
|
||
it('renders 2 titles', () => { | ||
const wrapper = mount(<CreatedContent {...mockedProps} />); | ||
const wrapper = shallow(<CreatedContent {...mockedProps} />, { context: { store } }); | ||
expect(wrapper.find('h3')).toHaveLength(2); | ||
}); | ||
}); |
19 changes: 11 additions & 8 deletions
19
superset/assets/spec/javascripts/profile/Favorites_spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,28 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import { shallow } from 'enzyme'; | ||
import thunk from 'redux-thunk'; | ||
import configureStore from 'redux-mock-store'; | ||
|
||
import { user } from './fixtures'; | ||
import Favorites from '../../../src/profile/components/Favorites'; | ||
import TableLoader from '../../../src/components/TableLoader'; | ||
|
||
// store needed for withToasts(TableLoader) | ||
const mockStore = configureStore([thunk]); | ||
const store = mockStore({}); | ||
|
||
describe('Favorites', () => { | ||
const mockedProps = { | ||
user, | ||
}; | ||
it('is valid', () => { | ||
expect( | ||
React.isValidElement(<Favorites {...mockedProps} />), | ||
).toBe(true); | ||
}); | ||
|
||
it('renders 2 TableLoader', () => { | ||
const wrapper = mount(<Favorites {...mockedProps} />); | ||
const wrapper = shallow(<Favorites {...mockedProps} />, { context: { store } }); | ||
expect(wrapper.find(TableLoader)).toHaveLength(2); | ||
}); | ||
|
||
it('renders 2 titles', () => { | ||
const wrapper = mount(<Favorites {...mockedProps} />); | ||
const wrapper = shallow(<Favorites {...mockedProps} />, { context: { store } }); | ||
expect(wrapper.find('h3')).toHaveLength(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 35 additions & 18 deletions
53
superset/assets/spec/javascripts/welcome/DashboardTable_spec.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,47 @@ | ||
import React from 'react'; | ||
import { mount } from 'enzyme'; | ||
import sinon from 'sinon'; | ||
import thunk from 'redux-thunk'; | ||
import configureStore from 'redux-mock-store'; | ||
import fetchMock from 'fetch-mock'; | ||
import { Table } from 'reactable'; | ||
|
||
import DashboardTable from '../../../src/welcome/DashboardTable'; | ||
import Loading from '../../../src/components/Loading'; | ||
|
||
const $ = window.$ = require('jquery'); | ||
// store needed for withToasts(TableLoader) | ||
const mockStore = configureStore([thunk]); | ||
const store = mockStore({}); | ||
|
||
const dashboardsEndpoint = 'glob:*/dashboardasync/api/read*'; | ||
const mockDashboards = [ | ||
{ id: 1, url: 'url', dashboard_title: 'title' }, | ||
]; | ||
|
||
fetchMock.get(dashboardsEndpoint, { result: mockDashboards }); | ||
|
||
function setup() { | ||
// use mount because data fetching is triggered on mount | ||
return mount(<DashboardTable />, { context: { store } }); | ||
} | ||
|
||
describe('DashboardTable', () => { | ||
const mockedProps = {}; | ||
let stub; | ||
beforeEach(() => { | ||
stub = sinon.stub($, 'getJSON'); | ||
}); | ||
afterEach(() => { | ||
stub.restore(); | ||
}); | ||
afterEach(fetchMock.resetHistory); | ||
|
||
it('is valid', () => { | ||
expect( | ||
React.isValidElement(<DashboardTable {...mockedProps} />), | ||
).toBe(true); | ||
it('renders a Loading initially', () => { | ||
const wrapper = setup(); | ||
expect(wrapper.find(Loading)).toHaveLength(1); | ||
}); | ||
it('renders', () => { | ||
const wrapper = mount(<DashboardTable {...mockedProps} />); | ||
expect(stub.callCount).toBe(1); | ||
expect(wrapper.find('img')).toHaveLength(1); | ||
|
||
it('fetches dashboards and renders a Table', (done) => { | ||
const wrapper = setup(); | ||
|
||
setTimeout(() => { | ||
expect(fetchMock.calls(dashboardsEndpoint)).toHaveLength(1); | ||
// there's a delay between response and updating state, so manually set it | ||
// rather than adding a timeout which could introduce flakiness | ||
wrapper.setState({ dashaboards: mockDashboards }); | ||
expect(wrapper.find(Table)).toHaveLength(1); | ||
done(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.