tree test
[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 * as ReactDOM from 'react-dom';
7 import { shallow, mount, render } from 'enzyme';
8 import * as Enzyme from 'enzyme';
9 import * as Adapter from 'enzyme-adapter-react-16';
10 import ListItemIcon from '@material-ui/core/ListItemIcon';
11 import { Collapse } from '@material-ui/core';
12
13 import ProjectTree from './project-tree';
14 import { TreeItem } from '../tree/tree';
15 import { Project } from '../../models/project';
16 Enzyme.configure({ adapter: new Adapter() });
17
18 describe("ProjectTree component", () => {
19
20     it("checks is there ListItemIcon in the ProjectTree component", () => {
21         const project: TreeItem<Project> = {
22             data: {
23                 name: "sample name",
24                 createdAt: "2018-06-12",
25                 icon: <i className="fas fa-th" />
26             },
27             id: "3",
28             open: true,
29             active: true
30         }
31         const wrapper = mount(<ProjectTree projects={[project]} toggleProjectTreeItem={() => { }} />);
32
33         expect(wrapper.find(ListItemIcon).length).toEqual(1);
34     });
35
36     it("checks are there two ListItemIcon's in the ProjectTree component", () => {
37         const project: Array<TreeItem<Project>> = [
38             {
39                 data: {
40                     name: "sample name",
41                     createdAt: "2018-06-12",
42                     icon: <i className="fas fa-th" />
43                 },
44                 id: "3",
45                 open: false,
46                 active: true
47             },
48             {
49                 data: {
50                     name: "sample name",
51                     createdAt: "2018-06-12",
52                     icon: <i className="fas fa-th" />
53                 },
54                 id: "3",
55                 open: false,
56                 active: true
57             }
58         ]
59         const wrapper = mount(<ProjectTree projects={project} toggleProjectTreeItem={() => { }} />);
60
61         expect(wrapper.find(ListItemIcon).length).toEqual(2);
62     });
63
64     it("check ProjectTree, when open is changed", () => {
65         const project: TreeItem<Project> = {
66             data: {
67                 name: "sample name",
68                 createdAt: "2018-06-12",
69                 icon: <i className="fas fa-th" />
70             },
71             id: "3",
72             open: true,
73             active: true,
74             items: [
75                 {
76                     data: {
77                         name: "sample name",
78                         createdAt: "2018-06-12",
79                         icon: <i className="fas fa-th" />
80                     },
81                     id: "4",
82                     open: false,
83                     active: true
84                 }
85             ]
86         }
87         const wrapper = mount(<ProjectTree projects={[project]} toggleProjectTreeItem={() => { }} />);
88         wrapper.setState({open: true });
89
90         expect(wrapper.find(Collapse).length).toEqual(1);
91     });
92 });