From bd9ec5d1b0802cde3f391b0264aa740d78999be1 Mon Sep 17 00:00:00 2001 From: Matthew Warman Date: Wed, 22 May 2024 15:13:28 -0400 Subject: [PATCH] lint fixes --- .../Header/__tests__/AppMenu.test.tsx | 3 +- src/test/AllProvidersExceptRouter.tsx | 25 ++++++++++ src/test/WithAllProviders.tsx | 28 +++++++++++ src/test/query-client.ts | 9 ++++ src/test/test-utils.tsx | 48 +------------------ vitest.setup.ts | 2 +- 6 files changed, 67 insertions(+), 48 deletions(-) create mode 100644 src/test/AllProvidersExceptRouter.tsx create mode 100644 src/test/WithAllProviders.tsx create mode 100644 src/test/query-client.ts diff --git a/src/components/Header/__tests__/AppMenu.test.tsx b/src/components/Header/__tests__/AppMenu.test.tsx index 302a1e1..cdea317 100644 --- a/src/components/Header/__tests__/AppMenu.test.tsx +++ b/src/components/Header/__tests__/AppMenu.test.tsx @@ -1,5 +1,6 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'; -import { queryClient, render, screen } from 'test/test-utils'; +import { render, screen } from 'test/test-utils'; +import { queryClient } from 'test/query-client'; import { UseQueryResult } from '@tanstack/react-query'; import * as UseAuth from 'hooks/useAuth'; diff --git a/src/test/AllProvidersExceptRouter.tsx b/src/test/AllProvidersExceptRouter.tsx new file mode 100644 index 0000000..91a534c --- /dev/null +++ b/src/test/AllProvidersExceptRouter.tsx @@ -0,0 +1,25 @@ +import { PropsWithChildren } from 'react'; +import { QueryClientProvider } from '@tanstack/react-query'; + +import ConfigContextProvider from 'providers/ConfigProvider'; +import SettingsContextProvider from 'providers/SettingsProvider'; +import AuthContextProvider from 'providers/AuthProvider'; +import ToastsProvider from 'providers/ToastsProvider'; + +import { queryClient } from './query-client'; + +const AllProvidersExceptRouter = ({ children }: PropsWithChildren): JSX.Element => { + return ( + + + + + {children} + + + + + ); +}; + +export default AllProvidersExceptRouter; diff --git a/src/test/WithAllProviders.tsx b/src/test/WithAllProviders.tsx new file mode 100644 index 0000000..c465b98 --- /dev/null +++ b/src/test/WithAllProviders.tsx @@ -0,0 +1,28 @@ +import { PropsWithChildren } from 'react'; +import { MemoryRouter } from 'react-router-dom'; +import { QueryClientProvider } from '@tanstack/react-query'; + +import ConfigContextProvider from 'providers/ConfigProvider'; +import SettingsContextProvider from 'providers/SettingsProvider'; +import AuthContextProvider from 'providers/AuthProvider'; +import ToastsProvider from 'providers/ToastsProvider'; + +import { queryClient } from './query-client'; + +const WithAllProviders = ({ children }: PropsWithChildren): JSX.Element => { + return ( + + + + + + {children} + + + + + + ); +}; + +export default WithAllProviders; diff --git a/src/test/query-client.ts b/src/test/query-client.ts new file mode 100644 index 0000000..dafe7d4 --- /dev/null +++ b/src/test/query-client.ts @@ -0,0 +1,9 @@ +import { QueryClient } from '@tanstack/react-query'; + +export const queryClient = new QueryClient({ + defaultOptions: { + queries: { + retry: false, + }, + }, +}); diff --git a/src/test/test-utils.tsx b/src/test/test-utils.tsx index 137359d..a3936b0 100644 --- a/src/test/test-utils.tsx +++ b/src/test/test-utils.tsx @@ -6,52 +6,7 @@ import { RenderHookOptions, RenderOptions, } from '@testing-library/react'; -import { PropsWithChildren } from 'react'; -import { MemoryRouter } from 'react-router-dom'; -import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; - -import ConfigContextProvider from 'providers/ConfigProvider'; -import SettingsContextProvider from 'providers/SettingsProvider'; -import AuthContextProvider from 'providers/AuthProvider'; -import ToastsProvider from 'providers/ToastsProvider'; - -export const queryClient = new QueryClient({ - defaultOptions: { - queries: { - retry: false, - }, - }, -}); - -const WithAllProviders = ({ children }: PropsWithChildren): JSX.Element => { - return ( - - - - - - {children} - - - - - - ); -}; - -export const AllProvidersExceptRouter = ({ children }: PropsWithChildren): JSX.Element => { - return ( - - - - - {children} - - - - - ); -}; +import WithAllProviders from './WithAllProviders'; const customRender = (ui: React.ReactElement, options?: RenderOptions, { route = '/' } = {}) => { window.history.pushState({}, 'Test page', route); @@ -73,6 +28,7 @@ function customRenderHook< } // re-export @testing-library/react +// eslint-disable-next-line export * from '@testing-library/react'; // override the render function diff --git a/vitest.setup.ts b/vitest.setup.ts index 1af8f19..1d42b77 100644 --- a/vitest.setup.ts +++ b/vitest.setup.ts @@ -1,7 +1,7 @@ import { afterAll, afterEach, beforeAll } from 'vitest'; import { server } from './src/test/mocks/server'; -import { queryClient } from './src/test/test-utils'; +import { queryClient } from './src/test/query-client'; beforeAll(() => { server.listen();