diff --git a/test/__helpers__/TestModalWrapper.tsx b/test/__helpers__/TestModalWrapper.tsx new file mode 100644 index 00000000..e2364192 --- /dev/null +++ b/test/__helpers__/TestModalWrapper.tsx @@ -0,0 +1,14 @@ +import { FC, ReactElement } from 'react'; +import { useToggle } from '../../src/utils/helpers/hooks'; + +interface RenderModalArgs { + isOpen: boolean; + toggle: () => void; +} + +export const TestModalWrapper: FC<{ renderModal: (args: RenderModalArgs) => ReactElement }> = ( + { renderModal }, +) => { + const [isOpen, toggle] = useToggle(true); + return renderModal({ isOpen, toggle }); +}; diff --git a/test/servers/DeleteServerModal.test.tsx b/test/servers/DeleteServerModal.test.tsx index 0e89afa9..0a5affe5 100644 --- a/test/servers/DeleteServerModal.test.tsx +++ b/test/servers/DeleteServerModal.test.tsx @@ -1,27 +1,13 @@ -import { FC } from 'react'; import { screen, waitFor } from '@testing-library/react'; import { Mock } from 'ts-mockery'; import { useNavigate } from 'react-router-dom'; import { DeleteServerModal } from '../../src/servers/DeleteServerModal'; import { ServerWithId } from '../../src/servers/data'; import { renderWithEvents } from '../__helpers__/setUpTest'; -import { useToggle } from '../../src/utils/helpers/hooks'; +import { TestModalWrapper } from '../__helpers__/TestModalWrapper'; jest.mock('react-router-dom', () => ({ ...jest.requireActual('react-router-dom'), useNavigate: jest.fn() })); -const DeleteServerModalWrapper: FC<{ name: string; deleteServer: () => void }> = ({ name, deleteServer }) => { - const [isOpen, toggle] = useToggle(true); - - return ( - ({ name })} - toggle={toggle} - isOpen={isOpen} - deleteServer={deleteServer} - /> - ); -}; - describe('', () => { const deleteServerMock = jest.fn(); const navigate = jest.fn(); @@ -30,9 +16,14 @@ describe('', () => { (useNavigate as any).mockReturnValue(navigate); return renderWithEvents( - ( + ({ name: serverName })} + deleteServer={deleteServerMock} + /> + )} />, ); };