2022-04-08 16:01:43 +02:00
|
|
|
import React, { FC } from 'react';
|
2022-05-05 13:42:18 +02:00
|
|
|
import { BrowserRouter } from 'react-router-dom';
|
2022-04-08 12:26:44 +02:00
|
|
|
import { render as rtlRender, 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';
|
2022-05-02 12:52:33 +02:00
|
|
|
import { 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';
|
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
|
|
|
) => {
|
|
|
|
window.history.pushState({}, 'Test page', route);
|
|
|
|
|
2022-05-02 12:52:33 +02:00
|
|
|
const Wrapper: FC = ({ children }) => (
|
2023-10-06 09:19:49 +02:00
|
|
|
<UIProviderContainer>
|
2023-11-23 09:50:19 +01:00
|
|
|
<SWRConfig
|
|
|
|
value={{ provider: () => new Map(), dedupingInterval: 0 }}
|
|
|
|
>
|
2023-10-06 09:19:49 +02:00
|
|
|
<AccessProviderMock permissions={permissions}>
|
2023-12-04 15:47:53 +01:00
|
|
|
<BrowserRouter>
|
|
|
|
<QueryParamProvider adapter={ReactRouter6Adapter}>
|
|
|
|
<ThemeProvider>
|
|
|
|
<AnnouncerProvider>
|
|
|
|
{children}
|
|
|
|
</AnnouncerProvider>
|
|
|
|
</ThemeProvider>
|
|
|
|
</QueryParamProvider>
|
|
|
|
</BrowserRouter>
|
2023-10-06 09:19:49 +02:00
|
|
|
</AccessProviderMock>
|
|
|
|
</SWRConfig>
|
|
|
|
</UIProviderContainer>
|
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
|
|
|
};
|