Merge branch 'master' into 13797-refatoring-part2
[arvados-workbench2.git] / src / views-components / project-tree / project-tree.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import * as React from 'react';
6 import * as Enzyme from 'enzyme';
7 import { mount } from 'enzyme';
8 import * as Adapter from 'enzyme-adapter-react-16';
9 import ListItemIcon from '@material-ui/core/ListItemIcon';
10 import { Collapse } from '@material-ui/core';
11 import CircularProgress from '@material-ui/core/CircularProgress';
12
13 import { ProjectTree } from './project-tree';
14 import { TreeItem } from '../../components/tree/tree';
15 import { ProjectResource } from '../../models/project';
16 import { mockProjectResource } from '../../models/test-utils';
17
18 Enzyme.configure({ adapter: new Adapter() });
19
20 describe("ProjectTree component", () => {
21
22     it("should render ListItemIcon", () => {
23         const project: TreeItem<ProjectResource> = {
24             data: mockProjectResource(),
25             id: "3",
26             open: true,
27             active: true,
28             status: 1
29         };
30         const wrapper = mount(<ProjectTree
31             projects={[project]}
32             toggleOpen={jest.fn()}
33             toggleActive={jest.fn()}
34             onContextMenu={jest.fn()} />);
35
36         expect(wrapper.find(ListItemIcon)).toHaveLength(1);
37     });
38
39     it("should render 2 ListItemIcons", () => {
40         const project: Array<TreeItem<ProjectResource>> = [
41             {
42                 data: mockProjectResource(),
43                 id: "3",
44                 open: false,
45                 active: true,
46                 status: 1
47             },
48             {
49                 data: mockProjectResource(),
50                 id: "3",
51                 open: false,
52                 active: true,
53                 status: 1
54             }
55         ];
56         const wrapper = mount(<ProjectTree
57             projects={project}
58             toggleOpen={jest.fn()}
59             toggleActive={jest.fn()}
60             onContextMenu={jest.fn()} />);
61
62         expect(wrapper.find(ListItemIcon)).toHaveLength(2);
63     });
64
65     it("should render Collapse", () => {
66         const project: Array<TreeItem<ProjectResource>> = [
67             {
68                 data: mockProjectResource(),
69                 id: "3",
70                 open: true,
71                 active: true,
72                 status: 2,
73                 items: [
74                     {
75                         data: mockProjectResource(),
76                         id: "3",
77                         open: true,
78                         active: true,
79                         status: 1
80                     }
81                 ]
82             }
83         ];
84         const wrapper = mount(<ProjectTree
85             projects={project}
86             toggleOpen={jest.fn()}
87             toggleActive={jest.fn()}
88             onContextMenu={jest.fn()} />);
89
90         expect(wrapper.find(Collapse)).toHaveLength(1);
91     });
92
93     it("should render CircularProgress", () => {
94         const project: TreeItem<ProjectResource> = {
95             data: mockProjectResource(),
96             id: "3",
97             open: false,
98             active: true,
99             status: 1
100         };
101         const wrapper = mount(<ProjectTree
102             projects={[project]}
103             toggleOpen={jest.fn()}
104             toggleActive={jest.fn()}
105             onContextMenu={jest.fn()} />);
106
107         expect(wrapper.find(CircularProgress)).toHaveLength(1);
108     });
109 });