2023-10-27 13:21:07 +00:00
|
|
|
import { IntlProvider } from 'react-intl';
|
|
|
|
|
|
|
|
import { MemoryRouter } from 'react-router';
|
|
|
|
|
2024-06-28 11:39:32 +00:00
|
|
|
import type { RenderOptions } from '@testing-library/react';
|
2023-10-27 13:21:07 +00:00
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
import { render as rtlRender } from '@testing-library/react';
|
|
|
|
|
2024-05-20 07:29:27 +00:00
|
|
|
import { IdentityContext } from './identity_context';
|
2023-10-27 13:21:07 +00:00
|
|
|
|
2024-09-19 10:52:46 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
global.requestIdleCallback = jest
|
|
|
|
.fn()
|
|
|
|
.mockImplementation((fn: () => void) => {
|
|
|
|
fn();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2023-10-27 13:21:07 +00:00
|
|
|
function render(
|
|
|
|
ui: React.ReactElement,
|
2024-06-28 11:39:32 +00:00
|
|
|
{
|
|
|
|
locale = 'en',
|
|
|
|
signedIn = true,
|
|
|
|
...renderOptions
|
|
|
|
}: RenderOptions & { locale?: string; signedIn?: boolean } = {},
|
2023-10-27 13:21:07 +00:00
|
|
|
) {
|
2024-05-20 07:29:27 +00:00
|
|
|
const fakeIdentity = {
|
|
|
|
signedIn: signedIn,
|
|
|
|
accountId: '123',
|
|
|
|
disabledAccountId: undefined,
|
|
|
|
permissions: 0,
|
|
|
|
};
|
|
|
|
|
2024-02-27 16:07:43 +00:00
|
|
|
const Wrapper = (props: { children: React.ReactNode }) => {
|
2023-10-27 13:21:07 +00:00
|
|
|
return (
|
|
|
|
<MemoryRouter>
|
|
|
|
<IntlProvider locale={locale}>
|
2024-05-20 07:29:27 +00:00
|
|
|
<IdentityContext.Provider value={fakeIdentity}>
|
2023-10-27 13:21:07 +00:00
|
|
|
{props.children}
|
2024-05-20 07:29:27 +00:00
|
|
|
</IdentityContext.Provider>
|
2023-10-27 13:21:07 +00:00
|
|
|
</IntlProvider>
|
|
|
|
</MemoryRouter>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
|
|
|
|
}
|
|
|
|
|
|
|
|
// re-export everything
|
|
|
|
// eslint-disable-next-line import/no-extraneous-dependencies
|
|
|
|
export * from '@testing-library/react';
|
|
|
|
|
|
|
|
// override render method
|
|
|
|
export { render };
|