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