19504: Add resource colors to breadcrumbs
[arvados.git] / src / components / breadcrumbs / breadcrumbs.test.tsx
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import React from "react";
6 import { configure, shallow } from "enzyme";
7
8 import Adapter from "enzyme-adapter-react-16";
9 import { Breadcrumbs } from "./breadcrumbs";
10 import { Button } from "@material-ui/core";
11 import ChevronRightIcon from '@material-ui/icons/ChevronRight';
12
13 configure({ adapter: new Adapter() });
14
15 describe("<Breadcrumbs />", () => {
16
17     let onClick: () => void;
18     let resources = {};
19
20     beforeEach(() => {
21         onClick = jest.fn();
22     });
23
24     it("renders one item", () => {
25         const items = [
26             { label: 'breadcrumb 1' }
27         ];
28         const breadcrumbs = shallow(<Breadcrumbs items={items} resources={resources} onClick={onClick} onContextMenu={jest.fn()} />).dive();
29         expect(breadcrumbs.find(Button)).toHaveLength(1);
30         expect(breadcrumbs.find(ChevronRightIcon)).toHaveLength(0);
31     });
32
33     it("renders multiple items", () => {
34         const items = [
35             { label: 'breadcrumb 1' },
36             { label: 'breadcrumb 2' }
37         ];
38         const breadcrumbs = shallow(<Breadcrumbs items={items} resources={resources} onClick={onClick} onContextMenu={jest.fn()} />).dive();
39         expect(breadcrumbs.find(Button)).toHaveLength(2);
40         expect(breadcrumbs.find(ChevronRightIcon)).toHaveLength(1);
41     });
42
43     it("calls onClick with clicked item", () => {
44         const items = [
45             { label: 'breadcrumb 1' },
46             { label: 'breadcrumb 2' }
47         ];
48         const breadcrumbs = shallow(<Breadcrumbs items={items} resources={resources} onClick={onClick} onContextMenu={jest.fn()} />).dive();
49         breadcrumbs.find(Button).at(1).simulate('click');
50         expect(onClick).toBeCalledWith(items[1]);
51     });
52
53 });