1 import type { ReactElement, ReactNode } from 'react';
2 import * as React from 'react';
3 import { Router } from 'react-router';
5 import { render as originalRender } from '@testing-library/react';
6 import { renderHook as originalRenderHook } from '@testing-library/react-hooks';
7 import { createMemoryHistory } from 'history';
9 import { CacheProvider, ConfigProvider, ModalsChildren, ModalsProvider } from '@proton/components';
10 import { APPS } from '@proton/shared/lib/constants';
11 import createCache from '@proton/shared/lib/helpers/cache';
12 import type { ProtonConfig } from '@proton/shared/lib/interfaces';
14 import NotificationsTestProvider from './NotificationsTestProvider';
16 jest.mock('@proton/shared/lib/helpers/setupCryptoWorker', () => ({
18 loadCryptoWorker: jest.fn(),
21 const history = createMemoryHistory({ initialEntries: ['/'] });
24 APP_NAME: APPS.PROTONCALENDAR,
25 APP_VERSION: 'test-app-version',
26 DATE_VERSION: 'test-date-version',
29 const TestProvider = ({ children }: { children: ReactNode }) => (
30 <ConfigProvider config={config}>
31 <NotificationsTestProvider>
33 <CacheProvider cache={createCache()}>
35 <Router history={history}>{children}</Router>
38 </NotificationsTestProvider>
42 export const render = (ui: ReactElement) =>
44 wrapper: TestProvider,
47 export const renderHook = <TProps, TResult>(callback: (props: TProps) => TResult) =>
48 originalRenderHook<TProps, TResult>(callback, { wrapper: TestProvider as any });