1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from "react";
6 import { configure, mount } from "enzyme";
7 import Adapter from "enzyme-adapter-react-16";
8 import { MPVContainer } from './multi-panel-view';
9 import { Button } from "@material-ui/core";
11 configure({ adapter: new Adapter() });
13 const PanelMock = ({panelName, panelMaximized, doHidePanel, doMaximizePanel, children, ...rest}) =>
14 <div {...rest}>{children}</div>;
16 describe('<MPVContainer />', () => {
25 it('should show default toggle buttons for every child', () => {
27 <PanelMock key={1}>This is one panel</PanelMock>,
28 <PanelMock key={2}>This is another panel</PanelMock>,
30 const wrapper = mount(<MPVContainer {...props}>{[...childs]}</MPVContainer>);
31 expect(wrapper.find(Button).first().html()).toContain('Panel 1');
32 expect(wrapper.html()).toContain('This is one panel');
33 expect(wrapper.find(Button).last().html()).toContain('Panel 2');
34 expect(wrapper.html()).toContain('This is another panel');
37 it('should toggle panel when clicking on its button', () => {
39 <PanelMock key={1}>This is one panel</PanelMock>,
41 const wrapper = mount(<MPVContainer {...props}>{[...childs]}</MPVContainer>);
43 // Initial state: panel visible
44 expect(wrapper.html()).toContain('This is one panel');
47 wrapper.find(Button).simulate('click');
48 expect(wrapper.html()).not.toContain('This is one panel');
49 expect(wrapper.html()).toContain('All panels are hidden');
50 wrapper.find(Button).simulate('click');
51 expect(wrapper.html()).toContain('This is one panel');
52 expect(wrapper.html()).not.toContain('All panels are hidden');
55 it('should show custom toggle buttons when config provided', () => {
57 <PanelMock key={1}>This is one panel</PanelMock>,
58 <PanelMock key={2}>This is another panel</PanelMock>,
61 {name: 'First Panel'},
63 const wrapper = mount(<MPVContainer {...props}>{[...childs]}</MPVContainer>);
64 expect(wrapper.find(Button).first().html()).toContain('First Panel');
65 expect(wrapper.html()).toContain('This is one panel');
66 // Second panel received the default button naming and hidden status by default
67 expect(wrapper.find(Button).last().html()).toContain('Panel 2');
68 expect(wrapper.html()).not.toContain('This is another panel');
69 wrapper.find(Button).last().simulate('click');
70 expect(wrapper.html()).toContain('This is another panel');
73 it('should set panel hidden when requested', () => {
75 <PanelMock key={1}>This is one panel</PanelMock>,
78 {name: 'First Panel', visible: false},
80 const wrapper = mount(<MPVContainer {...props}>{[...childs]}</MPVContainer>);
81 expect(wrapper.find(Button).html()).toContain('First Panel');
82 expect(wrapper.html()).not.toContain('This is one panel');
83 expect(wrapper.html()).toContain('All panels are hidden');