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

37 lines
1.5 KiB
TypeScript
Raw Normal View History

import { screen, waitFor } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
2023-02-18 13:11:01 +03:00
import type { ReactNode } from 'react';
2023-09-05 10:08:42 +03:00
import { DeleteServerButtonFactory } from '../../src/servers/DeleteServerButton';
import type { DeleteServerModalProps } from '../../src/servers/DeleteServerModal';
2022-07-10 20:44:49 +03:00
import { renderWithEvents } from '../__helpers__/setUpTest';
2018-08-24 13:23:35 +03:00
describe('<DeleteServerButton />', () => {
2023-09-05 10:08:42 +03:00
const DeleteServerButton = DeleteServerButtonFactory(fromPartial({
DeleteServerModal: ({ isOpen }: DeleteServerModalProps) => <>DeleteServerModal {isOpen ? '[Open]' : '[Closed]'}</>,
}));
const setUp = (children?: ReactNode) => renderWithEvents(
<DeleteServerButton server={fromPartial({})} 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
});
});