import { render, RenderOptions, RenderResult } from '@testing-library/react'; import ROUTES from 'constants/routes'; import { ResourceProvider } from 'hooks/useResourceAttribute'; import React, { ReactElement } from 'react'; import { QueryClient, QueryClientProvider } from 'react-query'; import { Provider } from 'react-redux'; import { BrowserRouter } from 'react-router-dom'; import configureStore from 'redux-mock-store'; import store from 'store'; const queryClient = new QueryClient({ defaultOptions: { queries: { refetchOnWindowFocus: false, }, }, }); beforeEach(() => { jest.useFakeTimers(); jest.setSystemTime(new Date('2023-10-20')); }); afterEach(() => { queryClient.clear(); jest.useRealTimers(); }); const mockStore = configureStore([]); const mockStored = (role?: string): any => mockStore({ ...store.getState(), app: { ...store.getState().app, role, // Use the role provided user: { userId: '6f532456-8cc0-4514-a93b-aed665c32b47', email: 'test@signoz.io', name: 'TestUser', profilePictureURL: '', accessJwt: '', refreshJwt: '', }, }, }); jest.mock('react-i18next', () => ({ useTranslation: (): { t: (str: string) => string; i18n: { changeLanguage: () => Promise; }; } => ({ t: (str: string): string => str, i18n: { changeLanguage: (): Promise => new Promise(() => {}), }, }), })); jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useLocation: (): { pathname: string } => ({ pathname: `${process.env.FRONTEND_API_ENDPOINT}/${ROUTES.TRACES_EXPLORER}/`, }), })); function AllTheProviders({ children, role, // Accept the role as a prop }: { children: React.ReactNode; role: string; // Define the role prop }): ReactElement { return ( {' '} {/* Use the mock store with the provided role */} {children} ); } const customRender = ( ui: ReactElement, options?: Omit, role = 'ADMIN', // Set a default role ): RenderResult => render(ui, { wrapper: () => {ui}, ...options, }); export * from '@testing-library/react'; export { customRender as render };