shlink-web-client/test/servers/DeleteServerButton.test.tsx

40 lines
1.4 KiB
TypeScript
Raw Normal View History

import { ReactNode } from 'react';
import userEvent from '@testing-library/user-event';
import { render, screen, waitFor } from '@testing-library/react';
import { Mock } from 'ts-mockery';
2018-12-18 00:32:51 +03:00
import deleteServerButtonConstruct from '../../src/servers/DeleteServerButton';
import { ServerWithId } from '../../src/servers/data';
2018-08-24 13:23:35 +03:00
describe('<DeleteServerButton />', () => {
const DeleteServerButton = deleteServerButtonConstruct(
({ isOpen }) => <>DeleteServerModal {isOpen ? '[Open]' : '[Closed]'}</>,
);
const setUp = (children?: ReactNode) => ({
user: userEvent.setup(),
...render(
<DeleteServerButton server={Mock.all<ServerWithId>()} textClassName="button">{children}</DeleteServerButton>,
),
});
2018-08-24 13:23:35 +03: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 13:23:35 +03: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 13:23:35 +03:00
await waitFor(() => expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Open/));
2018-08-24 13:23:35 +03:00
});
});