mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2026-03-11 10:03:51 +00:00
Set everything up to use hooks for reduc actions and state
This commit is contained in:
28
test/__helpers__/setUpTest.tsx
Normal file
28
test/__helpers__/setUpTest.tsx
Normal file
@@ -0,0 +1,28 @@
|
||||
import type { RenderOptions } from '@testing-library/react';
|
||||
import { render } from '@testing-library/react';
|
||||
import userEvent from '@testing-library/user-event';
|
||||
import type { PropsWithChildren, ReactElement } from 'react';
|
||||
import { Provider } from 'react-redux';
|
||||
import { setUpStore } from '../../src/container/store';
|
||||
import type { ShlinkState } from '../../src/container/types';
|
||||
|
||||
export const renderWithEvents = (element: ReactElement, options?: RenderOptions) => ({
|
||||
user: userEvent.setup(),
|
||||
...render(element, options),
|
||||
});
|
||||
|
||||
export type RenderOptionsWithState = Omit<RenderOptions, 'wrapper'> & {
|
||||
initialState?: Partial<ShlinkState>;
|
||||
};
|
||||
|
||||
export const renderWithStore = (
|
||||
element: ReactElement,
|
||||
{ initialState = {}, ...options }: RenderOptionsWithState = {},
|
||||
) => {
|
||||
const Wrapper = ({ children }: PropsWithChildren) => (
|
||||
<Provider store={setUpStore(initialState)}>
|
||||
{children}
|
||||
</Provider>
|
||||
);
|
||||
return renderWithEvents(element, { ...options, wrapper: Wrapper });
|
||||
};
|
||||
Reference in New Issue
Block a user