Skip to content

Commit

Permalink
lint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed May 22, 2024
1 parent 3f34367 commit bd9ec5d
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 48 deletions.
3 changes: 2 additions & 1 deletion src/components/Header/__tests__/AppMenu.test.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
25 changes: 25 additions & 0 deletions src/test/AllProvidersExceptRouter.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<ConfigContextProvider>
<QueryClientProvider client={queryClient}>
<SettingsContextProvider>
<AuthContextProvider>
<ToastsProvider>{children}</ToastsProvider>
</AuthContextProvider>
</SettingsContextProvider>
</QueryClientProvider>
</ConfigContextProvider>
);
};

export default AllProvidersExceptRouter;
28 changes: 28 additions & 0 deletions src/test/WithAllProviders.tsx
Original file line number Diff line number Diff line change
@@ -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 (
<ConfigContextProvider>
<QueryClientProvider client={queryClient}>
<SettingsContextProvider>
<AuthContextProvider>
<ToastsProvider>
<MemoryRouter>{children}</MemoryRouter>
</ToastsProvider>
</AuthContextProvider>
</SettingsContextProvider>
</QueryClientProvider>
</ConfigContextProvider>
);
};

export default WithAllProviders;
9 changes: 9 additions & 0 deletions src/test/query-client.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { QueryClient } from '@tanstack/react-query';

export const queryClient = new QueryClient({
defaultOptions: {
queries: {
retry: false,
},
},
});
48 changes: 2 additions & 46 deletions src/test/test-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<ConfigContextProvider>
<QueryClientProvider client={queryClient}>
<SettingsContextProvider>
<AuthContextProvider>
<ToastsProvider>
<MemoryRouter>{children}</MemoryRouter>
</ToastsProvider>
</AuthContextProvider>
</SettingsContextProvider>
</QueryClientProvider>
</ConfigContextProvider>
);
};

export const AllProvidersExceptRouter = ({ children }: PropsWithChildren): JSX.Element => {
return (
<ConfigContextProvider>
<QueryClientProvider client={queryClient}>
<SettingsContextProvider>
<AuthContextProvider>
<ToastsProvider>{children}</ToastsProvider>
</AuthContextProvider>
</SettingsContextProvider>
</QueryClientProvider>
</ConfigContextProvider>
);
};
import WithAllProviders from './WithAllProviders';

const customRender = (ui: React.ReactElement, options?: RenderOptions, { route = '/' } = {}) => {
window.history.pushState({}, 'Test page', route);
Expand All @@ -73,6 +28,7 @@ function customRenderHook<
}

// re-export @testing-library/react
// eslint-disable-next-line
export * from '@testing-library/react';

// override the render function
Expand Down
2 changes: 1 addition & 1 deletion vitest.setup.ts
Original file line number Diff line number Diff line change
@@ -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();
Expand Down

0 comments on commit bd9ec5d

Please sign in to comment.