1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-07-26 13:48:33 +02:00
unleash.unleash/frontend/src/utils/testRenderer.tsx
Nuno Góis 38bd50dc8a
refactor: introduce a highlight reusable component (#8643)
Follow-up to: https://github.com/Unleash/unleash/pull/8642

Introduces a reusable `Highlight` component that leverages the Context
API pattern, enabling highlight effects to be triggered from anywhere in
the application.

This update refactors the existing highlight effect in the event
timeline to use the new Highlight component and extends the
functionality to include the Unleash AI experiment, triggered by its
entry in the "New in Unleash" section.
2024-11-05 09:21:19 +00:00

73 lines
2.7 KiB
TypeScript

import type { FC } from 'react';
import { BrowserRouter } from 'react-router-dom';
import {
render as rtlRender,
type RenderOptions,
} from '@testing-library/react';
import { SWRConfig } from 'swr';
import { ThemeProvider } from 'themes/ThemeProvider';
import type { 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';
import { ReactRouter6Adapter } from 'use-query-params/adapters/react-router-6';
import { QueryParamProvider } from 'use-query-params';
import { FeedbackProvider } from 'component/feedbackNew/FeedbackProvider';
import { StickyProvider } from 'component/common/Sticky/StickyProvider';
import { HighlightProvider } from 'component/common/Highlight/HighlightProvider';
export const render = (
ui: JSX.Element,
{
route = '/',
permissions = [],
...renderOptions
}: { route?: string; permissions?: IPermission[] } & Omit<
RenderOptions,
'queries'
> = {},
) => {
if (!route.startsWith('/')) {
throw new Error('Route must start with a /');
}
window.history.pushState({}, 'Test page', route);
const Wrapper: FC<{ children?: React.ReactNode }> = ({ children }) => (
<SWRConfig
value={{
provider: () => new Map(),
isVisible() {
return true;
},
dedupingInterval: 0,
}}
>
<UIProviderContainer>
<FeedbackProvider>
<AccessProviderMock permissions={permissions}>
<BrowserRouter>
<QueryParamProvider adapter={ReactRouter6Adapter}>
<ThemeProvider>
<AnnouncerProvider>
<StickyProvider>
<HighlightProvider>
{children}
</HighlightProvider>
</StickyProvider>
</AnnouncerProvider>
</ThemeProvider>
</QueryParamProvider>
</BrowserRouter>
</AccessProviderMock>
</FeedbackProvider>
</UIProviderContainer>
</SWRConfig>
);
return rtlRender(ui, {
wrapper: Wrapper,
...renderOptions,
});
};