2018-08-12 09:45:48 +03:00
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
import { values } from 'ramda';
|
|
|
|
import React from 'react';
|
2018-12-17 22:24:31 +03:00
|
|
|
import Home from '../../src/common/Home';
|
2018-08-12 09:20:35 +03:00
|
|
|
|
|
|
|
describe('<Home />', () => {
|
|
|
|
let wrapped;
|
|
|
|
const defaultProps = {
|
2019-04-28 13:40:50 +03:00
|
|
|
resetSelectedServer: () => '',
|
|
|
|
servers: { loading: false, list: {} },
|
2018-08-12 09:20:35 +03:00
|
|
|
};
|
2018-08-26 00:39:27 +03:00
|
|
|
const createComponent = (props) => {
|
2018-08-12 09:20:35 +03:00
|
|
|
const actualProps = { ...defaultProps, ...props };
|
2018-08-26 00:39:27 +03:00
|
|
|
|
2018-12-17 22:24:31 +03:00
|
|
|
wrapped = shallow(<Home {...actualProps} />);
|
2018-08-26 00:39:27 +03:00
|
|
|
|
2018-08-12 09:20:35 +03:00
|
|
|
return wrapped;
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
if (wrapped !== undefined) {
|
|
|
|
wrapped.unmount();
|
|
|
|
wrapped = undefined;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
it('resets selected server when mounted', () => {
|
2019-04-19 11:29:49 +03:00
|
|
|
const resetSelectedServer = jest.fn();
|
2018-08-12 09:20:35 +03:00
|
|
|
|
2019-04-19 11:29:49 +03:00
|
|
|
expect(resetSelectedServer).not.toHaveBeenCalled();
|
2018-08-12 09:20:35 +03:00
|
|
|
createComponent({ resetSelectedServer });
|
2019-04-19 11:29:49 +03:00
|
|
|
expect(resetSelectedServer).toHaveBeenCalled();
|
2018-08-12 09:20:35 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
it('shows link to create server when no servers exist', () => {
|
|
|
|
const wrapped = createComponent();
|
|
|
|
|
|
|
|
expect(wrapped.find('Link')).toHaveLength(1);
|
|
|
|
expect(wrapped.find('ListGroup')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2019-04-28 13:40:50 +03:00
|
|
|
it('shows message when loading servers', () => {
|
|
|
|
const wrapped = createComponent({ servers: { loading: true } });
|
|
|
|
const span = wrapped.find('span');
|
|
|
|
|
|
|
|
expect(span).toHaveLength(1);
|
|
|
|
expect(span.text()).toContain('Trying to load servers...');
|
|
|
|
expect(wrapped.find('ListGroup')).toHaveLength(0);
|
|
|
|
});
|
|
|
|
|
2018-08-12 09:20:35 +03:00
|
|
|
it('shows servers list when list of servers is not empty', () => {
|
|
|
|
const servers = {
|
2019-04-28 13:40:50 +03:00
|
|
|
loading: false,
|
|
|
|
list: {
|
|
|
|
1: { name: 'foo', id: '123' },
|
|
|
|
2: { name: 'bar', id: '456' },
|
|
|
|
},
|
2018-08-26 00:39:27 +03:00
|
|
|
};
|
2018-08-12 09:20:35 +03:00
|
|
|
const wrapped = createComponent({ servers });
|
|
|
|
|
|
|
|
expect(wrapped.find('Link')).toHaveLength(0);
|
|
|
|
expect(wrapped.find('ListGroup')).toHaveLength(1);
|
|
|
|
expect(wrapped.find('ListGroupItem')).toHaveLength(values(servers).length);
|
|
|
|
});
|
|
|
|
});
|