2020-08-22 10:15:05 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
2018-08-26 20:48:21 +03:00
|
|
|
import { Route } from 'react-router-dom';
|
2021-02-16 21:25:23 +03:00
|
|
|
import { Mock } from 'ts-mockery';
|
2021-06-06 19:54:55 +03:00
|
|
|
import { Alert } from 'reactstrap';
|
2021-02-16 21:25:23 +03:00
|
|
|
import { Settings } from '../src/settings/reducers/settings';
|
2018-12-17 22:24:31 +03:00
|
|
|
import appFactory from '../src/App';
|
2018-08-26 20:48:21 +03:00
|
|
|
|
|
|
|
describe('<App />', () => {
|
2020-08-22 10:15:05 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
const MainHeader = () => null;
|
2021-06-06 19:54:55 +03:00
|
|
|
const ShlinkVersions = () => null;
|
2018-08-26 20:48:21 +03:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2021-06-06 19:54:55 +03:00
|
|
|
const App = appFactory(MainHeader, () => null, () => null, () => null, () => null, () => null, ShlinkVersions);
|
2018-12-17 22:24:31 +03:00
|
|
|
|
2021-06-06 19:54:55 +03:00
|
|
|
wrapper = shallow(
|
|
|
|
<App
|
|
|
|
fetchServers={() => {}}
|
|
|
|
servers={{}}
|
|
|
|
settings={Mock.all<Settings>()}
|
|
|
|
appUpdated={false}
|
|
|
|
resetAppUpdate={() => {}}
|
|
|
|
/>,
|
|
|
|
);
|
2018-08-26 20:48:21 +03:00
|
|
|
});
|
|
|
|
afterEach(() => wrapper.unmount());
|
|
|
|
|
|
|
|
it('renders a header', () => expect(wrapper.find(MainHeader)).toHaveLength(1));
|
|
|
|
|
2021-06-06 19:54:55 +03:00
|
|
|
it('renders versions', () => expect(wrapper.find(ShlinkVersions)).toHaveLength(1));
|
|
|
|
|
|
|
|
it('renders an Alert', () => expect(wrapper.find(Alert)).toHaveLength(1));
|
|
|
|
|
2018-08-26 20:48:21 +03:00
|
|
|
it('renders app main routes', () => {
|
|
|
|
const routes = wrapper.find(Route);
|
2019-03-03 13:02:29 +03:00
|
|
|
const expectedPaths = [
|
|
|
|
'/',
|
2020-04-25 10:49:54 +03:00
|
|
|
'/settings',
|
2020-03-15 11:56:16 +03:00
|
|
|
'/server/create',
|
|
|
|
'/server/:serverId/edit',
|
2019-03-03 13:02:29 +03:00
|
|
|
'/server/:serverId',
|
|
|
|
];
|
2018-08-26 20:48:21 +03:00
|
|
|
|
2019-03-03 13:02:29 +03:00
|
|
|
expect.assertions(expectedPaths.length + 1);
|
2020-03-15 11:56:16 +03:00
|
|
|
expect(routes).toHaveLength(expectedPaths.length + 1);
|
2019-03-03 13:02:29 +03:00
|
|
|
expectedPaths.forEach((path, index) => {
|
|
|
|
expect(routes.at(index).prop('path')).toEqual(path);
|
|
|
|
});
|
2018-08-26 20:48:21 +03:00
|
|
|
});
|
|
|
|
});
|