From 0fc9da6be7c41bbe03e8bf8bb0df36edcbb0ff05 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Tue, 26 Jan 2021 04:19:16 -0300 Subject: [PATCH] Fix tests errors and warnings - iteration 7 (#12212) (#12245) --- .../components/PropertiesModal_spec.jsx | 30 ++++++++--- .../views/CRUD/welcome/Welcome_spec.tsx | 52 ++++++++++++++++--- .../CRUD/alert/components/AlertStatusIcon.tsx | 4 +- .../src/views/CRUD/data/query/QueryList.tsx | 4 +- .../src/views/CRUD/welcome/Welcome.tsx | 6 +-- 5 files changed, 77 insertions(+), 19 deletions(-) diff --git a/superset-frontend/spec/javascripts/dashboard/components/PropertiesModal_spec.jsx b/superset-frontend/spec/javascripts/dashboard/components/PropertiesModal_spec.jsx index f30420b19..07dcf7d9a 100644 --- a/superset-frontend/spec/javascripts/dashboard/components/PropertiesModal_spec.jsx +++ b/superset-frontend/spec/javascripts/dashboard/components/PropertiesModal_spec.jsx @@ -19,6 +19,7 @@ import React from 'react'; import { mount } from 'enzyme'; import { Provider } from 'react-redux'; +import fetchMock from 'fetch-mock'; import { supersetTheme, @@ -41,6 +42,21 @@ const dashboardResult = { }, }; +fetchMock.restore(); + +fetchMock.get('glob:*/api/v1/dashboard/related/owners?*', { + result: {}, +}); + +fetchMock.get('glob:*/api/v1/dashboard/*', { + result: { + dashboard_title: 'New Title', + slug: '/new', + json_metadata: '{"something":"foo"}', + owners: [], + }, +}); + describe('PropertiesModal', () => { afterEach(() => { jest.restoreAllMocks(); @@ -84,14 +100,14 @@ describe('PropertiesModal', () => { }); describe('with metadata', () => { describe('with color_scheme in the metadata', () => { - const wrapper = setup(); - const modalInstance = wrapper.find('PropertiesModal').instance(); - modalInstance.setState({ - values: { - json_metadata: '{"color_scheme": "foo"}', - }, - }); it('will update the metadata', () => { + const wrapper = setup(); + const modalInstance = wrapper.find('PropertiesModal').instance(); + modalInstance.setState({ + values: { + json_metadata: '{"color_scheme": "foo"}', + }, + }); const spy = jest.spyOn(modalInstance, 'onMetadataChange'); modalInstance.onColorSchemeChange('SUPERSET_DEFAULT'); expect(spy).toHaveBeenCalledWith( 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 8788e52e6..53ba3575a 100644 --- a/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx +++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx @@ -21,15 +21,24 @@ import { styledMount as mount } from 'spec/helpers/theming'; import { Provider } from 'react-redux'; import thunk from 'redux-thunk'; import fetchMock from 'fetch-mock'; +import { act } from 'react-dom/test-utils'; import configureStore from 'redux-mock-store'; import Welcome from 'src/views/CRUD/welcome/Welcome'; +import { ReactWrapper } from 'enzyme'; const mockStore = configureStore([thunk]); const store = mockStore({}); const chartsEndpoint = 'glob:*/api/v1/chart/?*'; -const dashboardEndpoint = 'glob:*/api/v1/dashboard/?*'; +const chartInfoEndpoint = 'glob:*/api/v1/chart/_info?*'; +const chartFavoriteStatusEndpoint = 'glob:*/api/v1/chart/favorite_status?*'; +const dashboardsEndpoint = 'glob:*/api/v1/dashboard/?*'; +const dashboardInfoEndpoint = 'glob:*/api/v1/dashboard/_info?*'; +const dashboardFavoriteStatusEndpoint = + 'glob:*/api/v1/dashboard/favorite_status?*'; const savedQueryEndpoint = 'glob:*/api/v1/saved_query/?*'; +const savedQueryInfoEndpoint = 'glob:*/api/v1/saved_query/_info?*'; +const recentActivityEndpoint = 'glob:*/superset/recent_activity/*'; fetchMock.get(chartsEndpoint, { result: [ @@ -43,7 +52,7 @@ fetchMock.get(chartsEndpoint, { ], }); -fetchMock.get(dashboardEndpoint, { +fetchMock.get(dashboardsEndpoint, { result: [ { dashboard_title: 'Dashboard_Test', @@ -58,6 +67,28 @@ fetchMock.get(savedQueryEndpoint, { result: [], }); +fetchMock.get(recentActivityEndpoint, {}); + +fetchMock.get(chartInfoEndpoint, { + permissions: [], +}); + +fetchMock.get(chartFavoriteStatusEndpoint, { + result: [], +}); + +fetchMock.get(dashboardInfoEndpoint, { + permissions: [], +}); + +fetchMock.get(dashboardFavoriteStatusEndpoint, { + result: [], +}); + +fetchMock.get(savedQueryInfoEndpoint, { + permissions: [], +}); + describe('Welcome', () => { const mockedProps = { user: { @@ -70,11 +101,18 @@ describe('Welcome', () => { isActive: true, }, }; - const wrapper = mount( - - - , - ); + + let wrapper: ReactWrapper; + + beforeAll(async () => { + await act(async () => { + wrapper = mount( + + + , + ); + }); + }); it('renders', () => { expect(wrapper).toExist(); diff --git a/superset-frontend/src/views/CRUD/alert/components/AlertStatusIcon.tsx b/superset-frontend/src/views/CRUD/alert/components/AlertStatusIcon.tsx index 6b83d47e9..f6ef08c54 100644 --- a/superset-frontend/src/views/CRUD/alert/components/AlertStatusIcon.tsx +++ b/superset-frontend/src/views/CRUD/alert/components/AlertStatusIcon.tsx @@ -22,7 +22,9 @@ import { Tooltip } from 'src/common/components/Tooltip'; import Icon, { IconName } from 'src/components/Icon'; import { AlertState } from '../types'; -const StatusIcon = styled(Icon)<{ status: string; isReportEnabled: boolean }>` +const StatusIcon = styled(Icon, { + shouldForwardProp: prop => prop !== 'status' && prop !== 'isReportEnabled', +})<{ status: string; isReportEnabled: boolean }>` color: ${({ status, theme, isReportEnabled }) => { switch (status) { case AlertState.working: diff --git a/superset-frontend/src/views/CRUD/data/query/QueryList.tsx b/superset-frontend/src/views/CRUD/data/query/QueryList.tsx index a3393314d..0d03c0f4b 100644 --- a/superset-frontend/src/views/CRUD/data/query/QueryList.tsx +++ b/superset-frontend/src/views/CRUD/data/query/QueryList.tsx @@ -80,7 +80,9 @@ const StyledPopoverItem = styled.div` color: ${({ theme }) => theme.colors.grayscale.dark2}; `; -const StatusIcon = styled(Icon)<{ status: string }>` +const StatusIcon = styled(Icon, { + shouldForwardProp: prop => prop !== 'status', +})<{ status: string }>` color: ${({ status, theme }) => { if (status === 'success') return theme.colors.success.base; if (status === 'failed') return theme.colors.error.base; diff --git a/superset-frontend/src/views/CRUD/welcome/Welcome.tsx b/superset-frontend/src/views/CRUD/welcome/Welcome.tsx index 87bdc6339..83163db15 100644 --- a/superset-frontend/src/views/CRUD/welcome/Welcome.tsx +++ b/superset-frontend/src/views/CRUD/welcome/Welcome.tsx @@ -62,9 +62,9 @@ const WelcomeContainer = styled.div` } } .nav.navbar-nav { - & > li:nth-child(1), - & > li:nth-child(2), - & > li:nth-child(3) { + & > li:nth-of-type(1), + & > li:nth-of-type(2), + & > li:nth-of-type(3) { margin-top: ${({ theme }) => theme.gridUnit * 2}px; } } -- GitLab