shlink-web-client/test/servers/CreateServer.test.js

52 lines
1.5 KiB
JavaScript
Raw Normal View History

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';
import { ServerForm } from '../../src/servers/helpers/ServerForm';
2018-08-25 00:19:49 +03:00
describe('<CreateServer />', () => {
let wrapper;
2018-12-18 00:32:51 +03:00
const ImportServersBtn = () => '';
const createServerMock = jest.fn();
2018-08-25 00:19:49 +03:00
const historyMock = {
push: jest.fn(),
2018-08-25 00:19:49 +03:00
};
const createWrapper = (serversImported = false) => {
const CreateServer = createServerConstruct(ImportServersBtn, () => [ serversImported, () => '' ]);
2018-12-18 00:32:51 +03:00
2018-08-25 00:19:49 +03:00
wrapper = shallow(
<CreateServer createServer={createServerMock} resetSelectedServer={identity} history={historyMock} />
2018-08-25 00:19:49 +03:00
);
return wrapper;
};
afterEach(() => {
jest.resetAllMocks();
wrapper && wrapper.unmount();
2018-08-25 00:19:49 +03:00
});
it('renders components', () => {
const wrapper = createWrapper();
expect(wrapper.find(ServerForm)).toHaveLength(1);
2018-08-25 00:19:49 +03:00
expect(wrapper.find('.create-server__import-success-msg')).toHaveLength(0);
});
it('shows success message when imported is true', () => {
const wrapper = createWrapper(true);
2018-08-25 00:19:49 +03:00
expect(wrapper.find('.create-server__import-success-msg')).toHaveLength(1);
});
it('creates server and redirects to it when form is submitted', () => {
const wrapper = createWrapper();
const form = wrapper.find(ServerForm);
form.simulate('submit', {});
2018-08-25 00:19:49 +03:00
expect(createServerMock).toHaveBeenCalledTimes(1);
expect(historyMock.push).toHaveBeenCalledTimes(1);
2018-08-25 00:19:49 +03:00
});
});