From a234ec2fdf7a257aa1a9268d892e2b6079d4ef55 Mon Sep 17 00:00:00 2001 From: Michal Klobukowski Date: Wed, 13 Jun 2018 10:30:30 +0200 Subject: [PATCH] Create breadcrumbs tests Feature #13590 Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski --- .../breadcrumbs/breadcrumbs.test.tsx | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/components/breadcrumbs/breadcrumbs.test.tsx diff --git a/src/components/breadcrumbs/breadcrumbs.test.tsx b/src/components/breadcrumbs/breadcrumbs.test.tsx new file mode 100644 index 00000000..77beb494 --- /dev/null +++ b/src/components/breadcrumbs/breadcrumbs.test.tsx @@ -0,0 +1,53 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import * as React from "react"; +import { mount, configure } from "enzyme"; + +import * as Adapter from "enzyme-adapter-react-16"; +import Breadcrumbs from "./breadcrumbs"; +import { Button } from "@material-ui/core"; +import ChevronRightIcon from '@material-ui/icons/ChevronRight'; + +configure({ adapter: new Adapter() }); + +describe("", () => { + + let onClick: () => void; + + beforeEach(() => { + onClick = jest.fn(); + }); + + it("renders one item", () => { + const items = [ + {label: 'breadcrumb 1'} + ]; + 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'} + ]; + 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'} + ]; + const breadcrumbs = mount(); + breadcrumbs.find(Button).at(1).simulate('click'); + expect(onClick).toBeCalledWith(items[1]); + }); + + +}); \ No newline at end of file -- 2.39.5