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 aa704b094902dc64c9fed338b9b93274a735f344 Author: Phillip Kelley-Dotson <[email protected]> AuthorDate: Mon Oct 19 13:54:32 2020 -0700 update test part 1 --- .../views/CRUD/welcome/ActivityTable_spec.tsx | 4 -- .../views/CRUD/welcome/DashboardTable_spec.tsx | 15 ++--- .../{SavedQueries_spec.tsx => EmptyState_spec.tsx} | 36 ++++------- .../views/CRUD/welcome/SavedQueries_spec.tsx | 72 +++++++++++++++++++--- .../src/views/CRUD/chart/ChartList.tsx | 4 +- superset-frontend/src/views/CRUD/types.ts | 2 +- .../src/views/CRUD/welcome/ActivityTable.tsx | 1 + .../src/views/CRUD/welcome/ChartTable.tsx | 9 --- .../src/views/CRUD/welcome/EmptyState.tsx | 17 +++-- .../src/views/CRUD/welcome/SavedQueries.tsx | 16 ++--- 10 files changed, 104 insertions(+), 72 deletions(-) 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 2f54d58..19fb397 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/welcome/ActivityTable_spec.tsx +++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/ActivityTable_spec.tsx @@ -79,10 +79,6 @@ describe('ActivityTable', () => { expect(wrapper.find(ActivityTable)).toExist(); }); - it('renders a EmptyState', () => { - console.log('wrapper', wrapper.debug()) - }); - it('calls batch method and renders ListViewCArd', () => { const chartCall = fetchMock.calls(/chart\/\?q/); const dashboardCall = fetchMock.calls(/dashboard\/\?q/); 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 dd1e92a..013d3b3 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/welcome/DashboardTable_spec.tsx +++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/DashboardTable_spec.tsx @@ -44,7 +44,6 @@ const mockDashboards = [ ]; fetchMock.get(dashboardsEndpoint, { result: mockDashboards }); -//fetchMock.get(dashboardsEndpointNoData, { result: [] }); fetchMock.get(chartsInfoEndpoint, { permissions: ['can_list', 'can_edit', 'can_delete'], }); @@ -59,8 +58,6 @@ describe('DashboardTable', () => { const wrapper = mount(<DashboardTable {...dashboardProps} />, { context: { store }, }); - // console.log('wrapper', wrapper.debug()) - // beforeEach(fetchMock.resetHistory); beforeAll(async () => { await waitForComponentToPaint(wrapper); @@ -68,13 +65,12 @@ describe('DashboardTable', () => { it('renders', () => { expect(wrapper.find(DashboardTable)).toExist(); - console.log('wrapper', wrapper.debug()) }); it('render a submenu with clickable tabs and buttons', async () => { expect(wrapper.find(SubMenu)).toExist(); expect(wrapper.find('MenuItem')).toHaveLength(2); - expect(wrapper.find('Button')).toHaveLength(2); + expect(wrapper.find('Button')).toHaveLength(4); act(() => { wrapper.find('MenuItem').at(1).simulate('click'); }); @@ -87,8 +83,9 @@ describe('DashboardTable', () => { wrapper.setState({ dashboards: mockDashboards }); expect(wrapper.find(DashboardCard)).toExist(); }); - /*it('display EmptyState if there is no data', ()=>{ - (const wrapper = mount(<DashboardTable {...dashboardProps} />) - console.log('wrapper', wrapper); - });*/ + + it('display EmptyState if there is no data', () => { + fetchMock.resetHistory(); + expect(wrapper.find('EmptyState')).toExist(); + }); }); diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/EmptyState_spec.tsx similarity index 57% copy from superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx copy to superset-frontend/spec/javascripts/views/CRUD/welcome/EmptyState_spec.tsx index fd367a1..b6e5175 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx +++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/EmptyState_spec.tsx @@ -17,30 +17,20 @@ * under the License. */ import React from 'react'; -import SavedQueries from 'src/views/CRUD/welcome/SavedQueries'; -import { mount } from 'enzyme'; -import thunk from 'redux-thunk'; +import { styledMount as mount } from 'spec/helpers/theming'; +import { act } from 'react-dom/test-utils'; -import configureStore from 'redux-mock-store'; -// store needed for withToasts(DashboardTable) -const mockStore = configureStore([thunk]); -const store = mockStore({}); +import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint'; +import EmptyState from 'src/views/CRUD/welcome/EmptyState'; -describe('SavedQueries', () => { - const savedQueryProps = { - user: { - userId: '1', - }, - activityFilter: 'Edit', - }; - - const wrapper = mount(<SavedQueries {...savedQueryProps} />); - - it('is valid', () => { - expect(React.isValidElement(<SavedQueries />)).toBe(true); +describe('EmptyState', () => { + it('it renders an favorite dashboard empty state', () => { + const props = { + tab: 'Favorite', + tableName: 'DASHBOARDS', + }; + const wrapper = mount(<EmptyState {...props} />); + expect(wrapper).toExist(); + console.log('wrapper', wrapper.debug()); }); - it('takes in props', () => { - - // expect() - }); }); diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx index fd367a1..28173f2 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx +++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx @@ -17,30 +17,84 @@ * under the License. */ import React from 'react'; -import SavedQueries from 'src/views/CRUD/welcome/SavedQueries'; -import { mount } from 'enzyme'; import thunk from 'redux-thunk'; - +import { styledMount as mount } from 'spec/helpers/theming'; +import fetchMock from 'fetch-mock'; import configureStore from 'redux-mock-store'; +import { act } from 'react-dom/test-utils'; + +import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint'; +import SubMenu from 'src/components/Menu/SubMenu'; +import SavedQueries from 'src/views/CRUD/welcome/SavedQueries'; + // store needed for withToasts(DashboardTable) const mockStore = configureStore([thunk]); const store = mockStore({}); +const queriesEndpoint = 'glob:*/api/v1/saved_queries/?*'; + +const mockqueries = [...new Array(3)].map((_, i) => ({ + created_by: { + id: i, + first_name: `user`, + last_name: `${i}`, + }, + created_on: `${i}-2020`, + database: { + database_name: `db ${i}`, + id: i, + }, + changed_on_delta_humanized: '1 day ago', + db_id: i, + description: `SQL for ${i}`, + id: i, + label: `query ${i}`, + schema: 'public', + sql: `SELECT ${i} FROM table`, + sql_tables: [ + { + catalog: null, + schema: null, + table: `${i}`, + }, + ], +})); + +fetchMock.get(queriesEndpoint, { + result: mockqueries, +}); + describe('SavedQueries', () => { const savedQueryProps = { user: { userId: '1', }, - activityFilter: 'Edit', }; - const wrapper = mount(<SavedQueries {...savedQueryProps} />); + const wrapper = mount(<SavedQueries {...savedQueryProps} />, { + context: { store }, + }); + beforeAll(async () => { + await waitForComponentToPaint(wrapper); + }); it('is valid', () => { - expect(React.isValidElement(<SavedQueries />)).toBe(true); + expect(wrapper.find(SavedQueries)).toExist(); }); - it('takes in props', () => { - // expect() - }); + it('it renders a submenu with clickable tabls and buttons', async () => { + expect(wrapper.find(SubMenu)).toExist(); + expect(wrapper.find('MenuItem')).toHaveLength(2); + expect(wrapper.find('Button')).toHaveLength(4); + act(() => { + wrapper.find('MenuItem').at(1).simulate('click'); + }); + await waitForComponentToPaint(wrapper); + expect(fetchMock.calls(/chart\/\?q/)).toHaveLength(1); + }); + + it('fetches queries favorites and renders chart cards', () => { + expect(fetchMock.calls(/chart\/\?q/)).toHaveLength(1); + expect(wrapper.find('ListViewCard')).toExist(); + }); }); diff --git a/superset-frontend/src/views/CRUD/chart/ChartList.tsx b/superset-frontend/src/views/CRUD/chart/ChartList.tsx index ec0722e..8a0b8b7 100644 --- a/superset-frontend/src/views/CRUD/chart/ChartList.tsx +++ b/superset-frontend/src/views/CRUD/chart/ChartList.tsx @@ -17,7 +17,7 @@ * under the License. */ import { SupersetClient, getChartMetadataRegistry, t } from '@superset-ui/core'; -import React, { useState, useMemo } from 'react'; +import React, { useMemo } from 'react'; import rison from 'rison'; import { uniqBy } from 'lodash'; import { isFeatureEnabled, FeatureFlag } from 'src/featureFlags'; @@ -416,7 +416,7 @@ function ChartList(props: ChartListProps) { openChartEditModal={openChartEditModal} bulkSelectEnabled={bulkSelectEnabled} addDangerToast={props.addDangerToast} - addSuccessToast={addSuccessToast} + addSuccessToast={props.addSuccessToast} refreshData={refreshData} loading={loading} /> diff --git a/superset-frontend/src/views/CRUD/types.ts b/superset-frontend/src/views/CRUD/types.ts index 1070f57..0946247 100644 --- a/superset-frontend/src/views/CRUD/types.ts +++ b/superset-frontend/src/views/CRUD/types.ts @@ -68,4 +68,4 @@ export type SavedQueryObject = { schema: string; sql: string; sql_tables: Array<{ catalog?: string; schema: string; table: string }>; -}; \ No newline at end of file +}; diff --git a/superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx b/superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx index 02d2cbc..c9f0883 100644 --- a/superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx +++ b/superset-frontend/src/views/CRUD/welcome/ActivityTable.tsx @@ -143,6 +143,7 @@ export default function ActivityTable({ user }: ActivityProps) { Created: [...r.createdByChart, ...r.createdByDash], Edited: [...r.editedChart, ...r.editedDash], }; + console.log('r.viewed', r) if (r.viewed) { const filtered = reject(r.viewed, ['item_url', null]).map(r => r); data.Viewed = filtered; diff --git a/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx b/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx index 99d51c0..c2784d1 100644 --- a/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx +++ b/superset-frontend/src/views/CRUD/welcome/ChartTable.tsx @@ -77,15 +77,6 @@ function ChartTable({ value: true, }); } - // Do we need search? - /* filters.concat([ - { - id: 'dashboard_title', - operator: 'ct', - value: search, - }, - ]); - */ return filters; }; diff --git a/superset-frontend/src/views/CRUD/welcome/EmptyState.tsx b/superset-frontend/src/views/CRUD/welcome/EmptyState.tsx index e1c2936..fe06a18 100644 --- a/superset-frontend/src/views/CRUD/welcome/EmptyState.tsx +++ b/superset-frontend/src/views/CRUD/welcome/EmptyState.tsx @@ -32,7 +32,7 @@ const Container = styled.div` flex-direction: column; justify-content: center; img { - width: 87px; + width: 114px; display: block; margin: 0 auto; } @@ -73,13 +73,19 @@ export default function EmptyState({ tableName, tab }: EmptyStateProps) { }} > <IconContainer> - <Icon name="plus-small" /> {tableName} + <Icon name="plus-small" />{' '} + {tableName === 'SAVED_QUERIES' + ? 'SQL LAB QUERY' + : tableName + .split('') + .slice(0, tableName.length - 1) + .join('')}{' '} </IconContainer> </Button> </div> ); const span = ( - <div> + <div className="no-recents"> Recently viewed charts, dashboards, and saved queries will appear here </div> ); @@ -97,14 +103,15 @@ export default function EmptyState({ tableName, tab }: EmptyStateProps) { <Container> <img src="/static/assets/images/star-circle.png" alt="star.png" /> <div> - <div>You don't have any favorites yets!</div> + <div className="no-favorites">You don't have any favorites yet!</div> <Button buttonStyle="primary" onClick={() => { window.location = favRedirects[tableName]; }} > - SEE ALL {tableName} + SEE ALL{' '} + {tableName === 'SAVED_QUERIES' ? 'SQL LAB QUERIES' : tableName } </Button> </div> </Container> diff --git a/superset-frontend/src/views/CRUD/welcome/SavedQueries.tsx b/superset-frontend/src/views/CRUD/welcome/SavedQueries.tsx index 333d394..5a49ee5 100644 --- a/superset-frontend/src/views/CRUD/welcome/SavedQueries.tsx +++ b/superset-frontend/src/views/CRUD/welcome/SavedQueries.tsx @@ -17,7 +17,7 @@ * under the License. */ import React, { useEffect, useState } from 'react'; -import { t, styled, SupersetClient } from '@superset-ui/core'; +import { t, SupersetClient } from '@superset-ui/core'; import withToasts from 'src/messageToasts/enhancers/withToasts'; import { Dropdown, Menu } from 'src/common/components'; import { useListViewResource, copyQueryLink } from 'src/views/CRUD/hooks'; @@ -41,7 +41,6 @@ interface Query { rows: string; description: string; end_time: string; - addDangerToast: () => void; label: string; } @@ -50,15 +49,10 @@ interface SavedQueriesProps { userId: string | number; }; queryFilter: string; + addDangerToast: (arg0: string) => void; + addSuccessToast: (arg0: string) => void; } -const NoData = styled.div` - .create-your-query { - display: block; - margin: 0 auto; - } -`; - const SavedQueries = ({ user, addDangerToast, @@ -139,7 +133,9 @@ const SavedQueries = ({ )} <Menu.Item onClick={() => copyQueryLink(query.id, addDangerToast, addSuccessToast)} - >Share</Menu.Item> + > + Share + </Menu.Item> {canDelete && ( <Menu.Item onClick={() => {
