1
0
mirror of https://github.com/funamitech/mastodon synced 2024-12-12 05:39:02 +09:00
YuruToot/app/javascript/mastodon/test_helpers.tsx

54 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-10-27 22:21:07 +09:00
import { IntlProvider } from 'react-intl';
import { MemoryRouter } from 'react-router';
import type { RenderOptions } from '@testing-library/react';
2023-10-27 22:21:07 +09:00
// eslint-disable-next-line import/no-extraneous-dependencies
import { render as rtlRender } from '@testing-library/react';
import { IdentityContext } from './identity_context';
2023-10-27 22:21:07 +09:00
beforeEach(() => {
global.requestIdleCallback = jest
.fn()
.mockImplementation((fn: () => void) => {
fn();
});
});
2023-10-27 22:21:07 +09:00
function render(
ui: React.ReactElement,
{
locale = 'en',
signedIn = true,
...renderOptions
}: RenderOptions & { locale?: string; signedIn?: boolean } = {},
2023-10-27 22:21:07 +09:00
) {
const fakeIdentity = {
signedIn: signedIn,
accountId: '123',
disabledAccountId: undefined,
permissions: 0,
};
const Wrapper = (props: { children: React.ReactNode }) => {
2023-10-27 22:21:07 +09:00
return (
<MemoryRouter>
<IntlProvider locale={locale}>
<IdentityContext.Provider value={fakeIdentity}>
2023-10-27 22:21:07 +09:00
{props.children}
</IdentityContext.Provider>
2023-10-27 22:21:07 +09: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 };