diff --git a/src/component/admin/apiToken/ApiTokenList/ProjectsList/ProjectsList.tsx b/src/component/admin/apiToken/ApiTokenList/ProjectsList/ProjectsList.tsx index c7d69d8a3f..7cca5b4b52 100644 --- a/src/component/admin/apiToken/ApiTokenList/ProjectsList/ProjectsList.tsx +++ b/src/component/admin/apiToken/ApiTokenList/ProjectsList/ProjectsList.tsx @@ -10,7 +10,12 @@ export const ProjectsList: VFC = ({ projects, project, }) => { - let fields = projects && Array.isArray(projects) ? projects : [project]; + let fields: string[] = + projects && Array.isArray(projects) + ? projects + : project + ? [project] + : []; if (fields.length === 0) { return <>*; diff --git a/src/component/user/Authentication/Authentication.test.tsx b/src/component/user/Authentication/Authentication.test.tsx index 8a36fc60b5..481aa00cc4 100644 --- a/src/component/user/Authentication/Authentication.test.tsx +++ b/src/component/user/Authentication/Authentication.test.tsx @@ -1,5 +1,5 @@ import Authentication from 'component/user/Authentication/Authentication'; -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import { LOGIN_PASSWORD_ID, LOGIN_EMAIL_ID, @@ -8,7 +8,7 @@ import { SSO_LOGIN_BUTTON, } from 'utils/testIds'; import React from 'react'; -import { TestContext } from 'utils/testContext'; +import { render } from 'utils/testRenderer'; import { testServerSetup, testServerRoute } from 'utils/testServer'; const server = testServerSetup(); @@ -22,11 +22,7 @@ test('should render password auth', async () => { options: [], }); - render( - - - - ); + render(); await screen.findByTestId(AUTH_PAGE_ID); expect(screen.getByTestId(LOGIN_EMAIL_ID)).toBeInTheDocument(); @@ -43,11 +39,7 @@ test('should not render password auth if defaultHidden is true', async () => { options: [], }); - render( - - - - ); + render(); await screen.findByTestId(AUTH_PAGE_ID); expect(screen.queryByTestId(LOGIN_EMAIL_ID)).not.toBeInTheDocument(); @@ -64,11 +56,7 @@ test('should render demo auth', async () => { options: [], }); - render( - - - - ); + render(); await screen.findByTestId(AUTH_PAGE_ID); expect(screen.getByTestId(LOGIN_EMAIL_ID)).toBeInTheDocument(); @@ -85,11 +73,7 @@ test('should render email auth', async () => { options: [], }); - render( - - - - ); + render(); await screen.findByTestId(AUTH_PAGE_ID); expect(screen.getByTestId(LOGIN_EMAIL_ID)).toBeInTheDocument(); @@ -121,11 +105,7 @@ const testSSOAuthOption = async (authOption: string) => { type: 'password', }); - render( - - - - ); + render(); const ssoLink = await screen.findByTestId(testId); expect(ssoLink.getAttribute('href')).toEqual(path); diff --git a/src/component/user/ForgottenPassword/ForgottenPassword.test.tsx b/src/component/user/ForgottenPassword/ForgottenPassword.test.tsx index 9b31f06c21..2004205fcc 100644 --- a/src/component/user/ForgottenPassword/ForgottenPassword.test.tsx +++ b/src/component/user/ForgottenPassword/ForgottenPassword.test.tsx @@ -1,15 +1,11 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import { FORGOTTEN_PASSWORD_FIELD } from 'utils/testIds'; import React from 'react'; -import { TestContext } from 'utils/testContext'; import ForgottenPassword from 'component/user/ForgottenPassword/ForgottenPassword'; +import { render } from 'utils/testRenderer'; test('should render password auth', async () => { - render( - - - - ); + render(); await screen.findByTestId(FORGOTTEN_PASSWORD_FIELD); }); diff --git a/src/component/user/ResetPassword/ResetPassword.test.tsx b/src/component/user/ResetPassword/ResetPassword.test.tsx index b8b3907618..fea67c3de8 100644 --- a/src/component/user/ResetPassword/ResetPassword.test.tsx +++ b/src/component/user/ResetPassword/ResetPassword.test.tsx @@ -1,11 +1,10 @@ -import { render, screen } from '@testing-library/react'; +import { screen } from '@testing-library/react'; import { INVALID_TOKEN_BUTTON } from 'utils/testIds'; import React from 'react'; -import { TestContext } from 'utils/testContext'; import ResetPassword from 'component/user/ResetPassword/ResetPassword'; -import { MemoryRouter } from 'react-router-dom'; import { INVALID_TOKEN_ERROR } from 'hooks/api/getters/useResetPassword/useResetPassword'; import { testServerSetup, testServerRoute } from 'utils/testServer'; +import { render } from 'utils/testRenderer'; const server = testServerSetup(); @@ -14,13 +13,7 @@ test('should render password auth', async () => { name: INVALID_TOKEN_ERROR, }); - render( - - - - - - ); + render(, { route: '/new-user?token=invalid' }); await screen.findByTestId(INVALID_TOKEN_BUTTON); }); diff --git a/src/utils/testContext.tsx b/src/utils/testContext.tsx deleted file mode 100644 index 40fb4ab264..0000000000 --- a/src/utils/testContext.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import { SWRConfig } from 'swr'; -import { MemoryRouter } from 'react-router-dom'; -import { ThemeProvider } from '@material-ui/core/styles'; -import theme from 'themes/mainTheme'; -import React from 'react'; - -export const TestContext: React.FC = ({ children }) => { - return ( - new Map() }}> - - {children} - - - ); -}; diff --git a/src/utils/testRenderer.tsx b/src/utils/testRenderer.tsx index 1436a9d1bb..3609aba746 100644 --- a/src/utils/testRenderer.tsx +++ b/src/utils/testRenderer.tsx @@ -1,5 +1,9 @@ -import { BrowserRouter as Router } from 'react-router-dom'; import { render as rtlRender, RenderOptions } from '@testing-library/react'; +import { SWRConfig } from 'swr'; +import { ThemeProvider } from '@material-ui/core/styles'; +import theme from 'themes/mainTheme'; +import React from 'react'; +import { BrowserRouter } from 'react-router-dom'; export const render = ( ui: JSX.Element, @@ -11,7 +15,17 @@ export const render = ( window.history.pushState({}, 'Test page', route); return rtlRender(ui, { - wrapper: Router, + wrapper: Wrapper, ...renderOptions, }); }; + +const Wrapper: React.FC = ({ children }) => { + return ( + new Map() }}> + + {children} + + + ); +};