1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { configure, mount } from "enzyme";
8 import Adapter from "enzyme-adapter-react-16";
9 import { Breadcrumbs } from "./breadcrumbs";
10 import { Button, MuiThemeProvider } from "@material-ui/core";
11 import ChevronRightIcon from '@material-ui/icons/ChevronRight';
12 import { CustomTheme } from 'common/custom-theme';
13 import { Provider } from "react-redux";
14 import { combineReducers, createStore } from "redux";
16 configure({ adapter: new Adapter() });
18 describe("<Breadcrumbs />", () => {
20 let onClick: () => void;
25 const initialAuthState = {
29 ForwardSlashNameSubstitution: "/"
34 store = createStore(combineReducers({
35 auth: (state: any = initialAuthState, action: any) => state,
39 it("renders one item", () => {
41 { label: 'breadcrumb 1', uuid: '1' }
43 const breadcrumbs = mount(
44 <Provider store={store}>
45 <MuiThemeProvider theme={CustomTheme}>
46 <Breadcrumbs items={items} resources={resources} onClick={onClick} onContextMenu={jest.fn()} />
49 expect(breadcrumbs.find(Button)).toHaveLength(1);
50 expect(breadcrumbs.find(ChevronRightIcon)).toHaveLength(0);
53 it("renders multiple items", () => {
55 { label: 'breadcrumb 1', uuid: '1' },
56 { label: 'breadcrumb 2', uuid: '2' }
58 const breadcrumbs = mount(
59 <Provider store={store}>
60 <MuiThemeProvider theme={CustomTheme}>
61 <Breadcrumbs items={items} resources={resources} onClick={onClick} onContextMenu={jest.fn()} />
64 expect(breadcrumbs.find(Button)).toHaveLength(2);
65 expect(breadcrumbs.find(ChevronRightIcon)).toHaveLength(1);
68 it("calls onClick with clicked item", () => {
70 { label: 'breadcrumb 1', uuid: '1' },
71 { label: 'breadcrumb 2', uuid: '2' }
73 const breadcrumbs = mount(
74 <Provider store={store}>
75 <MuiThemeProvider theme={CustomTheme}>
76 <Breadcrumbs items={items} resources={resources} onClick={onClick} onContextMenu={jest.fn()} />
79 breadcrumbs.find(Button).at(1).simulate('click');
80 expect(onClick).toHaveBeenCalledWith(expect.any(Function), items[1]);