2022-05-03 18:36:34 +03:00
|
|
|
import { render, screen } from '@testing-library/react';
|
2023-04-13 22:48:29 +03:00
|
|
|
import { fromPartial } from '@total-typescript/shoehorn';
|
2022-05-03 18:36:34 +03:00
|
|
|
import { createMemoryHistory } from 'history';
|
2023-02-18 13:11:01 +03:00
|
|
|
import { Router } from 'react-router-dom';
|
2023-09-03 12:06:35 +03:00
|
|
|
import { AppFactory } from '../../src/app/App';
|
2022-02-08 00:17:57 +03:00
|
|
|
|
2018-08-26 20:48:21 +03:00
|
|
|
describe('<App />', () => {
|
2023-09-03 12:06:35 +03:00
|
|
|
const App = AppFactory(
|
|
|
|
fromPartial({
|
|
|
|
MainHeader: () => <>MainHeader</>,
|
|
|
|
Home: () => <>Home</>,
|
|
|
|
ShlinkWebComponentContainer: () => <>ShlinkWebComponentContainer</>,
|
|
|
|
CreateServer: () => <>CreateServer</>,
|
|
|
|
EditServer: () => <>EditServer</>,
|
|
|
|
Settings: () => <>SettingsComp</>,
|
|
|
|
ManageServers: () => <>ManageServers</>,
|
|
|
|
ShlinkVersionsContainer: () => <>ShlinkVersions</>,
|
|
|
|
}),
|
2021-11-14 01:04:59 +03:00
|
|
|
);
|
2022-05-03 18:36:34 +03:00
|
|
|
const setUp = (activeRoute = '/') => {
|
|
|
|
const history = createMemoryHistory();
|
|
|
|
history.push(activeRoute);
|
2018-08-26 20:48:21 +03:00
|
|
|
|
2022-05-03 18:36:34 +03:00
|
|
|
return render(
|
|
|
|
<Router location={history.location} navigator={history}>
|
|
|
|
<App
|
|
|
|
fetchServers={() => {}}
|
|
|
|
servers={{}}
|
2023-04-13 22:48:29 +03:00
|
|
|
settings={fromPartial({})}
|
2022-05-03 18:36:34 +03:00
|
|
|
appUpdated
|
|
|
|
resetAppUpdate={() => {}}
|
|
|
|
/>
|
|
|
|
</Router>,
|
|
|
|
);
|
2021-11-14 01:04:59 +03:00
|
|
|
};
|
2018-08-26 20:48:21 +03:00
|
|
|
|
2021-11-14 01:04:59 +03:00
|
|
|
it('renders children components', () => {
|
2022-05-03 18:36:34 +03:00
|
|
|
setUp();
|
2021-11-14 01:04:59 +03:00
|
|
|
|
2022-05-03 18:36:34 +03:00
|
|
|
expect(screen.getByText('MainHeader')).toBeInTheDocument();
|
|
|
|
expect(screen.getByText('ShlinkVersions')).toBeInTheDocument();
|
|
|
|
expect(screen.getByText('This app has just been updated!')).toBeInTheDocument();
|
2021-11-14 01:04:59 +03:00
|
|
|
});
|
2021-06-06 19:54:55 +03:00
|
|
|
|
2022-05-03 18:36:34 +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'],
|
2022-05-03 18:36:34 +03:00
|
|
|
['/other', 'Oops! We could not find requested route.'],
|
|
|
|
])('renders expected route', async (activeRoute, expectedComponent) => {
|
|
|
|
setUp(activeRoute);
|
|
|
|
expect(await screen.findByText(expectedComponent)).toBeInTheDocument();
|
2018-08-26 20:48:21 +03:00
|
|
|
});
|
2021-11-14 01:04:59 +03:00
|
|
|
|
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
['/foo', 'shlink-wrapper'],
|
|
|
|
['/bar', 'shlink-wrapper'],
|
|
|
|
['/', 'shlink-wrapper d-flex d-md-block align-items-center'],
|
2021-11-14 01:04:59 +03:00
|
|
|
])('renders expected classes on shlink-wrapper based on current pathname', (pathname, expectedClasses) => {
|
2022-05-03 18:36:34 +03:00
|
|
|
const { container } = setUp(pathname);
|
|
|
|
const shlinkWrapper = container.querySelector('.shlink-wrapper');
|
2021-11-14 01:04:59 +03:00
|
|
|
|
2022-05-03 18:36:34 +03:00
|
|
|
expect(shlinkWrapper).toHaveAttribute('class', expectedClasses);
|
2021-11-14 01:04:59 +03:00
|
|
|
});
|
2018-08-26 20:48:21 +03:00
|
|
|
});
|