shlink-web-client/test/servers/helpers/ServerForm.test.tsx

26 lines
866 B
TypeScript
Raw Normal View History

import { fireEvent, render, screen } from '@testing-library/react';
import { ServerForm } from '../../../src/servers/helpers/ServerForm';
2023-09-30 11:45:52 +03:00
import { checkAccessibility } from '../../__helpers__/accessibility';
describe('<ServerForm />', () => {
2023-05-27 12:57:26 +03:00
const onSubmit = vi.fn();
const setUp = () => render(<ServerForm onSubmit={onSubmit}>Something</ServerForm>);
2023-09-30 11:45:52 +03:00
it('passes a11y checks', () => checkAccessibility(setUp()));
it('renders components', () => {
setUp();
expect(screen.getAllByRole('textbox')).toHaveLength(3);
expect(screen.getByText('Something')).toBeInTheDocument();
});
it('invokes submit callback when submit event is triggered', async () => {
setUp();
expect(onSubmit).not.toHaveBeenCalled();
2023-05-27 12:57:26 +03:00
fireEvent.submit(screen.getByRole('form'), { preventDefault: vi.fn() });
expect(onSubmit).toHaveBeenCalled();
});
});