2018-08-25 00:19:49 +03:00
|
|
|
import React from 'react';
|
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { identity } from 'ramda';
|
2018-12-18 00:32:51 +03:00
|
|
|
import createServerConstruct from '../../src/servers/CreateServer';
|
2018-08-25 00:19:49 +03:00
|
|
|
|
|
|
|
describe('<CreateServer />', () => {
|
|
|
|
let wrapper;
|
2018-12-18 00:32:51 +03:00
|
|
|
const ImportServersBtn = () => '';
|
2019-04-19 11:29:49 +03:00
|
|
|
const createServerMock = jest.fn();
|
2018-08-25 00:19:49 +03:00
|
|
|
const historyMock = {
|
2019-04-19 11:29:49 +03:00
|
|
|
push: jest.fn(),
|
2018-08-25 00:19:49 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2019-04-19 11:29:49 +03:00
|
|
|
createServerMock.mockReset();
|
2018-08-25 00:19:49 +03:00
|
|
|
|
2018-12-18 00:32:51 +03:00
|
|
|
const CreateServer = createServerConstruct(ImportServersBtn);
|
|
|
|
|
2018-08-25 00:19:49 +03:00
|
|
|
wrapper = shallow(
|
2018-12-17 22:24:31 +03:00
|
|
|
<CreateServer createServer={createServerMock} resetSelectedServer={identity} history={historyMock} />
|
2018-08-25 00:19:49 +03:00
|
|
|
);
|
|
|
|
});
|
|
|
|
afterEach(() => wrapper.unmount());
|
|
|
|
|
|
|
|
it('renders components', () => {
|
|
|
|
expect(wrapper.find('#name')).toHaveLength(1);
|
|
|
|
expect(wrapper.find('#url')).toHaveLength(1);
|
|
|
|
expect(wrapper.find('#apiKey')).toHaveLength(1);
|
|
|
|
expect(wrapper.find(ImportServersBtn)).toHaveLength(1);
|
|
|
|
expect(wrapper.find('.create-server__import-success-msg')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('shows success message when imported is true', () => {
|
|
|
|
wrapper.setState({ serversImported: true });
|
|
|
|
expect(wrapper.find('.create-server__import-success-msg')).toHaveLength(1);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('creates server and redirects to it when form is submitted', () => {
|
|
|
|
const form = wrapper.find('form');
|
2018-08-26 00:39:27 +03:00
|
|
|
|
|
|
|
form.simulate('submit', { preventDefault() {
|
|
|
|
return '';
|
|
|
|
} });
|
2018-08-25 00:19:49 +03:00
|
|
|
|
2019-04-19 11:29:49 +03:00
|
|
|
expect(createServerMock).toHaveBeenCalledTimes(1);
|
|
|
|
expect(historyMock.push).toHaveBeenCalledTimes(1);
|
2018-08-25 00:19:49 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('updates state when inputs are changed', () => {
|
|
|
|
const nameInput = wrapper.find('#name');
|
|
|
|
const urlInput = wrapper.find('#url');
|
|
|
|
const apiKeyInput = wrapper.find('#apiKey');
|
|
|
|
|
|
|
|
nameInput.simulate('change', { target: { value: 'the_name' } });
|
|
|
|
urlInput.simulate('change', { target: { value: 'the_url' } });
|
|
|
|
apiKeyInput.simulate('change', { target: { value: 'the_api_key' } });
|
|
|
|
|
|
|
|
expect(wrapper.state('name')).toEqual('the_name');
|
|
|
|
expect(wrapper.state('url')).toEqual('the_url');
|
|
|
|
expect(wrapper.state('apiKey')).toEqual('the_api_key');
|
|
|
|
});
|
|
|
|
});
|