2020-08-29 10:19:15 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
|
|
|
import { Mock } from 'ts-mockery';
|
|
|
|
import Home, { HomeProps } from '../../src/common/Home';
|
|
|
|
import { ServerWithId } from '../../src/servers/data';
|
2020-12-20 14:17:12 +03:00
|
|
|
import { ShlinkLogo } from '../../src/common/img/ShlinkLogo';
|
2018-08-12 09:20:35 +03:00
|
|
|
|
|
|
|
describe('<Home />', () => {
|
2020-08-29 10:19:15 +03:00
|
|
|
let wrapped: ShallowWrapper;
|
2018-08-12 09:20:35 +03:00
|
|
|
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
|
|
|
};
|
2020-08-29 10:19:15 +03:00
|
|
|
const createComponent = (props: Partial<HomeProps> = {}) => {
|
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-08-29 10:19:15 +03:00
|
|
|
afterEach(() => wrapped?.unmount());
|
2018-08-12 09:20:35 +03:00
|
|
|
|
2020-12-20 14:17:12 +03:00
|
|
|
it('renders logo and title', () => {
|
2018-08-12 09:20:35 +03:00
|
|
|
const wrapped = createComponent();
|
|
|
|
|
2020-12-20 14:17:12 +03:00
|
|
|
expect(wrapped.find(ShlinkLogo)).toHaveLength(1);
|
|
|
|
expect(wrapped.find('.home__title')).toHaveLength(1);
|
2018-08-12 09:20:35 +03:00
|
|
|
});
|
|
|
|
|
2020-12-20 14:17:12 +03:00
|
|
|
it.each([
|
|
|
|
[
|
|
|
|
{
|
|
|
|
'1a': Mock.of<ServerWithId>({ name: 'foo', id: '1' }),
|
|
|
|
'2b': Mock.of<ServerWithId>({ name: 'bar', id: '2' }),
|
|
|
|
},
|
|
|
|
0,
|
|
|
|
],
|
2021-07-12 13:05:33 +03:00
|
|
|
[{}, 3 ],
|
2020-12-20 14:17:12 +03:00
|
|
|
])('shows link to create or set-up server only when no servers exist', (servers, expectedParagraphs) => {
|
2020-04-27 11:49:55 +03:00
|
|
|
const wrapped = createComponent({ servers });
|
2020-12-20 14:17:12 +03:00
|
|
|
const p = wrapped.find('p');
|
2020-03-08 13:35:06 +03:00
|
|
|
|
2020-12-20 14:17:12 +03:00
|
|
|
expect(p).toHaveLength(expectedParagraphs);
|
2020-03-08 13:35:06 +03:00
|
|
|
});
|
2018-08-12 09:20:35 +03:00
|
|
|
});
|