From: Lucas Di Pentima Date: Tue, 19 Oct 2021 20:50:38 +0000 (-0300) Subject: 18128: Adds unit tests. X-Git-Tag: 2.4.0~25^2~7 X-Git-Url: https://git.arvados.org/arvados-workbench2.git/commitdiff_plain/8699b7818676e6b22707757989885b58060e06b3?hp=5eeb8bd77267293db601ba914fc09ef162057b33 18128: Adds unit tests. Arvados-DCO-1.1-Signed-off-by: Lucas Di Pentima --- diff --git a/src/components/multi-panel-view/multi-panel-view.test.tsx b/src/components/multi-panel-view/multi-panel-view.test.tsx new file mode 100644 index 00000000..53a3bb60 --- /dev/null +++ b/src/components/multi-panel-view/multi-panel-view.test.tsx @@ -0,0 +1,85 @@ +// Copyright (C) The Arvados Authors. All rights reserved. +// +// SPDX-License-Identifier: AGPL-3.0 + +import React from "react"; +import { configure, mount } from "enzyme"; +import Adapter from "enzyme-adapter-react-16"; +import { MPVContainer } from './multi-panel-view'; +import { Button } from "@material-ui/core"; + +configure({ adapter: new Adapter() }); + +const PanelMock = ({panelName, panelMaximized, doHidePanel, doMaximizePanel, children, ...rest}) => +
{children}
; + +describe('', () => { + let props; + + beforeEach(() => { + props = { + classes: {}, + }; + }); + + it('should show default toggle buttons for every child', () => { + const childs = [ + This is one panel, + This is another panel, + ]; + const wrapper = mount({[...childs]}); + expect(wrapper.find(Button).first().html()).toContain('Panel 1'); + expect(wrapper.html()).toContain('This is one panel'); + expect(wrapper.find(Button).last().html()).toContain('Panel 2'); + expect(wrapper.html()).toContain('This is another panel'); + }); + + it('should toggle panel when clicking on its button', () => { + const childs = [ + This is one panel, + ]; + const wrapper = mount({[...childs]}); + + // Initial state: panel visible + expect(wrapper.html()).toContain('This is one panel'); + + // Panel toggling + wrapper.find(Button).simulate('click'); + expect(wrapper.html()).not.toContain('This is one panel'); + expect(wrapper.html()).toContain('All panels are hidden'); + wrapper.find(Button).simulate('click'); + expect(wrapper.html()).toContain('This is one panel'); + expect(wrapper.html()).not.toContain('All panels are hidden'); + }); + + it('should show custom toggle buttons when config provided', () => { + const childs = [ + This is one panel, + This is another panel, + ]; + props.panelStates = [ + {name: 'First Panel'}, + ] + const wrapper = mount({[...childs]}); + expect(wrapper.find(Button).first().html()).toContain('First Panel'); + expect(wrapper.html()).toContain('This is one panel'); + // Second panel received the default button naming and hidden status by default + expect(wrapper.find(Button).last().html()).toContain('Panel 2'); + expect(wrapper.html()).not.toContain('This is another panel'); + wrapper.find(Button).last().simulate('click'); + expect(wrapper.html()).toContain('This is another panel'); + }); + + it('should set panel hidden when requested', () => { + const childs = [ + This is one panel, + ]; + props.panelStates = [ + {name: 'First Panel', visible: false}, + ] + const wrapper = mount({[...childs]}); + expect(wrapper.find(Button).html()).toContain('First Panel'); + expect(wrapper.html()).not.toContain('This is one panel'); + expect(wrapper.html()).toContain('All panels are hidden'); + }); +}); \ No newline at end of file diff --git a/src/components/multi-panel-view/multi-panel-view.tsx b/src/components/multi-panel-view/multi-panel-view.tsx index 6778b526..35daa13c 100644 --- a/src/components/multi-panel-view/multi-panel-view.tsx +++ b/src/components/multi-panel-view/multi-panel-view.tsx @@ -119,8 +119,8 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo ? `Panel ${idx+1}` : (panelStates[idx] && panelStates[idx].name) || `Panel ${idx+1}`; const toggleVariant = panelVisibility[idx] - ? "raised" - : "flat"; + ? "contained" + : "text"; const toggleTooltip = panelVisibility[idx] ? `Hide ${panelName} panel` : `Show ${panelName} panel`; @@ -140,7 +140,7 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo ]; const aPanel = - {children[idx]} @@ -151,7 +151,7 @@ const MPVContainerComponent = ({children, panelStates, classes, ...props}: MPVCo return - { toggles.map(tgl => {tgl}) } + { toggles.map((tgl, idx) => {tgl}) } { panelVisibility.includes(true)