shlink-web-client/test/common/Home.test.js

47 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-08-12 09:45:48 +03:00
import { shallow } from 'enzyme';
import React from 'react';
import Home from '../../src/common/Home';
2018-08-12 09:20:35 +03:00
describe('<Home />', () => {
let wrapped;
const defaultProps = {
resetSelectedServer: jest.fn(),
2019-04-28 13:40:50 +03:00
servers: { loading: false, list: {} },
2018-08-12 09:20:35 +03:00
};
const createComponent = (props) => {
2018-08-12 09:20:35 +03:00
const actualProps = { ...defaultProps, ...props };
wrapped = shallow(<Home {...actualProps} />);
2018-08-12 09:20:35 +03:00
return wrapped;
};
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);
});
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...');
2018-08-12 09:20:35 +03:00
});
it('Asks to select a server when not loadign and servers exist', () => {
const list = [
{ name: 'foo', id: '1' },
{ name: 'bar', id: '2' },
];
const wrapped = createComponent({ servers: { list } });
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
});