2024-03-18 13:58:05 +01:00
|
|
|
import type { FC } from 'react';
|
2022-05-05 13:42:18 +02:00
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
2024-03-18 13:58:05 +01:00
|
|
|
import {
|
|
|
|
render as rtlRender,
|
|
|
|
type RenderOptions,
|
|
|
|
} from '@testing-library/react';
|
2022-04-08 15:02:06 +02:00
|
|
|
import { SWRConfig } from 'swr';
|
2022-05-02 15:52:41 +02:00
|
|
|
import { ThemeProvider } from 'themes/ThemeProvider';
|
2024-03-18 13:58:05 +01:00
|
|
|
import type { IPermission } from 'interfaces/user';
|
2022-05-02 15:52:41 +02:00
|
|
|
import { AnnouncerProvider } from 'component/common/Announcer/AnnouncerProvider/AnnouncerProvider';
|
|
|
|
import { AccessProviderMock } from 'component/providers/AccessProvider/AccessProviderMock';
|
2023-10-06 09:19:49 +02:00
|
|
|
import { UIProviderContainer } from '../component/providers/UIProvider/UIProviderContainer';
|
2023-12-04 15:47:53 +01:00
|
|
|
import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';
|
|
|
|
import { QueryParamProvider } from 'use-query-params';
|
2024-01-03 15:43:22 +01:00
|
|
|
import { FeedbackProvider } from 'component/feedbackNew/FeedbackProvider';
|
2024-07-17 15:03:02 +02:00
|
|
|
import { StickyProvider } from 'component/common/Sticky/StickyProvider';
|
2022-04-08 12:26:44 +02:00
|
|
|
|
|
|
|
export const render = (
|
|
|
|
ui: JSX.Element,
|
|
|
|
{
|
|
|
|
route = '/',
|
2022-05-02 12:52:33 +02:00
|
|
|
permissions = [],
|
2022-04-08 12:26:44 +02:00
|
|
|
...renderOptions
|
2022-05-02 12:52:33 +02:00
|
|
|
}: { route?: string; permissions?: IPermission[] } & Omit<
|
|
|
|
RenderOptions,
|
|
|
|
'queries'
|
2023-10-02 14:25:46 +02:00
|
|
|
> = {},
|
2022-04-08 12:26:44 +02:00
|
|
|
) => {
|
2023-12-20 09:16:45 +01:00
|
|
|
if (!route.startsWith('/')) {
|
|
|
|
throw new Error('Route must start with a /');
|
|
|
|
}
|
|
|
|
|
2022-04-08 12:26:44 +02:00
|
|
|
window.history.pushState({}, 'Test page', route);
|
|
|
|
|
2024-06-11 12:59:52 +02:00
|
|
|
const Wrapper: FC<{ children?: React.ReactNode }> = ({ children }) => (
|
|
|
|
<SWRConfig
|
|
|
|
value={{
|
|
|
|
provider: () => new Map(),
|
|
|
|
isVisible() {
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
dedupingInterval: 0,
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
<UIProviderContainer>
|
|
|
|
<FeedbackProvider>
|
2024-01-03 15:43:22 +01:00
|
|
|
<AccessProviderMock permissions={permissions}>
|
|
|
|
<BrowserRouter>
|
|
|
|
<QueryParamProvider adapter={ReactRouter6Adapter}>
|
|
|
|
<ThemeProvider>
|
|
|
|
<AnnouncerProvider>
|
2024-07-17 15:03:02 +02:00
|
|
|
<StickyProvider>
|
|
|
|
{children}
|
|
|
|
</StickyProvider>
|
2024-01-03 15:43:22 +01:00
|
|
|
</AnnouncerProvider>
|
|
|
|
</ThemeProvider>
|
|
|
|
</QueryParamProvider>
|
|
|
|
</BrowserRouter>
|
|
|
|
</AccessProviderMock>
|
2024-06-11 12:59:52 +02:00
|
|
|
</FeedbackProvider>
|
|
|
|
</UIProviderContainer>
|
|
|
|
</SWRConfig>
|
2022-04-08 15:02:06 +02:00
|
|
|
);
|
2022-05-02 12:52:33 +02:00
|
|
|
|
|
|
|
return rtlRender(ui, {
|
|
|
|
wrapper: Wrapper,
|
|
|
|
...renderOptions,
|
|
|
|
});
|
2022-04-08 15:02:06 +02:00
|
|
|
};
|