2022-07-09 23:03:21 +02:00
|
|
|
import { screen, waitFor } from '@testing-library/react';
|
2023-04-13 21:48:29 +02:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2023-02-18 11:11:01 +01:00
|
|
|
import type { ReactNode } from 'react';
|
2023-09-05 09:08:42 +02:00
|
|
|
import { DeleteServerButtonFactory } from '../../src/servers/DeleteServerButton';
|
|
|
|
import type { DeleteServerModalProps } from '../../src/servers/DeleteServerModal';
|
2023-09-30 10:45:52 +02:00
|
|
|
import { checkAccessibility } from '../__helpers__/accessibility';
|
2022-07-10 19:44:49 +02:00
|
|
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
2018-08-24 12:23:35 +02:00
|
|
|
|
|
|
|
describe('<DeleteServerButton />', () => {
|
2023-09-05 09:08:42 +02:00
|
|
|
const DeleteServerButton = DeleteServerButtonFactory(fromPartial({
|
|
|
|
DeleteServerModal: ({ isOpen }: DeleteServerModalProps) => <>DeleteServerModal {isOpen ? '[Open]' : '[Closed]'}</>,
|
|
|
|
}));
|
2022-07-09 23:03:21 +02:00
|
|
|
const setUp = (children?: ReactNode) => renderWithEvents(
|
2023-04-13 21:48:29 +02:00
|
|
|
<DeleteServerButton server={fromPartial({})} textClassName="button">{children}</DeleteServerButton>,
|
2022-07-09 23:03:21 +02:00
|
|
|
);
|
2018-08-24 12:23:35 +02:00
|
|
|
|
2023-09-30 10:45:52 +02:00
|
|
|
it('passes a11y checks', () => checkAccessibility(setUp('Delete me')));
|
|
|
|
|
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/);
|
2024-08-07 12:23:03 +02:00
|
|
|
if (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
|
|
|
});
|
|
|
|
});
|