2020-08-29 14:51:53 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2020-03-15 13:59:07 +03:00
|
|
|
import { ServerForm } from '../../../src/servers/helpers/ServerForm';
|
2022-03-07 18:27:25 +03:00
|
|
|
import { InputFormGroup } from '../../../src/utils/forms/InputFormGroup';
|
2020-03-15 13:59:07 +03:00
|
|
|
|
|
|
|
describe('<ServerForm />', () => {
|
2020-08-29 14:51:53 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
2020-03-15 13:59:07 +03:00
|
|
|
const onSubmit = jest.fn();
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
wrapper = shallow(<ServerForm onSubmit={onSubmit}><span>Something</span></ServerForm>);
|
|
|
|
});
|
|
|
|
|
2020-08-29 14:51:53 +03:00
|
|
|
afterEach(() => wrapper?.unmount());
|
|
|
|
afterEach(jest.resetAllMocks);
|
2020-03-15 13:59:07 +03:00
|
|
|
|
|
|
|
it('renders components', () => {
|
2022-03-07 18:27:25 +03:00
|
|
|
expect(wrapper.find(InputFormGroup)).toHaveLength(3);
|
2020-03-15 13:59:07 +03:00
|
|
|
expect(wrapper.find('span')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('invokes submit callback when submit event is triggered', () => {
|
|
|
|
const form = wrapper.find('form');
|
|
|
|
const preventDefault = jest.fn();
|
|
|
|
|
|
|
|
form.simulate('submit', { preventDefault });
|
|
|
|
|
|
|
|
expect(preventDefault).toHaveBeenCalled();
|
|
|
|
expect(onSubmit).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|