1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { mount, configure } from "enzyme";
7 import * as Adapter from "enzyme-adapter-react-16";
8 import { MainAppBar, MainAppBarProps } from './main-app-bar';
9 import { SearchBar } from "~/components/search-bar/search-bar";
10 import { Breadcrumbs } from "~/components/breadcrumbs/breadcrumbs";
11 import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
12 import { Button, MenuItem, IconButton } from "@material-ui/core";
13 import { User } from "~/models/user";
15 configure({ adapter: new Adapter() });
17 describe("<MainAppBar />", () => {
22 email: "test.user@example.com",
27 it("renders all components and the menu for authenticated user if user prop has value", () => {
28 const mainAppBar = mount(
30 {...mockMainAppBarProps({ user })}
33 expect(mainAppBar.find(SearchBar)).toHaveLength(1);
34 expect(mainAppBar.find(Breadcrumbs)).toHaveLength(1);
35 expect(mainAppBar.find(DropdownMenu)).toHaveLength(2);
38 it("renders only the menu for anonymous user if user prop is undefined", () => {
39 const menuItems = { accountMenu: [], helpMenu: [], anonymousMenu: [{ label: 'Sign in' }] };
40 const mainAppBar = mount(
42 {...mockMainAppBarProps({ user: undefined, menuItems })}
45 expect(mainAppBar.find(SearchBar)).toHaveLength(0);
46 expect(mainAppBar.find(Breadcrumbs)).toHaveLength(0);
47 expect(mainAppBar.find(DropdownMenu)).toHaveLength(0);
48 expect(mainAppBar.find(Button)).toHaveLength(1);
51 it("communicates with <SearchBar />", () => {
52 const onSearch = jest.fn();
53 const mainAppBar = mount(
55 {...mockMainAppBarProps({ searchText: 'search text', searchDebounce: 2000, onSearch, user })}
58 const searchBar = mainAppBar.find(SearchBar);
59 expect(searchBar.prop("value")).toBe("search text");
60 expect(searchBar.prop("debounce")).toBe(2000);
61 searchBar.prop("onSearch")("new search text");
62 expect(onSearch).toBeCalledWith("new search text");
65 it("communicates with menu", () => {
66 const onMenuItemClick = jest.fn();
67 const menuItems = { accountMenu: [{ label: "log out" }], helpMenu: [], anonymousMenu: [] };
68 const mainAppBar = mount(
70 {...mockMainAppBarProps({ menuItems, onMenuItemClick, user })}
74 mainAppBar.find(DropdownMenu).at(0).find(IconButton).simulate("click");
75 mainAppBar.find(DropdownMenu).at(0).find(MenuItem).at(1).simulate("click");
76 expect(onMenuItemClick).toBeCalledWith(menuItems.accountMenu[0]);
80 const Breadcrumbs = () => <span>Breadcrumbs</span>;
82 const mockMainAppBarProps = (props: Partial<MainAppBarProps>): MainAppBarProps => ({
84 breadcrumbs: Breadcrumbs,
92 onMenuItemClick: jest.fn(),
93 onDetailsPanelToggle: jest.fn(),