From 4cb1877c4e452b965bd733ed3c53ff26daacb056 Mon Sep 17 00:00:00 2001 From: Patrick Ear Date: Tue, 16 May 2023 15:09:29 +0200 Subject: [PATCH] chore: cleanup import, type and tests --- src/react/App.tsx | 2 - src/react/ZenkoUI.tsx | 3 +- .../__tests__/AccountPoliciesList.test.tsx | 41 +++++-------------- .../__tests__/AccountUserList.test.tsx | 13 ++---- .../__tests__/CreateAccountPolicy.test.tsx | 17 ++------ .../__tests__/UpdateAccountPolicy.test.tsx | 22 +++------- .../__tests__/Attachments.test.tsx | 9 +--- .../ObjectRestorationButtonAndModal.test.tsx | 3 -- .../ui/MetricsAdapterProvider.tsx | 4 +- src/react/utils/testUtil.tsx | 1 - .../__tests__/TransitionForm.test.tsx | 1 - 11 files changed, 27 insertions(+), 89 deletions(-) diff --git a/src/react/App.tsx b/src/react/App.tsx index a64c883d2..1fe38c661 100644 --- a/src/react/App.tsx +++ b/src/react/App.tsx @@ -7,8 +7,6 @@ import { QueryClient, QueryClientProvider } from 'react-query'; import { ReactQueryDevtools } from 'react-query/devtools'; import ZenkoUI from './ZenkoUI'; import { ConfigProvider } from './next-architecture/ui/ConfigProvider'; -import DataServiceRoleProvider from './DataServiceRoleProvider'; -import { S3AssumeRoleClientProvider } from './next-architecture/ui/S3ClientProvider'; import { AuthProvider } from './next-architecture/ui/AuthProvider'; import { AccountsAdapterProvider } from './next-architecture/ui/AccountAdapterProvider'; import { AccessibleAccountsAdapterProvider } from './next-architecture/ui/AccessibleAccountsAdapterProvider'; diff --git a/src/react/ZenkoUI.tsx b/src/react/ZenkoUI.tsx index f3d9e383a..c6c78efb3 100644 --- a/src/react/ZenkoUI.tsx +++ b/src/react/ZenkoUI.tsx @@ -1,12 +1,11 @@ import { Container, MainContainer } from './ui-elements/Container'; -import React, { useEffect } from 'react'; +import { useEffect } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import Activity from './ui-elements/Activity'; import type { AppState } from '../types/state'; import { Banner, Icon, ScrollbarWrapper } from '@scality/core-ui'; import ErrorHandlerModal from './ui-elements/ErrorHandlerModal'; import Loader from './ui-elements/Loader'; -import ReauthDialog from './ui-elements/ReauthDialog'; import Routes from './Routes'; import { ThemeProvider } from 'styled-components'; import { loadAppConfig } from './actions'; diff --git a/src/react/account/__tests__/AccountPoliciesList.test.tsx b/src/react/account/__tests__/AccountPoliciesList.test.tsx index fdb724fe6..acf814cab 100644 --- a/src/react/account/__tests__/AccountPoliciesList.test.tsx +++ b/src/react/account/__tests__/AccountPoliciesList.test.tsx @@ -5,7 +5,6 @@ import { mockOffsetSize, reduxRender, TEST_API_BASE_URL, - Wrapper as wrapper, } from '../../utils/testUtil'; import AccountPoliciesList from '../AccountPoliciesList'; @@ -117,9 +116,7 @@ afterAll(() => server.close()); describe('AccountPoliciesList', () => { it('should render header buttons and a table with user policies', async () => { try { - reduxRender(, { - wrapper, - }); + reduxRender(); expect(screen.getAllByText('Loading policies...')).toHaveLength(2); @@ -149,9 +146,7 @@ describe('AccountPoliciesList', () => { } }); it('should render enabled Attach button', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); //E await waitFor(() => screen.getAllByText(/Edit/i)); //V @@ -161,9 +156,7 @@ describe('AccountPoliciesList', () => { expect(attachButton).not.toBeDisabled(); }); it('should render Edit button for Non Scality internal Policy', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); //E await waitFor(() => screen.getAllByText('Edit')); //V @@ -174,9 +167,7 @@ describe('AccountPoliciesList', () => { expect(editButton).toBeInTheDocument(); }); it('should render view button for Scality internal Policies', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); //E await waitFor(() => screen.getAllByText('Edit')); //V @@ -187,9 +178,7 @@ describe('AccountPoliciesList', () => { expect(viewButton).toBeInTheDocument(); }); it('should render enabled Copy ARN button', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); //E await waitFor(() => screen.getAllByText(/Copy ARN/i)); //V @@ -199,9 +188,7 @@ describe('AccountPoliciesList', () => { expect(arnButton).not.toBeDisabled(); }); it('should render disabled Delete button for Scality internal policy', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); await waitFor(() => screen.getAllByText(/Edit/i)); const deleteButton = screen.getByRole('button', { @@ -230,9 +217,7 @@ describe('AccountPoliciesList', () => { }), ); - reduxRender(, { - wrapper, - }); + reduxRender(); // E await waitFor(() => screen.getAllByText(/Edit/i)); @@ -298,9 +283,7 @@ describe('AccountPoliciesList', () => { }), ); - reduxRender(, { - wrapper, - }); + reduxRender(); //E await waitFor(() => screen.getAllByText('View')); //V @@ -334,9 +317,7 @@ describe('AccountPoliciesList', () => { }), ); - reduxRender(, { - wrapper, - }); + reduxRender(); // E await waitFor(() => screen.getAllByText(/Edit/i)); @@ -468,9 +449,7 @@ describe('AccountPoliciesList', () => { }), ); - reduxRender(, { - wrapper, - }); + reduxRender(); // E await waitFor(() => screen.getAllByText(/Edit/i)); diff --git a/src/react/account/__tests__/AccountUserList.test.tsx b/src/react/account/__tests__/AccountUserList.test.tsx index a11d97182..56910628f 100644 --- a/src/react/account/__tests__/AccountUserList.test.tsx +++ b/src/react/account/__tests__/AccountUserList.test.tsx @@ -12,7 +12,6 @@ import { mockOffsetSize, reduxRender, TEST_API_BASE_URL, - Wrapper as wrapper, } from '../../utils/testUtil'; const SAMPLE_USER_ID = 'GENERATED_ID'; @@ -57,9 +56,7 @@ afterAll(() => server.close()); describe('AccountUserList', () => { it('should render a table with users', async () => { //E - reduxRender(, { - wrapper, - }); + reduxRender(); //V //Loading state expect(screen.getAllByText('Loading users...')).toHaveLength(2); @@ -92,9 +89,7 @@ describe('AccountUserList', () => { ).toBeInTheDocument(); }); it('should render header buttons and column names', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); /********** Number of columns : ************/ @@ -122,9 +117,7 @@ describe('AccountUserList', () => { ), ); - reduxRender(, { - wrapper, - }); + reduxRender(); await waitFor(() => screen.getByText( diff --git a/src/react/account/__tests__/CreateAccountPolicy.test.tsx b/src/react/account/__tests__/CreateAccountPolicy.test.tsx index a9ef2c818..fdef2e9cd 100644 --- a/src/react/account/__tests__/CreateAccountPolicy.test.tsx +++ b/src/react/account/__tests__/CreateAccountPolicy.test.tsx @@ -5,7 +5,6 @@ import { mockOffsetSize, reduxRender, TEST_API_BASE_URL, - Wrapper as wrapper, } from '../../utils/testUtil'; import CreateAccountPolicy from '../CreateAccountPolicy'; import userEvent from '@testing-library/user-event'; @@ -45,9 +44,7 @@ afterAll(() => server.close()); describe('CreateAccountPolicy', () => { it('should display all fields for CreateAccountPolicy form', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); expect(screen.getByText('Policy Creation')).toBeInTheDocument(); expect(screen.getByText('* are required fields')).toBeInTheDocument(); expect( @@ -69,9 +66,7 @@ describe('CreateAccountPolicy', () => { expect(cancelButton).toBeInTheDocument(); }); it('should disable Create button if policy name input and policy document textarea are empty', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); const policyNameInput = screen.getByRole('textbox', { name: /Policy name/i, }); @@ -83,9 +78,7 @@ describe('CreateAccountPolicy', () => { expect(createButton).toBeDisabled(); }); it('should check if create button is disabled when no policy name is provided', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); const policyNameInput = screen.getByRole('textbox', { name: /Policy name/i, }); @@ -99,9 +92,7 @@ describe('CreateAccountPolicy', () => { expect(createButton).toBeDisabled(); }); it('should check if Copy button is enabled if policy document is not empty', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); const copyButton = screen.getByRole('button', { name: /copy policy/i }); diff --git a/src/react/account/__tests__/UpdateAccountPolicy.test.tsx b/src/react/account/__tests__/UpdateAccountPolicy.test.tsx index 46b0ade82..43055dd04 100644 --- a/src/react/account/__tests__/UpdateAccountPolicy.test.tsx +++ b/src/react/account/__tests__/UpdateAccountPolicy.test.tsx @@ -2,11 +2,7 @@ import React from 'react'; import { screen, waitForElementToBeRemoved } from '@testing-library/react'; import { rest } from 'msw'; import { setupServer } from 'msw/node'; -import { - reduxRender, - TEST_API_BASE_URL, - Wrapper as wrapper, -} from '../../utils/testUtil'; +import { reduxRender, TEST_API_BASE_URL } from '../../utils/testUtil'; import UpdateAccountPolicy from '../UpdateAccountPolicy'; import router from 'react-router'; @@ -87,9 +83,7 @@ describe('UpdateAccountPolicy', () => { afterAll(() => server.close()); it('should render readonly form when the policy is internal', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); await waitForElementToBeRemoved( () => [...screen.queryAllByText(/Loading/i)], { timeout: 8000 }, @@ -114,9 +108,7 @@ describe('UpdateAccountPolicy', () => { policyArn: 'arn:aws:iam::137489910101:policy/custom-policy', defaultVersionId: 'v1', }); - reduxRender(, { - wrapper, - }); + reduxRender(); await waitForElementToBeRemoved( () => [...screen.queryAllByText(/Loading/i)], { timeout: 8000 }, @@ -137,9 +129,7 @@ describe('UpdateAccountPolicy', () => { expect(cancelButton).toBeInTheDocument(); }); it('should display fields policy name and ARN not empty', async () => { - reduxRender(, { - wrapper, - }); + reduxRender(); await waitForElementToBeRemoved( () => [...screen.queryAllByText(/Loading/i)], { timeout: 8000 }, @@ -156,9 +146,7 @@ describe('UpdateAccountPolicy', () => { policyArn: 'arn:aws:iam::137489910101:policy/custom-policy', defaultVersionId: 'v1', }); - reduxRender(, { - wrapper, - }); + reduxRender(); await waitForElementToBeRemoved( () => [...screen.queryAllByText(/Loading/i)], diff --git a/src/react/account/iamAttachment/__tests__/Attachments.test.tsx b/src/react/account/iamAttachment/__tests__/Attachments.test.tsx index 05cf377a4..1f835aff0 100644 --- a/src/react/account/iamAttachment/__tests__/Attachments.test.tsx +++ b/src/react/account/iamAttachment/__tests__/Attachments.test.tsx @@ -7,7 +7,6 @@ import { mockOffsetSize, reduxRender, TEST_API_BASE_URL, - Wrapper as wrapper, } from '../../../utils/testUtil'; import Attachments from '../Attachments'; import accountSeeds from '../../../../../public/assets/account-seeds.json'; @@ -167,9 +166,7 @@ const setupPolicyRender = ( jest.spyOn(router, 'useParams').mockReturnValue({ policyArn, }); - reduxRender(, { - wrapper, - }); + reduxRender(); }; describe('Policy Attachments', () => { @@ -455,9 +452,7 @@ describe('User Attachments', () => { jest.spyOn(router, 'useParams').mockReturnValue({ IAMUserName: userName, }); - reduxRender(, { - wrapper, - }); + reduxRender(); }; it('should render Groups and Policies for User Attachments Tabs', () => { diff --git a/src/react/databrowser/objects/details/__tests__/ObjectRestorationButtonAndModal.test.tsx b/src/react/databrowser/objects/details/__tests__/ObjectRestorationButtonAndModal.test.tsx index b3df22955..9738f1315 100644 --- a/src/react/databrowser/objects/details/__tests__/ObjectRestorationButtonAndModal.test.tsx +++ b/src/react/databrowser/objects/details/__tests__/ObjectRestorationButtonAndModal.test.tsx @@ -6,7 +6,6 @@ import { mockOffsetSize, reduxRender, TEST_API_BASE_URL, - Wrapper as wrapper, } from '../../../../utils/testUtil'; import { OBJECT_METADATA } from '../../../../actions/__tests__/utils/testUtil'; import ObjectRestorationButtonAndModal from '../ObjectRestorationButtonAndModal'; @@ -62,7 +61,6 @@ describe('Object Restoration Button And Modal', () => { bucketName={bucketName} objectMetadata={OBJECT_METADATA} />, - { wrapper }, ); act(() => { userEvent.click(selectors.restoreButtonSelector()); @@ -114,7 +112,6 @@ describe('Object Restoration Button And Modal', () => { bucketName={bucketName} objectMetadata={OBJECT_METADATA} />, - { wrapper }, ); userEvent.click(selectors.restoreButtonSelector()); //V diff --git a/src/react/next-architecture/ui/MetricsAdapterProvider.tsx b/src/react/next-architecture/ui/MetricsAdapterProvider.tsx index cd558ef3d..141ee7f1c 100644 --- a/src/react/next-architecture/ui/MetricsAdapterProvider.tsx +++ b/src/react/next-architecture/ui/MetricsAdapterProvider.tsx @@ -1,4 +1,4 @@ -import { createContext, useContext } from 'react'; +import { createContext, useContext, ReactNode } from 'react'; import { PensieveMetricsAdapter } from '../adapters/metrics/PensieveMetricsAdapter'; import { IMetricsAdapter } from '../adapters/metrics/IMetricsAdapter'; import { useAccessToken, useInstanceId } from './AuthProvider'; @@ -20,7 +20,7 @@ export const useMetricsAdapter = (): IMetricsAdapter => { return context.metricsAdapter; }; -const MetricsAdapterProvider = ({ children }: { children: JSX.Element }) => { +const MetricsAdapterProvider = ({ children }: { children: ReactNode }) => { const token = useAccessToken(); const instanceId = useInstanceId(); const { managementEndpoint } = useConfig(); diff --git a/src/react/utils/testUtil.tsx b/src/react/utils/testUtil.tsx index bb72ea2a6..0236e9dec 100644 --- a/src/react/utils/testUtil.tsx +++ b/src/react/utils/testUtil.tsx @@ -9,7 +9,6 @@ import { createMemoryHistory } from 'history'; import IAMClient from '../../js/IAMClient'; import { QueryClient, QueryClientProvider } from 'react-query'; import { Router } from 'react-router-dom'; -import { _IAMContext, useIAMClient } from '../IAMProvider'; import { render } from '@testing-library/react'; import { _ManagementContext } from '../ManagementProvider'; diff --git a/src/react/workflow/__tests__/TransitionForm.test.tsx b/src/react/workflow/__tests__/TransitionForm.test.tsx index 2b8c6e7f6..914a6b747 100644 --- a/src/react/workflow/__tests__/TransitionForm.test.tsx +++ b/src/react/workflow/__tests__/TransitionForm.test.tsx @@ -12,7 +12,6 @@ import { FormProvider, useForm } from 'react-hook-form'; import { mockOffsetSize, reduxRender, - Wrapper as wrapper, zenkoUITestConfig, } from '../../utils/testUtil'; import {