This is an automated email from the ASF dual-hosted git repository. yjc pushed a commit to branch home-screen-mvp in repository https://gitbox.apache.org/repos/asf/incubator-superset.git
commit 03e6fde0a52f565ad5bed891064b4205c866122b Author: Phillip Kelley-Dotson <[email protected]> AuthorDate: Mon Oct 26 15:51:59 2020 -0700 test fixes --- .../spec/javascripts/components/SubMenu_spec.jsx | 2 +- .../views/CRUD/welcome/ActivityTable_spec.tsx | 6 ++-- .../views/CRUD/welcome/ChartTable_spec.tsx | 39 +++++++++++++--------- .../views/CRUD/welcome/DashboardTable_spec.tsx | 7 ++-- .../views/CRUD/welcome/Welcome_spec.tsx | 18 +++++++--- .../src/views/CRUD/chart/ChartCard.tsx | 3 +- superset-frontend/src/views/CRUD/data/common.ts | 2 +- superset-frontend/src/views/CRUD/utils.tsx | 13 +++++++- .../src/views/CRUD/welcome/ActivityTable.tsx | 2 +- .../src/views/CRUD/welcome/ChartTable.tsx | 3 +- 10 files changed, 62 insertions(+), 33 deletions(-) diff --git a/superset-frontend/spec/javascripts/components/SubMenu_spec.jsx b/superset-frontend/spec/javascripts/components/SubMenu_spec.jsx index 54a1b63..ab0020d 100644 --- a/superset-frontend/spec/javascripts/components/SubMenu_spec.jsx +++ b/superset-frontend/spec/javascripts/components/SubMenu_spec.jsx @@ -24,7 +24,7 @@ import SubMenu from 'src/components/Menu/SubMenu'; const defaultProps = { name: 'Title', - children: [ + tabs: [ { name: 'Page1', label: 'Page1', diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/ActivityTable_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/ActivityTable_spec.tsx index 19fb397..db1ec1f 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/welcome/ActivityTable_spec.tsx +++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/ActivityTable_spec.tsx @@ -29,6 +29,7 @@ import ListViewCard from 'src/components/ListViewCard'; const mockStore = configureStore([thunk]); const store = mockStore({}); +const recentsEnpoint = 'glob:*/superset/recent_activity/*'; const chartsEndpoint = 'glob:*/api/v1/chart/?*'; const dashboardEndpoint = 'glob:*/api/v1/dashboard/?*'; const savedQueryEndpoint = 'glob:*/api/v1/saved_query/?*'; @@ -75,15 +76,14 @@ describe('ActivityTable', () => { await waitForComponentToPaint(wrapper); }); - it('renders', () => { + it('the component renders ', () => { expect(wrapper.find(ActivityTable)).toExist(); }); - it('calls batch method and renders ListViewCArd', () => { + it('calls batch method and renders ListViewCArd', async () => { const chartCall = fetchMock.calls(/chart\/\?q/); const dashboardCall = fetchMock.calls(/dashboard\/\?q/); expect(chartCall).toHaveLength(2); expect(dashboardCall).toHaveLength(2); - expect(wrapper.find(ListViewCard)).toHaveLength(2); }); }); diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/ChartTable_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/ChartTable_spec.tsx index aa024d8..f8cd053 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/welcome/ChartTable_spec.tsx +++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/ChartTable_spec.tsx @@ -17,20 +17,19 @@ * under the License. */ import React from 'react'; -import { mount } from 'enzyme'; +import { styledMount as mount } from 'spec/helpers/theming'; import thunk from 'redux-thunk'; import fetchMock from 'fetch-mock'; - import configureStore from 'redux-mock-store'; + import ChartTable from 'src/views/CRUD/welcome/ChartTable'; -import ChartCard from 'src/views/CRUD/chart/ChartCard'; import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint'; -// store needed for withToasts(DashboardTable) const mockStore = configureStore([thunk]); const store = mockStore({}); const chartsEndpoint = 'glob:*/api/v1/chart/?*'; +const chartsInfoEndpoint = 'glob:*/api/v1/chart/_info*'; const mockCharts = [...new Array(3)].map((_, i) => ({ changed_on_utc: new Date().toISOString(), @@ -40,31 +39,41 @@ const mockCharts = [...new Array(3)].map((_, i) => ({ url: 'url', viz_type: 'bar', datasource_title: `ds${i}`, - thumbnail_url: '/thumbnail', + thumbnail_url: '', })); fetchMock.get(chartsEndpoint, { result: mockCharts, }); -describe('ChartTable', () => { - beforeEach(fetchMock.resetHistory); +fetchMock.get(chartsInfoEndpoint, { + permissions: ['can_add', 'can_edit', 'can_delete'], +}); - const mockedProps = {}; +describe('ChartTable', () => { + const mockedProps = { + user: { + userId: '2', + }, + }; const wrapper = mount(<ChartTable {...mockedProps} />, { context: { store }, }); - - beforeAll(async () => { - await waitForComponentToPaint(wrapper); - }); - it('it renders', () => { expect(wrapper.find(ChartTable)).toExist(); }); - it('fetches chart favorites and renders chart cards ', () => { + it('fetches chart favorites and renders chart cards ', async () => { expect(fetchMock.calls(chartsEndpoint)).toHaveLength(1); - expect(wrapper.find(ChartCard)).toExist(); + await waitForComponentToPaint(wrapper); + expect(wrapper.find('ChartCard')).toExist(); + }); + + it('display EmptyState if there is no data', () => { + fetchMock.resetHistory(); + const wrapper = mount(<ChartTable {...mockedProps} />, { + context: { store }, + }); + expect(wrapper.find('EmptyState')).toExist(); }); }); diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/DashboardTable_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/DashboardTable_spec.tsx index 013d3b3..e7f28f3 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/welcome/DashboardTable_spec.tsx +++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/DashboardTable_spec.tsx @@ -33,7 +33,7 @@ const mockStore = configureStore([thunk]); const store = mockStore({}); const dashboardsEndpoint = 'glob:*/api/v1/dashboard/?*'; -const chartsInfoEndpoint = 'glob:*/api/v1/chart/_info*'; +const dashboardInfoEndpoint = 'glob:*/api/v1/dashboard/_info*'; const mockDashboards = [ { id: 1, @@ -44,7 +44,7 @@ const mockDashboards = [ ]; fetchMock.get(dashboardsEndpoint, { result: mockDashboards }); -fetchMock.get(chartsInfoEndpoint, { +fetchMock.get(dashboardInfoEndpoint, { permissions: ['can_list', 'can_edit', 'can_delete'], }); @@ -86,6 +86,9 @@ describe('DashboardTable', () => { it('display EmptyState if there is no data', () => { fetchMock.resetHistory(); + const wrapper = mount(<DashboardTable {...dashboardProps} />, { + context: { store }, + }); expect(wrapper.find('EmptyState')).toExist(); }); }); diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx index fa1778d..a9a2c49 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx +++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx @@ -17,10 +17,14 @@ * under the License. */ import React from 'react'; -import { styledMount as mount } from 'spec/helpers/theming'; - +import { shallow } from 'enzyme'; +import thunk from 'redux-thunk'; +import configureStore from 'redux-mock-store'; import Welcome from 'src/views/CRUD/welcome/Welcome'; +const mockStore = configureStore([thunk]); +const store = mockStore({}); + describe('Welcome', () => { const mockedProps = { user: { @@ -33,11 +37,15 @@ describe('Welcome', () => { isActive: true, }, }; - const wrapper = mount(<Welcome {...mockedProps} />); + const wrapper = shallow(<Welcome {...mockedProps} />, { + context: { store }, + }); + it('is renders', () => { - expect(wrapper.find(Welcome)).toExist(); + expect(wrapper).toExist(); }); + it('renders all panels on the page on page load', () => { - expect(wrapper.find('PanelContent')).toHaveLength(4); + expect(wrapper.find('CollapsePanel')).toHaveLength(4); }); }); diff --git a/superset-frontend/src/views/CRUD/chart/ChartCard.tsx b/superset-frontend/src/views/CRUD/chart/ChartCard.tsx index 9e3b696..bcf21d2 100644 --- a/superset-frontend/src/views/CRUD/chart/ChartCard.tsx +++ b/superset-frontend/src/views/CRUD/chart/ChartCard.tsx @@ -59,7 +59,6 @@ export default function ChartCard({ FAVESTAR_BASE_URL, addDangerToast, ); - function handleChartDelete({ id, slice_name: sliceName }: Chart) { SupersetClient.delete({ endpoint: `/api/v1/chart/${id}`, @@ -117,7 +116,7 @@ export default function ChartCard({ loading={loading} title={chart.slice_name} url={bulkSelectEnabled ? undefined : chart.url} - imgURL={chart.thumbnail_url ?? ''} + imgURL={chart.thumbnail_url || ''} imgFallbackURL="/static/assets/images/chart-card-fallback.png" description={t('Last modified %s', chart.changed_on_delta_humanized)} coverLeft={<FacePile users={chart.owners || []} />} diff --git a/superset-frontend/src/views/CRUD/data/common.ts b/superset-frontend/src/views/CRUD/data/common.ts index 9b2194a..6fecd21 100644 --- a/superset-frontend/src/views/CRUD/data/common.ts +++ b/superset-frontend/src/views/CRUD/data/common.ts @@ -20,7 +20,7 @@ import { t } from '@superset-ui/core'; export const commonMenuData = { name: t('Data'), - children: [ + tabs: [ { name: 'Datasets', label: t('Datasets'), diff --git a/superset-frontend/src/views/CRUD/utils.tsx b/superset-frontend/src/views/CRUD/utils.tsx index 55ae299..a604770 100644 --- a/superset-frontend/src/views/CRUD/utils.tsx +++ b/superset-frontend/src/views/CRUD/utils.tsx @@ -101,15 +101,26 @@ export const getRecentAcitivtyObjs = ( SupersetClient.get({ endpoint: `/api/v1/chart/?q=${getParams(filters.created)}`, }), + SupersetClient.get({ + endpoint: `/api/v1/saved_query/?q=${getParams(filters.created)}`, + }), ]; return Promise.all(baseBatch).then( // @ts-ignore - ([recentsRes, editedDash, editedChart, createdByDash, createdByChart]) => { + ([ + recentsRes, + editedDash, + editedChart, + createdByDash, + createdByChart, + createdByQuery, + ]) => { const res: any = { editedDash: editedDash.json?.result.slice(0, 3), editedChart: editedChart.json?.result.slice(0, 3), createdByDash: createdByDash.json?.result.slice(0, 3), createdByChart: createdByChart.json?.result.slice(0, 3), + createdByQuery: createdByQuery.json?.result.slice(0, 3), }; if (recentsRes.json.length === 0) { const newBatch = [ diff --git a/superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx b/superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx index 56e5d70..c515911 100644 --- a/superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx +++ b/superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx @@ -147,7 +147,7 @@ export default function ActivityTable({ user }: ActivityProps) { getRecentAcitivtyObjs(user.userId, recent) .then(res => { const data: any = { - Created: [...res.createdByChart, ...res.createdByDash], + Created: [...res.createdByChart, ...res.createdByDash, ...res.createdByQuery], Edited: [...res.editedChart, ...res.editedDash], }; if (res.viewed) { diff --git a/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx b/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx index 1979a18..c807f35 100644 --- a/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx +++ b/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx @@ -51,7 +51,6 @@ function ChartTable({ refreshData, fetchData, } = useListViewResource<Chart>('chart', t('chart'), addDangerToast); - const { sliceCurrentlyEditing, openChartEditModal, @@ -142,7 +141,7 @@ function ChartTable({ }, ]} /> - {charts.length ? ( + {charts?.length ? ( <CardContainer> {charts.map(e => ( <ChartCard
