1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
4 import * as React from 'react';
5 import { mount } from 'enzyme';
6 import * as Enzyme from 'enzyme';
7 import * as Adapter from 'enzyme-adapter-react-16';
8 import ListItem from "@material-ui/core/ListItem/ListItem";
10 import { Tree, TreeItem } from './tree';
11 import { ProjectResource } from '../../models/project';
12 import { mockProjectResource } from '../../models/test-utils';
13 import { Checkbox } from '@material-ui/core';
15 Enzyme.configure({ adapter: new Adapter() });
17 describe("Tree component", () => {
19 it("should render ListItem", () => {
20 const project: TreeItem<ProjectResource> = {
21 data: mockProjectResource(),
27 const wrapper = mount(<Tree
28 render={project => <div />}
29 toggleItemOpen={jest.fn()}
30 toggleItemActive={jest.fn()}
31 onContextMenu={jest.fn()}
32 items={[project]} />);
33 expect(wrapper.find(ListItem)).toHaveLength(1);
36 it("should render arrow", () => {
37 const project: TreeItem<ProjectResource> = {
38 data: mockProjectResource(),
44 const wrapper = mount(<Tree
45 render={project => <div />}
46 toggleItemOpen={jest.fn()}
47 toggleItemActive={jest.fn()}
48 onContextMenu={jest.fn()}
49 items={[project]} />);
50 expect(wrapper.find('i')).toHaveLength(1);
53 it("should render checkbox", () => {
54 const project: TreeItem<ProjectResource> = {
55 data: mockProjectResource(),
61 const wrapper = mount(<Tree
63 render={() => <div />}
64 toggleItemOpen={jest.fn()}
65 toggleItemActive={jest.fn()}
66 onContextMenu={jest.fn()}
67 items={[project]} />);
68 expect(wrapper.find(Checkbox)).toHaveLength(1);
71 it("call onSelectionChanged with associated item", () => {
72 const project: TreeItem<ProjectResource> = {
73 data: mockProjectResource(),
79 const spy = jest.fn();
80 const onSelectionChanged = (event: any, item: TreeItem<any>) => spy(item);
81 const wrapper = mount(<Tree
83 render={() => <div />}
84 toggleItemOpen={jest.fn()}
85 toggleItemActive={jest.fn()}
86 onContextMenu={jest.fn()}
87 onSelectionChange={onSelectionChanged}
88 items={[project]} />);
89 wrapper.find(Checkbox).prop('onClick')();
90 expect(spy).toHaveBeenLastCalledWith({
91 data: mockProjectResource(),