import React from 'react';
import { mount } from 'enzyme';
import { EditServer as editServerConstruct } from '../../src/servers/EditServer';
import { ServerForm } from '../../src/servers/helpers/ServerForm';
describe('', () => {
let wrapper;
const ServerError = jest.fn();
const editServerMock = jest.fn();
const historyMock = { push: jest.fn() };
const match = {
params: { serverId: 'abc123' },
};
const selectedServer = {
id: 'abc123',
name: 'name',
url: 'url',
apiKey: 'apiKey',
};
beforeEach(() => {
const EditServer = editServerConstruct(ServerError);
wrapper = mount(
);
});
afterEach(() => {
jest.resetAllMocks();
wrapper && wrapper.unmount();
});
it('renders components', () => {
expect(wrapper.find(ServerForm)).toHaveLength(1);
});
it('edits server and redirects to it when form is submitted', () => {
const form = wrapper.find(ServerForm);
form.simulate('submit', {});
expect(editServerMock).toHaveBeenCalledTimes(1);
expect(historyMock.push).toHaveBeenCalledTimes(1);
});
});