Skip to content

Commit

Permalink
chore: cleanup import, type and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
MonPote committed May 16, 2023
1 parent 56be1c9 commit 4cb1877
Show file tree
Hide file tree
Showing 11 changed files with 27 additions and 89 deletions.
2 changes: 0 additions & 2 deletions src/react/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
3 changes: 1 addition & 2 deletions src/react/ZenkoUI.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
41 changes: 10 additions & 31 deletions src/react/account/__tests__/AccountPoliciesList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
mockOffsetSize,
reduxRender,
TEST_API_BASE_URL,
Wrapper as wrapper,
} from '../../utils/testUtil';
import AccountPoliciesList from '../AccountPoliciesList';

Expand Down Expand Up @@ -117,9 +116,7 @@ afterAll(() => server.close());
describe('AccountPoliciesList', () => {
it('should render header buttons and a table with user policies', async () => {
try {
reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);

expect(screen.getAllByText('Loading policies...')).toHaveLength(2);

Expand Down Expand Up @@ -149,9 +146,7 @@ describe('AccountPoliciesList', () => {
}
});
it('should render enabled Attach button', async () => {
reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);
//E
await waitFor(() => screen.getAllByText(/Edit/i));
//V
Expand All @@ -161,9 +156,7 @@ describe('AccountPoliciesList', () => {
expect(attachButton).not.toBeDisabled();
});
it('should render Edit button for Non Scality internal Policy', async () => {
reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);
//E
await waitFor(() => screen.getAllByText('Edit'));
//V
Expand All @@ -174,9 +167,7 @@ describe('AccountPoliciesList', () => {
expect(editButton).toBeInTheDocument();
});
it('should render view button for Scality internal Policies', async () => {
reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);
//E
await waitFor(() => screen.getAllByText('Edit'));
//V
Expand All @@ -187,9 +178,7 @@ describe('AccountPoliciesList', () => {
expect(viewButton).toBeInTheDocument();
});
it('should render enabled Copy ARN button', async () => {
reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);
//E
await waitFor(() => screen.getAllByText(/Copy ARN/i));
//V
Expand All @@ -199,9 +188,7 @@ describe('AccountPoliciesList', () => {
expect(arnButton).not.toBeDisabled();
});
it('should render disabled Delete button for Scality internal policy', async () => {
reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);

await waitFor(() => screen.getAllByText(/Edit/i));
const deleteButton = screen.getByRole('button', {
Expand Down Expand Up @@ -230,9 +217,7 @@ describe('AccountPoliciesList', () => {
}),
);

reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);

// E
await waitFor(() => screen.getAllByText(/Edit/i));
Expand Down Expand Up @@ -298,9 +283,7 @@ describe('AccountPoliciesList', () => {
}),
);

reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);
//E
await waitFor(() => screen.getAllByText('View'));
//V
Expand Down Expand Up @@ -334,9 +317,7 @@ describe('AccountPoliciesList', () => {
}),
);

reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);

// E
await waitFor(() => screen.getAllByText(/Edit/i));
Expand Down Expand Up @@ -468,9 +449,7 @@ describe('AccountPoliciesList', () => {
}),
);

reduxRender(<AccountPoliciesList accountName="account" />, {
wrapper,
});
reduxRender(<AccountPoliciesList accountName="account" />);

// E
await waitFor(() => screen.getAllByText(/Edit/i));
Expand Down
13 changes: 3 additions & 10 deletions src/react/account/__tests__/AccountUserList.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
mockOffsetSize,
reduxRender,
TEST_API_BASE_URL,
Wrapper as wrapper,
} from '../../utils/testUtil';

const SAMPLE_USER_ID = 'GENERATED_ID';
Expand Down Expand Up @@ -57,9 +56,7 @@ afterAll(() => server.close());
describe('AccountUserList', () => {
it('should render a table with users', async () => {
//E
reduxRender(<AccountUserList accountName="account" />, {
wrapper,
});
reduxRender(<AccountUserList accountName="account" />);
//V
//Loading state
expect(screen.getAllByText('Loading users...')).toHaveLength(2);
Expand Down Expand Up @@ -92,9 +89,7 @@ describe('AccountUserList', () => {
).toBeInTheDocument();
});
it('should render header buttons and column names', async () => {
reduxRender(<AccountUserList accountName="account" />, {
wrapper,
});
reduxRender(<AccountUserList accountName="account" />);

/********** Number of columns : ************/

Expand Down Expand Up @@ -122,9 +117,7 @@ describe('AccountUserList', () => {
),
);

reduxRender(<AccountUserList accountName="account" />, {
wrapper,
});
reduxRender(<AccountUserList accountName="account" />);

await waitFor(() =>
screen.getByText(
Expand Down
17 changes: 4 additions & 13 deletions src/react/account/__tests__/CreateAccountPolicy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -45,9 +44,7 @@ afterAll(() => server.close());

describe('CreateAccountPolicy', () => {
it('should display all fields for CreateAccountPolicy form', async () => {
reduxRender(<CreateAccountPolicy />, {
wrapper,
});
reduxRender(<CreateAccountPolicy />);
expect(screen.getByText('Policy Creation')).toBeInTheDocument();
expect(screen.getByText('* are required fields')).toBeInTheDocument();
expect(
Expand All @@ -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(<CreateAccountPolicy />, {
wrapper,
});
reduxRender(<CreateAccountPolicy />);
const policyNameInput = screen.getByRole('textbox', {
name: /Policy name/i,
});
Expand All @@ -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(<CreateAccountPolicy />, {
wrapper,
});
reduxRender(<CreateAccountPolicy />);
const policyNameInput = screen.getByRole('textbox', {
name: /Policy name/i,
});
Expand All @@ -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(<CreateAccountPolicy />, {
wrapper,
});
reduxRender(<CreateAccountPolicy />);

const copyButton = screen.getByRole('button', { name: /copy policy/i });

Expand Down
22 changes: 5 additions & 17 deletions src/react/account/__tests__/UpdateAccountPolicy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -87,9 +83,7 @@ describe('UpdateAccountPolicy', () => {
afterAll(() => server.close());

it('should render readonly form when the policy is internal', async () => {
reduxRender(<UpdateAccountPolicy />, {
wrapper,
});
reduxRender(<UpdateAccountPolicy />);
await waitForElementToBeRemoved(
() => [...screen.queryAllByText(/Loading/i)],
{ timeout: 8000 },
Expand All @@ -114,9 +108,7 @@ describe('UpdateAccountPolicy', () => {
policyArn: 'arn:aws:iam::137489910101:policy/custom-policy',
defaultVersionId: 'v1',
});
reduxRender(<UpdateAccountPolicy />, {
wrapper,
});
reduxRender(<UpdateAccountPolicy />);
await waitForElementToBeRemoved(
() => [...screen.queryAllByText(/Loading/i)],
{ timeout: 8000 },
Expand All @@ -137,9 +129,7 @@ describe('UpdateAccountPolicy', () => {
expect(cancelButton).toBeInTheDocument();
});
it('should display fields policy name and ARN not empty', async () => {
reduxRender(<UpdateAccountPolicy />, {
wrapper,
});
reduxRender(<UpdateAccountPolicy />);
await waitForElementToBeRemoved(
() => [...screen.queryAllByText(/Loading/i)],
{ timeout: 8000 },
Expand All @@ -156,9 +146,7 @@ describe('UpdateAccountPolicy', () => {
policyArn: 'arn:aws:iam::137489910101:policy/custom-policy',
defaultVersionId: 'v1',
});
reduxRender(<UpdateAccountPolicy />, {
wrapper,
});
reduxRender(<UpdateAccountPolicy />);

await waitForElementToBeRemoved(
() => [...screen.queryAllByText(/Loading/i)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -167,9 +166,7 @@ const setupPolicyRender = (
jest.spyOn(router, 'useParams').mockReturnValue({
policyArn,
});
reduxRender(<Attachments />, {
wrapper,
});
reduxRender(<Attachments />);
};

describe('Policy Attachments', () => {
Expand Down Expand Up @@ -455,9 +452,7 @@ describe('User Attachments', () => {
jest.spyOn(router, 'useParams').mockReturnValue({
IAMUserName: userName,
});
reduxRender(<Attachments />, {
wrapper,
});
reduxRender(<Attachments />);
};

it('should render Groups and Policies for User Attachments Tabs', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -62,7 +61,6 @@ describe('Object Restoration Button And Modal', () => {
bucketName={bucketName}
objectMetadata={OBJECT_METADATA}
/>,
{ wrapper },
);
act(() => {
userEvent.click(selectors.restoreButtonSelector());
Expand Down Expand Up @@ -114,7 +112,6 @@ describe('Object Restoration Button And Modal', () => {
bucketName={bucketName}
objectMetadata={OBJECT_METADATA}
/>,
{ wrapper },
);
userEvent.click(selectors.restoreButtonSelector());
//V
Expand Down
4 changes: 2 additions & 2 deletions src/react/next-architecture/ui/MetricsAdapterProvider.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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();
Expand Down
1 change: 0 additions & 1 deletion src/react/utils/testUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
1 change: 0 additions & 1 deletion src/react/workflow/__tests__/TransitionForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { FormProvider, useForm } from 'react-hook-form';
import {
mockOffsetSize,
reduxRender,
Wrapper as wrapper,
zenkoUITestConfig,
} from '../../utils/testUtil';
import {
Expand Down

0 comments on commit 4cb1877

Please sign in to comment.