Skip to content
Snippets Groups Projects
Unverified Commit a8e955e9 authored by Jessie Keck's avatar Jessie Keck Committed by GitHub
Browse files

Merge pull request #1843 from ProjectMirador/refeactor-windowtopmenu-component

Refactor <WindowTopMenu/> component.
parents 98dcb054 f23e1c77
Branches
Tags
No related merge requests found
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import ListItem from '@material-ui/core/ListItem';
import Menu from '@material-ui/core/Menu';
import Divider from '@material-ui/core/Divider';
import WindowThumbnailSettings from '../../../src/containers/WindowThumbnailSettings';
import WindowTopMenu from '../../../src/components/WindowTopMenu'; import WindowTopMenu from '../../../src/components/WindowTopMenu';
/** create wrapper */
function createWrapper(props) {
return shallow(
<WindowTopMenu
windowId="xyz"
handleClose={() => {}}
anchorEl={null}
{...props}
/>,
);
}
describe('WindowTopMenu', () => { describe('WindowTopMenu', () => {
let wrapper; it('renders all needed elements', () => {
let handleClose; const wrapper = createWrapper();
beforeEach(() => { expect(wrapper.find(Menu).length).toBe(1);
handleClose = jest.fn(); expect(wrapper.find(ListItem).length).toBe(1);
wrapper = shallow(<WindowTopMenu windowId="xyz" handleClose={handleClose} />).dive(); expect(wrapper.find(WindowThumbnailSettings).length).toBe(1);
expect(wrapper.find(Divider).length).toBe(1);
});
it('passes windowId to <WindowThumbnailSettings/>', () => {
const wrapper = createWrapper();
expect(wrapper.find(WindowThumbnailSettings)
.first().props().windowId).toBe('xyz');
});
it('passses correct props to <Menu/> when no achor element given', () => {
const handleClose = jest.fn();
const wrapper = createWrapper({ handleClose });
expect(wrapper.find(Menu).first().props().anchorEl).toBe(null);
expect(wrapper.find(Menu).first().props().open).toBe(false);
expect(wrapper.find(Menu).first().props().onClose).toBe(handleClose);
}); });
it('renders without an error', () => { it('passses correct props to <Menu/> when no achor element given', () => {
expect(wrapper.find('WithStyles(Menu)').length).toBe(1); const handleClose = jest.fn();
expect(wrapper.find('Connect(WindowThumbnailSettings)').length).toBe(1); const anchorEl = {};
const wrapper = createWrapper({ anchorEl, handleClose });
expect(wrapper.find(Menu).first().props().anchorEl).toBe(anchorEl);
expect(wrapper.find(Menu).first().props().open).toBe(true);
expect(wrapper.find(Menu).first().props().onClose).toBe(handleClose);
}); });
}); });
import React from 'react'; import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import WindowTopMenuButton from '../../../src/components/WindowTopMenuButton'; import WindowTopMenuButton from '../../../src/components/WindowTopMenuButton';
import WindowTopMenu from '../../../src/containers/WindowTopMenu';
describe('WindowTopMenuButton', () => { describe('WindowTopMenuButton', () => {
let wrapper; let wrapper;
...@@ -15,6 +16,6 @@ describe('WindowTopMenuButton', () => { ...@@ -15,6 +16,6 @@ describe('WindowTopMenuButton', () => {
}); });
it('when clicked, updates the state', () => { it('when clicked, updates the state', () => {
wrapper.find('WithStyles(IconButton)').simulate('click', { currentTarget: 'x' }); wrapper.find('WithStyles(IconButton)').simulate('click', { currentTarget: 'x' });
expect(wrapper.find('Connect(miradorWithPlugins(WithStyles(WindowTopMenu)))').props().anchorEl).toBe('x'); expect(wrapper.find(WindowTopMenu).props().anchorEl).toBe('x');
}); });
}); });
import React, { Component } from 'react'; import React, { Component } from 'react';
import { compose } from 'redux';
import ListItem from '@material-ui/core/ListItem'; import ListItem from '@material-ui/core/ListItem';
import Menu from '@material-ui/core/Menu'; import Menu from '@material-ui/core/Menu';
import Divider from '@material-ui/core/Divider'; import Divider from '@material-ui/core/Divider';
import { withStyles } from '@material-ui/core/styles';
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import WindowThumbnailSettings from '../containers/WindowThumbnailSettings'; import WindowThumbnailSettings from '../containers/WindowThumbnailSettings';
/** /**
*/ */
class WindowTopMenu extends Component { class WindowTopMenu extends Component {
/**
* constructor -
*/
constructor(props) {
super(props);
this.state = {
};
}
/** /**
* render * render
* @return * @return
...@@ -50,15 +39,4 @@ WindowTopMenu.defaultProps = { ...@@ -50,15 +39,4 @@ WindowTopMenu.defaultProps = {
anchorEl: null, anchorEl: null,
}; };
/** export default WindowTopMenu;
* @private
*/
const styles = theme => ({
});
const enhance = compose(
withStyles(styles),
// further HOC go here
);
export default enhance(WindowTopMenu);
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment