Skip to content
Snippets Groups Projects
Commit f23e1c77 authored by Mathias Maaß's avatar Mathias Maaß
Browse files

Refactor <WindowTopMenu/> component.

parent 20033aa7
No related branches found
No related tags found
No related merge requests found
import React from 'react';
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';
/** create wrapper */
function createWrapper(props) {
return shallow(
<WindowTopMenu
windowId="xyz"
handleClose={() => {}}
anchorEl={null}
{...props}
/>,
);
}
describe('WindowTopMenu', () => {
let wrapper;
let handleClose;
beforeEach(() => {
handleClose = jest.fn();
wrapper = shallow(<WindowTopMenu windowId="xyz" handleClose={handleClose} />).dive();
it('renders all needed elements', () => {
const wrapper = createWrapper();
expect(wrapper.find(Menu).length).toBe(1);
expect(wrapper.find(ListItem).length).toBe(1);
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', () => {
expect(wrapper.find('WithStyles(Menu)').length).toBe(1);
expect(wrapper.find('Connect(WindowThumbnailSettings)').length).toBe(1);
it('passses correct props to <Menu/> when no achor element given', () => {
const handleClose = jest.fn();
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 { shallow } from 'enzyme';
import WindowTopMenuButton from '../../../src/components/WindowTopMenuButton';
import WindowTopMenu from '../../../src/containers/WindowTopMenu';
describe('WindowTopMenuButton', () => {
let wrapper;
......@@ -15,6 +16,6 @@ describe('WindowTopMenuButton', () => {
});
it('when clicked, updates the state', () => {
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 { compose } from 'redux';
import ListItem from '@material-ui/core/ListItem';
import Menu from '@material-ui/core/Menu';
import Divider from '@material-ui/core/Divider';
import { withStyles } from '@material-ui/core/styles';
import PropTypes from 'prop-types';
import WindowThumbnailSettings from '../containers/WindowThumbnailSettings';
/**
*/
class WindowTopMenu extends Component {
/**
* constructor -
*/
constructor(props) {
super(props);
this.state = {
};
}
/**
* render
* @return
......@@ -50,15 +39,4 @@ WindowTopMenu.defaultProps = {
anchorEl: null,
};
/**
* @private
*/
const styles = theme => ({
});
const enhance = compose(
withStyles(styles),
// further HOC go here
);
export default enhance(WindowTopMenu);
export default WindowTopMenu;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment