changing location of context-menu
[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 { Project } from '../../models/project';
16 import { ResourceKind } from "../../models/resource";
17
18 Enzyme.configure({ adapter: new Adapter() });
19
20 describe("ProjectTree component", () => {
21
22     it("should render ListItemIcon", () => {
23         const project: TreeItem<Project> = {
24             data: {
25                 name: "sample name",
26                 createdAt: "2018-06-12",
27                 modifiedAt: "2018-06-13",
28                 uuid: "uuid",
29                 ownerUuid: "ownerUuid",
30                 href: "href",
31                 kind: ResourceKind.PROJECT
32             },
33             id: "3",
34             open: true,
35             active: true,
36             status: 1
37         };
38         const wrapper = mount(<ProjectTree projects={[project]} toggleOpen={jest.fn()} toggleActive={jest.fn()} />);
39
40         expect(wrapper.find(ListItemIcon)).toHaveLength(1);
41     });
42
43     it("should render 2 ListItemIcons", () => {
44         const project: Array<TreeItem<Project>> = [
45             {
46                 data: {
47                     name: "sample name",
48                     createdAt: "2018-06-12",
49                     modifiedAt: "2018-06-13",
50                     uuid: "uuid",
51                     ownerUuid: "ownerUuid",
52                     href: "href",
53                     kind: ResourceKind.PROJECT
54                 },
55                 id: "3",
56                 open: false,
57                 active: true,
58                 status: 1
59             },
60             {
61                 data: {
62                     name: "sample name",
63                     createdAt: "2018-06-12",
64                     modifiedAt: "2018-06-13",
65                     uuid: "uuid",
66                     ownerUuid: "ownerUuid",
67                     href: "href",
68                     kind: ResourceKind.PROJECT
69                 },
70                 id: "3",
71                 open: false,
72                 active: true,
73                 status: 1
74             }
75         ];
76         const wrapper = mount(<ProjectTree projects={project} toggleOpen={jest.fn()} toggleActive={jest.fn()} />);
77
78         expect(wrapper.find(ListItemIcon)).toHaveLength(2);
79     });
80
81     it("should render Collapse", () => {
82         const project: Array<TreeItem<Project>> = [
83             {
84                 data: {
85                     name: "sample name",
86                     createdAt: "2018-06-12",
87                     modifiedAt: "2018-06-13",
88                     uuid: "uuid",
89                     ownerUuid: "ownerUuid",
90                     href: "href",
91                     kind: ResourceKind.PROJECT
92                 },
93                 id: "3",
94                 open: true,
95                 active: true,
96                 status: 2,
97                 items: [
98                     {
99                         data: {
100                             name: "sample name",
101                             createdAt: "2018-06-12",
102                             modifiedAt: "2018-06-13",
103                             uuid: "uuid",
104                             ownerUuid: "ownerUuid",
105                             href: "href",
106                             kind: ResourceKind.PROJECT
107                         },
108                         id: "3",
109                         open: true,
110                         active: true,
111                         status: 1
112                     }
113                 ]
114             }
115         ];
116         const wrapper = mount(<ProjectTree projects={project} toggleOpen={jest.fn()} toggleActive={jest.fn()}/>);
117
118         expect(wrapper.find(Collapse)).toHaveLength(1);
119     });
120
121     it("should render CircularProgress", () => {
122         const project: TreeItem<Project> = {
123             data: {
124                 name: "sample name",
125                 createdAt: "2018-06-12",
126                 modifiedAt: "2018-06-13",
127                 uuid: "uuid",
128                 ownerUuid: "ownerUuid",
129                 href: "href",
130                 kind: ResourceKind.PROJECT
131             },
132             id: "3",
133             open: false,
134             active: true,
135             status: 1
136         };
137         const wrapper = mount(<ProjectTree projects={[project]} toggleOpen={jest.fn()} toggleActive={jest.fn()} />);
138
139         expect(wrapper.find(CircularProgress)).toHaveLength(1);
140     });
141 });