2022-05-16 20:42:00 +02:00
|
|
|
import { ReactNode } from 'react';
|
2022-07-09 23:03:21 +02:00
|
|
|
import { screen, waitFor } from '@testing-library/react';
|
2020-08-29 09:19:15 +02:00
|
|
|
import { Mock } from 'ts-mockery';
|
2022-05-28 10:47:39 +02:00
|
|
|
import { DeleteServerButton as createDeleteServerButton } from '../../src/servers/DeleteServerButton';
|
2020-08-29 09:19:15 +02:00
|
|
|
import { ServerWithId } from '../../src/servers/data';
|
2022-07-10 19:44:49 +02:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2018-08-24 12:23:35 +02:00
|
|
|
|
|
|
|
describe('<DeleteServerButton />', () => {
|
2022-05-28 10:47:39 +02:00
|
|
|
const DeleteServerButton = createDeleteServerButton(
|
2022-05-16 20:42:00 +02:00
|
|
|
({ isOpen }) => <>DeleteServerModal {isOpen ? '[Open]' : '[Closed]'}</>,
|
|
|
|
);
|
2022-07-09 23:03:21 +02:00
|
|
|
const setUp = (children?: ReactNode) => renderWithEvents(
|
|
|
|
<DeleteServerButton server={Mock.all<ServerWithId>()} textClassName="button">{children}</DeleteServerButton>,
|
|
|
|
);
|
2018-08-24 12:23:35 +02:00
|
|
|
|
2022-05-16 20:42:00 +02:00
|
|
|
it.each([
|
|
|
|
['Foo bar'],
|
|
|
|
['baz'],
|
|
|
|
['something'],
|
|
|
|
[undefined],
|
|
|
|
])('renders expected content', (children) => {
|
|
|
|
const { container } = setUp(children);
|
|
|
|
expect(container.firstChild).toBeTruthy();
|
|
|
|
expect(container.firstChild).toMatchSnapshot();
|
2018-08-24 12:23:35 +02:00
|
|
|
});
|
|
|
|
|
2022-05-16 20:42:00 +02:00
|
|
|
it('displays modal when button is clicked', async () => {
|
|
|
|
const { user, container } = setUp();
|
|
|
|
|
|
|
|
expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Closed/);
|
|
|
|
expect(screen.getByText(/DeleteServerModal/)).not.toHaveTextContent(/Open/);
|
|
|
|
container.firstElementChild && await user.click(container.firstElementChild);
|
2018-08-24 12:23:35 +02:00
|
|
|
|
2022-05-16 20:42:00 +02:00
|
|
|
await waitFor(() => expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Open/));
|
2018-08-24 12:23:35 +02:00
|
|
|
});
|
|
|
|
});
|