2022-02-21 09:25:47 -06:00
|
|
|
import { AnyAction, configureStore } from '@reduxjs/toolkit';
|
|
|
|
import { ThunkMiddlewareFor } from '@reduxjs/toolkit/dist/getDefaultMiddleware';
|
2022-04-22 08:33:13 -05:00
|
|
|
import { render as rtlRender } from '@testing-library/react';
|
|
|
|
import React from 'react';
|
2022-02-21 09:25:47 -06:00
|
|
|
import { Provider } from 'react-redux';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-02-21 09:25:47 -06:00
|
|
|
import { createRootReducer } from 'app/core/reducers/root';
|
|
|
|
import { StoreState } from 'app/types';
|
2022-04-22 08:33:13 -05:00
|
|
|
|
2022-02-21 09:25:47 -06:00
|
|
|
import { mockNavModel } from './mocks/navModel';
|
|
|
|
|
|
|
|
function render(
|
|
|
|
ui: React.ReactElement,
|
|
|
|
{
|
|
|
|
preloadedState = { navIndex: mockNavModel },
|
|
|
|
store = configureStore<
|
|
|
|
StoreState,
|
|
|
|
AnyAction,
|
|
|
|
ReadonlyArray<ThunkMiddlewareFor<StoreState, { thunk: true; serializableCheck: false; immutableCheck: false }>>
|
|
|
|
>({
|
|
|
|
reducer: createRootReducer(),
|
|
|
|
preloadedState,
|
|
|
|
middleware: (getDefaultMiddleware) =>
|
|
|
|
getDefaultMiddleware({ thunk: true, serializableCheck: false, immutableCheck: false }),
|
|
|
|
}),
|
|
|
|
...renderOptions
|
|
|
|
}: { preloadedState?: Partial<StoreState>; store?: ReturnType<typeof configureStore> } = {}
|
|
|
|
) {
|
|
|
|
function Wrapper({ children }: { children: React.ReactNode }) {
|
|
|
|
return <Provider store={store}>{children}</Provider>;
|
|
|
|
}
|
|
|
|
|
|
|
|
return rtlRender(ui, { wrapper: Wrapper, ...renderOptions });
|
|
|
|
}
|
|
|
|
|
|
|
|
export { render };
|