import { DropdownMenu } from "~/components/dropdown-menu/dropdown-menu";
import { Button, MenuItem, IconButton } from "@material-ui/core";
import { User } from "~/models/user";
+import { MemoryRouter } from 'react-router-dom';
configure({ adapter: new Adapter() });
it("renders all components and the menu for authenticated user if user prop has value", () => {
const mainAppBar = mount(
- <MainAppBar
- {...mockMainAppBarProps({ user })}
- />
+ <MemoryRouter>
+ <MainAppBar
+ {...mockMainAppBarProps({ user })}
+ />
+ </MemoryRouter>
);
expect(mainAppBar.find(SearchBar)).toHaveLength(1);
expect(mainAppBar.find(Breadcrumbs)).toHaveLength(1);
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
- {...mockMainAppBarProps({ user: undefined, menuItems })}
- />
+ <MemoryRouter>
+ <MainAppBar
+ {...mockMainAppBarProps({ user: undefined, menuItems })}
+ />
+ </MemoryRouter>
);
expect(mainAppBar.find(SearchBar)).toHaveLength(0);
expect(mainAppBar.find(Breadcrumbs)).toHaveLength(0);
it("communicates with <SearchBar />", () => {
const onSearch = jest.fn();
const mainAppBar = mount(
- <MainAppBar
- {...mockMainAppBarProps({ searchText: 'search text', searchDebounce: 2000, onSearch, user })}
- />
+ <MemoryRouter>
+ <MainAppBar
+ {...mockMainAppBarProps({ searchText: 'search text', searchDebounce: 2000, onSearch, user })}
+ />
+ </MemoryRouter>
);
const searchBar = mainAppBar.find(SearchBar);
expect(searchBar.prop("value")).toBe("search text");
const onMenuItemClick = jest.fn();
const menuItems = { accountMenu: [{ label: "log out" }], helpMenu: [], anonymousMenu: [] };
const mainAppBar = mount(
- <MainAppBar
- {...mockMainAppBarProps({ menuItems, onMenuItemClick, user })}
- />
+ <MemoryRouter>
+ <MainAppBar
+ {...mockMainAppBarProps({ menuItems, onMenuItemClick, user })}
+ />
+ </MemoryRouter>
);
mainAppBar.find(DropdownMenu).at(0).find(IconButton).simulate("click");