X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/750a9abc14ba1e17784a386399237ebf35fb279b..f1db282d059c1d0a6e264943344e09bda5d40282:/src/components/tree/tree.test.tsx

diff --git a/src/components/tree/tree.test.tsx b/src/components/tree/tree.test.tsx
index bb0499f8..a153ec06 100644
--- a/src/components/tree/tree.test.tsx
+++ b/src/components/tree/tree.test.tsx
@@ -5,51 +5,95 @@ import * as React from 'react';
 import { mount } from 'enzyme';
 import * as Enzyme from 'enzyme';
 import * as Adapter from 'enzyme-adapter-react-16';
-import { Collapse } from '@material-ui/core';
-import CircularProgress from '@material-ui/core/CircularProgress';
 import ListItem from "@material-ui/core/ListItem/ListItem";
 
-import Tree, {TreeItem} from './tree';
-import { Project } from '../../models/project';
+import { Tree, TreeItem, TreeItemStatus } from './tree';
+import { ProjectResource } from '../../models/project';
+import { mockProjectResource } from '../../models/test-utils';
+import { Checkbox } from '@material-ui/core';
+
 Enzyme.configure({ adapter: new Adapter() });
 
 describe("Tree component", () => {
 
-	it("should render ListItem", () => {
-		const project: TreeItem<Project> = {
-            data: {
-                name: "sample name",
-                createdAt: "2018-06-12",
-                modifiedAt: "2018-06-13",
-                uuid: "uuid",
-                ownerUuid: "ownerUuid",
-                href: "href",
-            },
+    it("should render ListItem", () => {
+        const project: TreeItem<ProjectResource> = {
+            data: mockProjectResource(),
             id: "3",
             open: true,
-			active: true,
-			status: 1,
+            active: true,
+            status: TreeItemStatus.LOADED
         };
-		const wrapper = mount(<Tree render={project => <div/>} toggleItem={() => { }} items={[project]}/>)
-		expect(wrapper.find(ListItem)).toHaveLength(1);
-	});
-    
+        const wrapper = mount(<Tree
+            render={project => <div />}
+            toggleItemOpen={jest.fn()}
+            toggleItemActive={jest.fn()}
+            onContextMenu={jest.fn()}
+            items={[project]} />);
+        expect(wrapper.find(ListItem)).toHaveLength(1);
+    });
+
     it("should render arrow", () => {
-		const project: TreeItem<Project> = {
-            data: {
-                name: "sample name",
-                createdAt: "2018-06-12",
-                modifiedAt: "2018-06-13",
-                uuid: "uuid",
-                ownerUuid: "ownerUuid",
-                href: "href",
-            },
+        const project: TreeItem<ProjectResource> = {
+            data: mockProjectResource(),
             id: "3",
             open: true,
-			active: true,
-			status: 1,
+            active: true,
+            status: TreeItemStatus.LOADED,
         };
-		const wrapper = mount(<Tree render={project => <div/>} toggleItem={() => { }} items={[project]}/>)
-		expect(wrapper.find('i')).toHaveLength(1);
-	});
+        const wrapper = mount(<Tree
+            render={project => <div />}
+            toggleItemOpen={jest.fn()}
+            toggleItemActive={jest.fn()}
+            onContextMenu={jest.fn()}
+            items={[project]} />);
+        expect(wrapper.find('i')).toHaveLength(1);
+    });
+
+    it("should render checkbox", () => {
+        const project: TreeItem<ProjectResource> = {
+            data: mockProjectResource(),
+            id: "3",
+            open: true,
+            active: true,
+            status: TreeItemStatus.LOADED
+        };
+        const wrapper = mount(<Tree
+            showSelection={true}
+            render={() => <div />}
+            toggleItemOpen={jest.fn()}
+            toggleItemActive={jest.fn()}
+            onContextMenu={jest.fn()}
+            items={[project]} />);
+        expect(wrapper.find(Checkbox)).toHaveLength(1);
+    });
+
+    it("call onSelectionChanged with associated item", () => {
+        const project: TreeItem<ProjectResource> = {
+            data: mockProjectResource(),
+            id: "3",
+            open: true,
+            active: true,
+            status: TreeItemStatus.LOADED,
+        };
+        const spy = jest.fn();
+        const onSelectionChanged = (event: any, item: TreeItem<any>) => spy(item);
+        const wrapper = mount(<Tree
+            showSelection={true}
+            render={() => <div />}
+            toggleItemOpen={jest.fn()}
+            toggleItemActive={jest.fn()}
+            onContextMenu={jest.fn()}
+            toggleItemSelection={onSelectionChanged}
+            items={[project]} />);
+        wrapper.find(Checkbox).simulate('click');
+        expect(spy).toHaveBeenLastCalledWith({
+            data: mockProjectResource(),
+            id: "3",
+            open: true,
+            active: true,
+            status: TreeItemStatus.LOADED,
+        });
+    });
+
 });
