X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/f14b66751cfaf92a2bc28331d8878789d4040e8f..cbd013127744bc5bf3cf3a4159dcf3d6f2b43855:/src/views-components/main-app-bar/main-app-bar.test.tsx

diff --git a/src/views-components/main-app-bar/main-app-bar.test.tsx b/src/views-components/main-app-bar/main-app-bar.test.tsx
index 7bdb63b3f6..69b4dd648c 100644
--- a/src/views-components/main-app-bar/main-app-bar.test.tsx
+++ b/src/views-components/main-app-bar/main-app-bar.test.tsx
@@ -3,14 +3,15 @@
 // SPDX-License-Identifier: AGPL-3.0
 
 import * as React from "react";
-import { mount, configure, ReactWrapper } from "enzyme";
+import { mount, configure } from "enzyme";
 import * as Adapter from "enzyme-adapter-react-16";
-import MainAppBar from "./main-app-bar";
-import SearchBar from "../../components/search-bar/search-bar";
-import Breadcrumbs from "../../components/breadcrumbs/breadcrumbs";
-import DropdownMenu from "../../components/dropdown-menu/dropdown-menu";
+import { MainAppBar, MainAppBarProps } from './main-app-bar';
+import { SearchBar } from "~/components/search-bar/search-bar";
+import { Breadcrumbs } from "~/components/breadcrumbs/breadcrumbs";
+import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
 import { Button, MenuItem, IconButton } from "@material-ui/core";
-import { User } from "../../models/user";
+import { User } from "~/models/user";
+import { MemoryRouter } from 'react-router-dom';
 
 configure({ adapter: new Adapter() });
 
@@ -26,11 +27,11 @@ describe("<MainAppBar />", () => {
 
     it("renders all components and the menu for authenticated user if user prop has value", () => {
         const mainAppBar = mount(
-            <MainAppBar
-                user={user}
-                onDetailsPanelToggle={jest.fn()}
-                {...{ searchText: "", breadcrumbs: [], menuItems: { accountMenu: [], helpMenu: [], anonymousMenu: [] }, onSearch: jest.fn(), onBreadcrumbClick: jest.fn(), onMenuItemClick: jest.fn() }}
-            />
+            <MemoryRouter>
+                <MainAppBar
+                    {...mockMainAppBarProps({ user })}
+                />
+            </MemoryRouter>
         );
         expect(mainAppBar.find(SearchBar)).toHaveLength(1);
         expect(mainAppBar.find(Breadcrumbs)).toHaveLength(1);
@@ -40,11 +41,11 @@ describe("<MainAppBar />", () => {
     it("renders only the menu for anonymous user if user prop is undefined", () => {
         const menuItems = { accountMenu: [], helpMenu: [], anonymousMenu: [{ label: 'Sign in' }] };
         const mainAppBar = mount(
-            <MainAppBar
-                menuItems={menuItems}
-                onDetailsPanelToggle={jest.fn()}
-                {...{ searchText: "", breadcrumbs: [], onSearch: jest.fn(), onBreadcrumbClick: jest.fn(), onMenuItemClick: jest.fn() }}
-            />
+            <MemoryRouter>
+                <MainAppBar
+                    {...mockMainAppBarProps({ user: undefined, menuItems })}
+                />
+            </MemoryRouter>
         );
         expect(mainAppBar.find(SearchBar)).toHaveLength(0);
         expect(mainAppBar.find(Breadcrumbs)).toHaveLength(0);
@@ -55,13 +56,11 @@ describe("<MainAppBar />", () => {
     it("communicates with <SearchBar />", () => {
         const onSearch = jest.fn();
         const mainAppBar = mount(
-            <MainAppBar
-                searchText="search text"
-                searchDebounce={2000}
-                onSearch={onSearch}
-                onDetailsPanelToggle={jest.fn()}
-                {...{ user, breadcrumbs: [], menuItems: { accountMenu: [], helpMenu: [], anonymousMenu: [] }, onBreadcrumbClick: jest.fn(), onMenuItemClick: jest.fn() }}
-            />
+            <MemoryRouter>
+                <MainAppBar
+                    {...mockMainAppBarProps({ searchText: 'search text', searchDebounce: 2000, onSearch, user })}
+                />
+            </MemoryRouter>
         );
         const searchBar = mainAppBar.find(SearchBar);
         expect(searchBar.prop("value")).toBe("search text");
@@ -70,33 +69,15 @@ describe("<MainAppBar />", () => {
         expect(onSearch).toBeCalledWith("new search text");
     });
 
-    it("communicates with <Breadcrumbs />", () => {
-        const items = [{ label: "breadcrumb 1" }];
-        const onBreadcrumbClick = jest.fn();
-        const mainAppBar = mount(
-            <MainAppBar
-                breadcrumbs={items}
-                onBreadcrumbClick={onBreadcrumbClick}
-                onDetailsPanelToggle={jest.fn()}
-                {...{ user, searchText: "", menuItems: { accountMenu: [], helpMenu: [], anonymousMenu: [] }, onSearch: jest.fn(), onMenuItemClick: jest.fn() }}
-            />
-        );
-        const breadcrumbs = mainAppBar.find(Breadcrumbs);
-        expect(breadcrumbs.prop("items")).toBe(items);
-        breadcrumbs.prop("onClick")(items[0]);
-        expect(onBreadcrumbClick).toBeCalledWith(items[0]);
-    });
-
     it("communicates with menu", () => {
         const onMenuItemClick = jest.fn();
-        const menuItems = { accountMenu: [{label: "log out"}], helpMenu: [], anonymousMenu: [] };
+        const menuItems = { accountMenu: [{ label: "log out" }], helpMenu: [], anonymousMenu: [] };
         const mainAppBar = mount(
-            <MainAppBar
-                menuItems={menuItems}
-                onMenuItemClick={onMenuItemClick}
-                onDetailsPanelToggle={jest.fn()}
-                {...{ user, searchText: "", breadcrumbs: [], onSearch: jest.fn(), onBreadcrumbClick: jest.fn() }}
-            />
+            <MemoryRouter>
+                <MainAppBar
+                    {...mockMainAppBarProps({ menuItems, onMenuItemClick, user })}
+                />
+            </MemoryRouter>
         );
 
         mainAppBar.find(DropdownMenu).at(0).find(IconButton).simulate("click");
@@ -104,3 +85,20 @@ describe("<MainAppBar />", () => {
         expect(onMenuItemClick).toBeCalledWith(menuItems.accountMenu[0]);
     });
 });
+
+const Breadcrumbs = () => <span>Breadcrumbs</span>;
+
+const mockMainAppBarProps = (props: Partial<MainAppBarProps>): MainAppBarProps => ({
+    searchText: '',
+    breadcrumbs: Breadcrumbs,
+    menuItems: {
+        accountMenu: [],
+        helpMenu: [],
+        anonymousMenu: [],
+    },
+    buildInfo: '',
+    onSearch: jest.fn(),
+    onMenuItemClick: jest.fn(),
+    onDetailsPanelToggle: jest.fn(),
+    ...props,
+});
