2018-08-12 09:45:48 +03:00
|
|
|
import { shallow } from 'enzyme';
|
|
|
|
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 = {
|
2020-03-08 13:16:57 +03:00
|
|
|
resetSelectedServer: jest.fn(),
|
2020-04-27 11:49:55 +03:00
|
|
|
servers: {},
|
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;
|
|
|
|
};
|
|
|
|
|
2020-03-08 13:16:57 +03:00
|
|
|
afterEach(() => wrapped && wrapped.unmount());
|
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);
|
|
|
|
});
|
|
|
|
|
2020-04-27 11:49:55 +03:00
|
|
|
it('asks to select a server when servers exist', () => {
|
|
|
|
const servers = {
|
|
|
|
1: { name: 'foo', id: '1' },
|
|
|
|
2: { name: 'bar', id: '2' },
|
|
|
|
};
|
|
|
|
const wrapped = createComponent({ servers });
|
2020-03-08 13:35:06 +03:00
|
|
|
const span = wrapped.find('span');
|
|
|
|
|
|
|
|
expect(span).toHaveLength(1);
|
|
|
|
expect(span.text()).toContain('Please, select a server.');
|
|
|
|
});
|
2018-08-12 09:20:35 +03:00
|
|
|
});
|