mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 12:43:13 +00:00
* chore: upgrade frontend application dependencies * chore: upgrade frontend infrastructure dependencies * fix: align lockfiles with CI npm * fix: preserve ky error semantics * fix: sanitize timeout error message
62 lines
1.7 KiB
TypeScript
62 lines
1.7 KiB
TypeScript
import { CssBaseline, ThemeProvider } from "@mui/material";
|
|
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
|
|
import { render, type RenderOptions } from "@testing-library/react";
|
|
import type { ReactElement, ReactNode } from "react";
|
|
import { MemoryRouter, type MemoryRouterProps } from "react-router";
|
|
|
|
import { muiTheme } from "@/lib/theme/mui-theme";
|
|
import { AuthProvider } from "@/providers/auth-provider";
|
|
|
|
export function createTestQueryClient(): QueryClient {
|
|
return new QueryClient({
|
|
defaultOptions: {
|
|
queries: {
|
|
retry: false,
|
|
gcTime: 0,
|
|
},
|
|
mutations: {
|
|
retry: false,
|
|
},
|
|
},
|
|
});
|
|
}
|
|
|
|
type RenderWithProvidersOptions = Omit<RenderOptions, "wrapper"> & {
|
|
route?: string;
|
|
routerProps?: Omit<MemoryRouterProps, "children">;
|
|
withAuth?: boolean;
|
|
queryClient?: QueryClient;
|
|
};
|
|
|
|
export function renderWithProviders(
|
|
ui: ReactElement,
|
|
{
|
|
route = "/",
|
|
routerProps,
|
|
withAuth = true,
|
|
queryClient = createTestQueryClient(),
|
|
...renderOptions
|
|
}: RenderWithProvidersOptions = {},
|
|
) {
|
|
const initialEntries = routerProps?.initialEntries ?? [route];
|
|
|
|
function Wrapper({ children }: { children: ReactNode }) {
|
|
const content = withAuth ? <AuthProvider>{children}</AuthProvider> : children;
|
|
|
|
return (
|
|
<QueryClientProvider client={queryClient}>
|
|
<ThemeProvider theme={muiTheme}>
|
|
<CssBaseline />
|
|
<MemoryRouter {...routerProps} initialEntries={initialEntries}>
|
|
{content}
|
|
</MemoryRouter>
|
|
</ThemeProvider>
|
|
</QueryClientProvider>
|
|
);
|
|
}
|
|
|
|
return {
|
|
...render(ui, { wrapper: Wrapper, ...renderOptions }),
|
|
queryClient,
|
|
};
|
|
}
|