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, doUnMaximizePanel, panelIlluminated, panelRef, children, ...rest}) =>
14 <div {...rest}>{children}</div>;
16 describe('<MPVContainer />', () => {
25 it('should show default panel 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 show panel when clicking on its button', () => {
39 <PanelMock key={1}>This is one panel</PanelMock>,
42 {name: 'Initially invisible Panel', visible: false},
45 const wrapper = mount(<MPVContainer {...props}>{[...childs]}</MPVContainer>);
47 // Initial state: panel not visible
48 expect(wrapper.html()).not.toContain('This is one panel');
49 expect(wrapper.html()).toContain('All panels are hidden');
51 // Panel visible when clicking on its button
52 wrapper.find(Button).simulate('click');
53 expect(wrapper.html()).toContain('This is one panel');
54 expect(wrapper.html()).not.toContain('All panels are hidden');
57 it('should show custom panel buttons when config provided', () => {
59 <PanelMock key={1}>This is one panel</PanelMock>,
60 <PanelMock key={2}>This is another panel</PanelMock>,
63 {name: 'First Panel'},
65 const wrapper = mount(<MPVContainer {...props}>{[...childs]}</MPVContainer>);
66 expect(wrapper.find(Button).first().html()).toContain('First Panel');
67 expect(wrapper.html()).toContain('This is one panel');
68 // Second panel received the default button naming and hidden status by default
69 expect(wrapper.find(Button).last().html()).toContain('Panel 2');
70 expect(wrapper.html()).not.toContain('This is another panel');
71 wrapper.find(Button).last().simulate('click');
72 expect(wrapper.html()).toContain('This is another panel');
75 it('should set panel hidden when requested', () => {
77 <PanelMock key={1}>This is one panel</PanelMock>,
80 {name: 'First Panel', visible: false},
82 const wrapper = mount(<MPVContainer {...props}>{[...childs]}</MPVContainer>);
83 expect(wrapper.find(Button).html()).toContain('First Panel');
84 expect(wrapper.html()).not.toContain('This is one panel');
85 expect(wrapper.html()).toContain('All panels are hidden');