shlink-web-client/test/app/App.test.tsx

67 lines
2.4 KiB
TypeScript
Raw Permalink Normal View History

import { act, render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';
import { MemoryRouter } from 'react-router-dom';
import { AppFactory } from '../../src/app/App';
2023-09-30 11:20:28 +03:00
import { checkAccessibility } from '../__helpers__/accessibility';
2018-08-26 20:48:21 +03:00
describe('<App />', () => {
const App = AppFactory(
fromPartial({
MainHeader: () => <>MainHeader</>,
Home: () => <>Home</>,
ShlinkWebComponentContainer: () => <>ShlinkWebComponentContainer</>,
CreateServer: () => <>CreateServer</>,
EditServer: () => <>EditServer</>,
Settings: () => <>SettingsComp</>,
ManageServers: () => <>ManageServers</>,
ShlinkVersionsContainer: () => <>ShlinkVersions</>,
}),
);
2023-12-31 21:59:56 +03:00
const setUp = async (activeRoute = '/') => act(() => render(
<MemoryRouter initialEntries={[{ pathname: activeRoute }]}>
<App
fetchServers={() => {}}
servers={{}}
settings={fromPartial({})}
appUpdated={false}
resetAppUpdate={() => {}}
/>
</MemoryRouter>,
2023-12-31 21:59:56 +03:00
));
2018-08-26 20:48:21 +03:00
2023-09-30 11:20:28 +03:00
it('passes a11y checks', () => checkAccessibility(setUp()));
2023-12-31 21:59:56 +03:00
it('renders children components', async () => {
await setUp();
expect(screen.getByText('MainHeader')).toBeInTheDocument();
expect(screen.getByText('ShlinkVersions')).toBeInTheDocument();
});
2021-06-06 19:54:55 +03:00
it.each([
['/settings/foo', 'SettingsComp'],
['/settings/bar', 'SettingsComp'],
['/manage-servers', 'ManageServers'],
['/server/create', 'CreateServer'],
['/server/abc123/edit', 'EditServer'],
['/server/def456/edit', 'EditServer'],
2023-08-04 09:56:06 +03:00
['/server/abc123/foo', 'ShlinkWebComponentContainer'],
['/server/def456/bar', 'ShlinkWebComponentContainer'],
['/other', 'Oops! We could not find requested route.'],
])('renders expected route', async (activeRoute, expectedComponent) => {
2023-12-31 21:59:56 +03:00
await setUp(activeRoute);
expect(screen.getByText(expectedComponent)).toBeInTheDocument();
2018-08-26 20:48:21 +03:00
});
it.each([
2022-03-26 14:17:42 +03:00
['/foo', 'shlink-wrapper'],
['/bar', 'shlink-wrapper'],
['/', 'shlink-wrapper d-flex align-items-center pt-3'],
2023-12-31 21:59:56 +03:00
])('renders expected classes on shlink-wrapper based on current pathname', async (pathname, expectedClasses) => {
const { container } = await setUp(pathname);
const shlinkWrapper = container.querySelector('.shlink-wrapper');
expect(shlinkWrapper).toHaveAttribute('class', expectedClasses);
});
2018-08-26 20:48:21 +03:00
});