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 & { route?: string; routerProps?: Omit; 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 ? {children} : children; return ( {content} ); } return { ...render(ui, { wrapper: Wrapper, ...renderOptions }), queryClient, }; }