1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00
unleash.unleash/frontend/src/utils/testRenderer.tsx

45 lines
1.5 KiB
TypeScript
Raw Normal View History

import React, { FC } from 'react';
import { BrowserRouter } from 'react-router-dom';
import { render as rtlRender, RenderOptions } from '@testing-library/react';
import { SWRConfig } from 'swr';
import { ThemeProvider } from 'themes/ThemeProvider';
import { IPermission } from 'interfaces/user';
import { AnnouncerProvider } from 'component/common/Announcer/AnnouncerProvider/AnnouncerProvider';
import { AccessProviderMock } from 'component/providers/AccessProvider/AccessProviderMock';
import { UIProviderContainer } from '../component/providers/UIProvider/UIProviderContainer';
export const render = (
ui: JSX.Element,
{
route = '/',
permissions = [],
...renderOptions
}: { route?: string; permissions?: IPermission[] } & Omit<
RenderOptions,
'queries'
> = {},
) => {
window.history.pushState({}, 'Test page', route);
const Wrapper: FC = ({ children }) => (
<UIProviderContainer>
<SWRConfig
value={{ provider: () => new Map(), dedupingInterval: 0 }}
>
<AccessProviderMock permissions={permissions}>
<ThemeProvider>
<AnnouncerProvider>
<BrowserRouter>{children}</BrowserRouter>
</AnnouncerProvider>
</ThemeProvider>
</AccessProviderMock>
</SWRConfig>
</UIProviderContainer>
);
return rtlRender(ui, {
wrapper: Wrapper,
...renderOptions,
});
};