17782: Fixes almost all tests (4 left) mostly by fixing namespace-type imports.
[arvados-workbench2.git] / src / views / not-found-panel / not-found-panel-root.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from 'react';
6 import { mount, configure } from 'enzyme';
7 import Adapter from "enzyme-adapter-react-16";
8 import { StyledComponentProps, MuiThemeProvider } from '@material-ui/core';
9 import { ClusterConfigJSON } from 'common/config';
10 import { CustomTheme } from 'common/custom-theme';
11 import { NotFoundPanelRoot, NotFoundPanelRootDataProps, CssRules } from './not-found-panel-root';
12
13 configure({ adapter: new Adapter() });
14
15 describe('NotFoundPanelRoot', () => {
16     let props: NotFoundPanelRootDataProps & StyledComponentProps<CssRules>;
17
18     beforeEach(() => {
19         props = {
20             classes: {
21                 root: 'root',
22                 title: 'title',
23                 active: 'active',
24             },
25             clusterConfig: {
26                 Mail: {
27                     SupportEmailAddress: 'support@example.com'
28                 }
29             } as ClusterConfigJSON,
30             location: null,
31         };
32     });
33
34     it('should render component', () => {
35         // given
36         const expectedMessage = "The page you requested was not found";
37
38         // when
39         const wrapper = mount(
40             <MuiThemeProvider theme={CustomTheme}>
41                 <NotFoundPanelRoot {...props} />
42             </MuiThemeProvider>
43             );
44
45         // then
46         expect(wrapper.find('p').text()).toContain(expectedMessage);
47     });
48
49     it('should render component without email url when no email', () => {
50         // setup
51         props.clusterConfig.Mail.SupportEmailAddress = '';
52
53         // when
54         const wrapper = mount(
55             <MuiThemeProvider theme={CustomTheme}>
56                 <NotFoundPanelRoot {...props} />
57             </MuiThemeProvider>
58             );
59
60         // then
61         expect(wrapper.find('a').length).toBe(0);
62     });
63
64     it('should render component with additional message and email url', () => {
65         // given
66         const hash = '123hash123';
67         const pathname = `/collections/${hash}`;
68
69         // setup
70         props.location = {
71             pathname,
72         } as any;
73
74         // when
75         const wrapper = mount(
76             <MuiThemeProvider theme={CustomTheme}>
77                 <NotFoundPanelRoot {...props} />
78             </MuiThemeProvider>
79             );
80
81         // then
82         expect(wrapper.find('p').first().text()).toContain(hash);
83
84         // and
85         expect(wrapper.find('a').length).toBe(1);
86     });
87 });