2022-05-03 20:15:22 +02:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2023-04-13 21:48:29 +02:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2023-05-27 11:57:26 +02:00
|
|
|
import { MemoryRouter } from 'react-router';
|
2022-05-03 20:15:22 +02:00
|
|
|
import { Home } from '../../src/common/Home';
|
2023-02-18 10:40:37 +01:00
|
|
|
import type { ServersMap, ServerWithId } from '../../src/servers/data';
|
2023-09-30 10:20:28 +02:00
|
|
|
import { checkAccessibility } from '../__helpers__/accessibility';
|
2022-02-07 22:17:57 +01:00
|
|
|
|
2018-08-12 08:20:35 +02:00
|
|
|
describe('<Home />', () => {
|
2022-05-03 20:15:22 +02:00
|
|
|
const setUp = (servers: ServersMap = {}) => render(
|
|
|
|
<MemoryRouter>
|
|
|
|
<Home servers={servers} />
|
|
|
|
</MemoryRouter>,
|
|
|
|
);
|
|
|
|
|
2023-09-30 10:20:28 +02:00
|
|
|
it('passes a11y checks', () => checkAccessibility(
|
|
|
|
setUp({ '1a': fromPartial<ServerWithId>({ name: 'foo', id: '1' }) }),
|
|
|
|
));
|
|
|
|
|
2022-05-03 20:15:22 +02:00
|
|
|
it('renders title', () => {
|
|
|
|
setUp();
|
|
|
|
expect(screen.getByRole('heading', { name: 'Welcome!' })).toBeInTheDocument();
|
2018-08-12 08:20:35 +02:00
|
|
|
});
|
|
|
|
|
2020-12-20 12:17:12 +01:00
|
|
|
it.each([
|
|
|
|
[
|
|
|
|
{
|
2023-04-13 21:48:29 +02:00
|
|
|
'1a': fromPartial<ServerWithId>({ name: 'foo', id: '1' }),
|
|
|
|
'2b': fromPartial<ServerWithId>({ name: 'bar', id: '2' }),
|
|
|
|
'3c': fromPartial<ServerWithId>({ name: 'baz', id: '3' }),
|
2020-12-20 12:17:12 +01:00
|
|
|
},
|
2022-05-03 20:15:22 +02:00
|
|
|
3,
|
2020-12-20 12:17:12 +01:00
|
|
|
],
|
2022-05-03 20:15:22 +02: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 11:35:06 +01:00
|
|
|
|
2022-05-03 20:15:22 +02: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 11:35:06 +01:00
|
|
|
});
|
2018-08-12 08:20:35 +02:00
|
|
|
});
|