mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 17:40:23 +03:00
36 lines
1.5 KiB
TypeScript
36 lines
1.5 KiB
TypeScript
import { screen, waitFor } from '@testing-library/react';
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
|
import type { ReactNode } from 'react';
|
|
import { DeleteServerButtonFactory } from '../../src/servers/DeleteServerButton';
|
|
import type { DeleteServerModalProps } from '../../src/servers/DeleteServerModal';
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
|
|
|
describe('<DeleteServerButton />', () => {
|
|
const DeleteServerButton = DeleteServerButtonFactory(fromPartial({
|
|
DeleteServerModal: ({ isOpen }: DeleteServerModalProps) => <>DeleteServerModal {isOpen ? '[Open]' : '[Closed]'}</>,
|
|
}));
|
|
const setUp = (children?: ReactNode) => renderWithEvents(
|
|
<DeleteServerButton server={fromPartial({})} textClassName="button">{children}</DeleteServerButton>,
|
|
);
|
|
|
|
it.each([
|
|
['Foo bar'],
|
|
['baz'],
|
|
['something'],
|
|
[undefined],
|
|
])('renders expected content', (children) => {
|
|
const { container } = setUp(children);
|
|
expect(container.firstChild).toBeTruthy();
|
|
expect(container.firstChild).toMatchSnapshot();
|
|
});
|
|
|
|
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);
|
|
|
|
await waitFor(() => expect(screen.getByText(/DeleteServerModal/)).toHaveTextContent(/Open/));
|
|
});
|
|
});
|