2022-06-04 20:02:20 +03:00
|
|
|
import { fireEvent, render, screen } from '@testing-library/react';
|
2020-03-15 13:59:07 +03:00
|
|
|
import { ServerForm } from '../../../src/servers/helpers/ServerForm';
|
|
|
|
|
|
|
|
describe('<ServerForm />', () => {
|
|
|
|
const onSubmit = jest.fn();
|
2022-06-04 20:02:20 +03:00
|
|
|
const setUp = () => render(<ServerForm onSubmit={onSubmit}>Something</ServerForm>);
|
2020-03-15 13:59:07 +03:00
|
|
|
|
2020-08-29 14:51:53 +03:00
|
|
|
afterEach(jest.resetAllMocks);
|
2020-03-15 13:59:07 +03:00
|
|
|
|
|
|
|
it('renders components', () => {
|
2022-06-04 20:02:20 +03:00
|
|
|
setUp();
|
2020-03-15 13:59:07 +03:00
|
|
|
|
2022-06-04 20:02:20 +03:00
|
|
|
expect(screen.getAllByRole('textbox')).toHaveLength(3);
|
|
|
|
expect(screen.getByText('Something')).toBeInTheDocument();
|
|
|
|
});
|
2020-03-15 13:59:07 +03:00
|
|
|
|
2022-06-04 20:02:20 +03:00
|
|
|
it('invokes submit callback when submit event is triggered', async () => {
|
|
|
|
setUp();
|
2020-03-15 13:59:07 +03:00
|
|
|
|
2022-06-04 20:02:20 +03:00
|
|
|
expect(onSubmit).not.toHaveBeenCalled();
|
|
|
|
fireEvent.submit(screen.getByRole('form'), { preventDefault: jest.fn() });
|
2020-03-15 13:59:07 +03:00
|
|
|
expect(onSubmit).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|