From 62e6fff927ed9def5dc9cecb9a67b0fee7430e5d Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Wed, 16 Nov 2022 14:47:50 -0500 Subject: [PATCH] 19504: Fix breadcrumb unit tests Arvados-DCO-1.1-Signed-off-by: Stephen Smith --- .../breadcrumbs/breadcrumbs.test.tsx | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/src/components/breadcrumbs/breadcrumbs.test.tsx b/src/components/breadcrumbs/breadcrumbs.test.tsx index 1594c036..f17ce393 100644 --- a/src/components/breadcrumbs/breadcrumbs.test.tsx +++ b/src/components/breadcrumbs/breadcrumbs.test.tsx @@ -3,12 +3,15 @@ // SPDX-License-Identifier: AGPL-3.0 import React from "react"; -import { configure, shallow } from "enzyme"; +import { configure, mount } from "enzyme"; import Adapter from "enzyme-adapter-react-16"; import { Breadcrumbs } from "./breadcrumbs"; -import { Button } from "@material-ui/core"; +import { Button, MuiThemeProvider } from "@material-ui/core"; import ChevronRightIcon from '@material-ui/icons/ChevronRight'; +import { CustomTheme } from 'common/custom-theme'; +import { Provider } from "react-redux"; +import { combineReducers, createStore } from "redux"; configure({ adapter: new Adapter() }); @@ -16,36 +19,63 @@ describe("", () => { let onClick: () => void; let resources = {}; - + let store; beforeEach(() => { onClick = jest.fn(); + const initialAuthState = { + config: { + clusterConfig: { + Collections: { + ForwardSlashNameSubstitution: "/" + } + } + } + } + store = createStore(combineReducers({ + auth: (state: any = initialAuthState, action: any) => state, + })); }); it("renders one item", () => { const items = [ - { label: 'breadcrumb 1' } + { label: 'breadcrumb 1', uuid: '1' } ]; - const breadcrumbs = shallow().dive(); + const breadcrumbs = mount( + + + + + ); expect(breadcrumbs.find(Button)).toHaveLength(1); expect(breadcrumbs.find(ChevronRightIcon)).toHaveLength(0); }); it("renders multiple items", () => { const items = [ - { label: 'breadcrumb 1' }, - { label: 'breadcrumb 2' } + { label: 'breadcrumb 1', uuid: '1' }, + { label: 'breadcrumb 2', uuid: '2' } ]; - const breadcrumbs = shallow().dive(); + const breadcrumbs = mount( + + + + + ); expect(breadcrumbs.find(Button)).toHaveLength(2); expect(breadcrumbs.find(ChevronRightIcon)).toHaveLength(1); }); it("calls onClick with clicked item", () => { const items = [ - { label: 'breadcrumb 1' }, - { label: 'breadcrumb 2' } + { label: 'breadcrumb 1', uuid: '1' }, + { label: 'breadcrumb 2', uuid: '2' } ]; - const breadcrumbs = shallow().dive(); + const breadcrumbs = mount( + + + + + ); breadcrumbs.find(Button).at(1).simulate('click'); expect(onClick).toBeCalledWith(items[1]); }); -- 2.39.5