Format creadcrumbs test code
[arvados-workbench2.git] / src / 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
12 import ProjectTree from './project-tree';
13 import { TreeItem } from '../tree/tree';
14 import { Project } from '../../models/project';
15 Enzyme.configure({ adapter: new Adapter() });
16
17 describe("ProjectTree component", () => {
18
19     it("checks is there ListItemIcon in the ProjectTree component", () => {
20         const project: TreeItem<Project> = {
21             data: {
22                 name: "sample name",
23                 createdAt: "2018-06-12",
24                 modifiedAt: "2018-06-13",
25                 uuid: "uuid",
26                 ownerUuid: "ownerUuid",
27                 href: "href",
28             },
29             id: "3",
30             open: true,
31             active: true
32         };
33         const wrapper = mount(<ProjectTree projects={[project]} toggleProjectTreeItem={() => { }} />);
34
35         expect(wrapper.find(ListItemIcon).length).toEqual(1);
36     });
37
38     it("checks are there two ListItemIcon's in the ProjectTree component", () => {
39         const project: Array<TreeItem<Project>> = [
40             {
41                 data: {
42                     name: "sample name",
43                     createdAt: "2018-06-12",
44                     modifiedAt: "2018-06-13",
45                     uuid: "uuid",
46                     ownerUuid: "ownerUuid",
47                     href: "href",
48                 },
49                 id: "3",
50                 open: false,
51                 active: true
52             },
53             {
54                 data: {
55                     name: "sample name",
56                     createdAt: "2018-06-12",
57                     modifiedAt: "2018-06-13",
58                     uuid: "uuid",
59                     ownerUuid: "ownerUuid",
60                     href: "href",
61                 },
62                 id: "3",
63                 open: false,
64                 active: true
65             }
66         ];
67         const wrapper = mount(<ProjectTree projects={project} toggleProjectTreeItem={() => { }} />);
68
69         expect(wrapper.find(ListItemIcon).length).toEqual(2);
70     });
71
72     it("check ProjectTree, when open is changed", () => {
73         const project: TreeItem<Project> = {
74             data: {
75                 name: "sample name",
76                 createdAt: "2018-06-12",
77                 modifiedAt: "2018-06-13",
78                 uuid: "uuid",
79                 ownerUuid: "ownerUuid",
80                 href: "href",
81             },
82             id: "3",
83             open: true,
84             active: true,
85             items: [
86                 {
87                     data: {
88                         name: "sample name",
89                         createdAt: "2018-06-12",
90                         modifiedAt: "2018-06-13",
91                         uuid: "uuid",
92                         ownerUuid: "ownerUuid",
93                         href: "href",
94                     },
95                     id: "4",
96                     open: false,
97                     active: true
98                 }
99             ]
100         };
101         const wrapper = mount(<ProjectTree projects={[project]} toggleProjectTreeItem={() => { }} />);
102         wrapper.setState({open: true });
103
104         expect(wrapper.find(Collapse).length).toEqual(1);
105     });
106 });