1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-07-19 05:19:39 +02:00
portainer/app/react-tools/test-utils.tsx
Chaim Lev-Ari ecd0eb6170
refactor(app): create access-control-form react component [EE-2332] (#6346)
* refactor(app): create access-control-form react component [EE-2332]

fix [EE-2332]

* chore(tests): setup msw for async tests and stories

chore(sb): add msw support for storybook

* refactor(access-control): move loading into component

* fix(app): fix users and teams selector stories

* chore(access-control): write test for validation
2022-01-05 18:28:56 +02:00

38 lines
1.2 KiB
TypeScript

import '@testing-library/jest-dom';
import { render, RenderOptions } from '@testing-library/react';
import { UIRouter, pushStateLocationPlugin } from '@uirouter/react';
import { PropsWithChildren, ReactElement } from 'react';
import { QueryClient, QueryClientProvider } from 'react-query';
function Provider({ children }: PropsWithChildren<unknown>) {
return <UIRouter plugins={[pushStateLocationPlugin]}>{children}</UIRouter>;
}
function customRender(ui: ReactElement, options?: RenderOptions) {
return render(ui, { wrapper: Provider, ...options });
}
// re-export everything
export * from '@testing-library/react';
// override render method
export { customRender as render };
export function renderWithQueryClient(ui: React.ReactElement) {
const testQueryClient = new QueryClient({
defaultOptions: { queries: { retry: false } },
});
const { rerender, ...result } = customRender(
<QueryClientProvider client={testQueryClient}>{ui}</QueryClientProvider>
);
return {
...result,
rerender: (rerenderUi: React.ReactElement) =>
rerender(
<QueryClientProvider client={testQueryClient}>
{rerenderUi}
</QueryClientProvider>
),
};
}