2022-05-03 21:15:22 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2020-08-29 10:19:15 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2022-05-03 21:15:22 +03:00
|
|
|
import { MemoryRouter } from 'react-router-dom';
|
|
|
|
import { Home } from '../../src/common/Home';
|
|
|
|
import { ServersMap, ServerWithId } from '../../src/servers/data';
|
2022-02-08 00:17:57 +03:00
|
|
|
|
2018-08-12 09:20:35 +03:00
|
|
|
describe('<Home />', () => {
|
2022-05-03 21:15:22 +03:00
|
|
|
const setUp = (servers: ServersMap = {}) => render(
|
|
|
|
<MemoryRouter>
|
|
|
|
<Home servers={servers} />
|
|
|
|
</MemoryRouter>,
|
|
|
|
);
|
|
|
|
|
|
|
|
it('renders title', () => {
|
|
|
|
setUp();
|
|
|
|
expect(screen.getByRole('heading', { name: 'Welcome!' })).toBeInTheDocument();
|
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' }),
|
2022-05-03 21:15:22 +03:00
|
|
|
'3c': Mock.of<ServerWithId>({ name: 'baz', id: '3' }),
|
2020-12-20 14:17:12 +03:00
|
|
|
},
|
2022-05-03 21:15:22 +03:00
|
|
|
3,
|
2020-12-20 14:17:12 +03:00
|
|
|
],
|
2022-05-03 21:15:22 +03:00
|
|
|
[{}, 2],
|
|
|
|
])('shows link to create or set-up server only when no servers exist', (servers, expectedServers) => {
|
|
|
|
setUp(servers);
|
|
|
|
const links = screen.getAllByRole('link');
|
|
|
|
|
|
|
|
expect(links).toHaveLength(expectedServers);
|
2020-03-08 13:35:06 +03:00
|
|
|
|
2022-05-03 21:15:22 +03:00
|
|
|
if (Object.keys(servers).length === 0) {
|
|
|
|
expect(screen.getByText('This application will help you manage your Shlink servers.')).toBeInTheDocument();
|
|
|
|
expect(screen.getByText('Learn more about Shlink')).toBeInTheDocument();
|
|
|
|
}
|
2020-03-08 13:35:06 +03:00
|
|
|
});
|
2018-08-12 09:20:35 +03:00
|
|
|
});
|