diff --git a/__tests__/src/components/WindowTopMenu.test.js b/__tests__/src/components/WindowTopMenu.test.js index 47851603c78bd7d8081aaa8c8192344d094aae13..d2b260854166e6c87d7790af4e1b1efba1dbf29f 100644 --- a/__tests__/src/components/WindowTopMenu.test.js +++ b/__tests__/src/components/WindowTopMenu.test.js @@ -1,17 +1,52 @@ 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); }); }); diff --git a/__tests__/src/components/WindowTopMenuButton.test.js b/__tests__/src/components/WindowTopMenuButton.test.js index c016c58da0146cf137c8b53a7c0b93e8f472f78a..e36db1c72fe205f6fdfebfb259892bcf4fa212f7 100644 --- a/__tests__/src/components/WindowTopMenuButton.test.js +++ b/__tests__/src/components/WindowTopMenuButton.test.js @@ -1,6 +1,7 @@ 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'); }); }); diff --git a/src/components/WindowTopMenu.js b/src/components/WindowTopMenu.js index a7e41a2f84ee04866fef1eee2fec2ad5bf2d5e44..b8d799abb772164ba0f2650933ee81c837c4004a 100644 --- a/src/components/WindowTopMenu.js +++ b/src/components/WindowTopMenu.js @@ -1,24 +1,13 @@ 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;