all repos — caroster @ 550370ebaa750b5433b92c35d407de6f7f363911

[Octree] Group carpool to your event https://caroster.io

start EventMenu
Hadrien Froger hadrien@octree.ch
Thu, 16 Jul 2020 13:06:43 +0100
commit

550370ebaa750b5433b92c35d407de6f7f363911

parent

98f53a5eab4bb9bf3b826b17508504e534c82a3f

D app/src/App.test.js

@@ -1,9 +0,0 @@

-import React from 'react'; -import {render} from '@testing-library/react'; -import App from './App'; - -test('renders learn react link', () => { - const {getByText} = render(<App />); - const linkElement = getByText(/learn react/i); - expect(linkElement).toBeInTheDocument(); -});
A app/src/containers/EventMenu/EventMenu.js

@@ -0,0 +1,37 @@

+import React from 'react'; +import Menu from '@material-ui/core/Menu'; +import MenuItem from '@material-ui/core/MenuItem'; + +const EventMenu = ({anchorEl, setAnchorEl, actions = []}) => { + return ( + <Menu + anchorEl={anchorEl} + anchorOrigin={{ + vertical: 'top', + horizontal: 'right', + }} + keepMounted + transformOrigin={{ + vertical: 'top', + horizontal: 'right', + }} + open={!!anchorEl} + onClose={() => setAnchorEl(null)} + > + {actions && + actions.map((action, idx) => ( + <MenuItem + onClick={() => { + action.onClick(); + setAnchorEl(null); + }} + key={idx} + id={action.id || `MenuItem${idx}`} + > + {action.label} + </MenuItem> + ))} + </Menu> + ); +}; +export default EventMenu;
A app/src/containers/EventMenu/EventMenu.test.js

@@ -0,0 +1,12 @@

+import React, {createRef} from 'react'; +import EventMenu from './EventMenu'; +import renderer from 'react-test-renderer'; + +describe('EventMenu', () => { + const EventMenuDOM = renderer.create( + <EventMenu anchorEl={() => <div></div>} /> + ); + it('should match snapshot without props', () => { + expect(EventMenuDOM.toJSON()).toMatchSnapshot(); + }); +});
M app/src/containers/EventMenu/index.jsapp/src/containers/EventMenu/index.js

@@ -1,38 +1,2 @@

-import React from 'react'; -import Menu from '@material-ui/core/Menu'; -import MenuItem from '@material-ui/core/MenuItem'; - -const EventMenu = ({anchorEl, setAnchorEl, actions = []}) => { - return ( - <Menu - anchorEl={anchorEl} - anchorOrigin={{ - vertical: 'top', - horizontal: 'right', - }} - keepMounted - transformOrigin={{ - vertical: 'top', - horizontal: 'right', - }} - open={!!anchorEl} - onClose={() => setAnchorEl(null)} - > - {actions && - actions.map((action, idx) => ( - <MenuItem - onClick={() => { - action.onClick(); - setAnchorEl(null); - }} - key={idx} - id={action.id || `MenuItem${idx}`} - > - {action.label} - </MenuItem> - ))} - </Menu> - ); -}; - +import EventMenu from './EventMenu'; export default EventMenu;
M app/src/setupTests.jsapp/src/setupTests.js

@@ -4,3 +4,20 @@ // expect(element).toHaveTextContent(/react/i)

// learn more: https://github.com/testing-library/jest-dom import '@testing-library/jest-dom/extend-expect'; import './i18n'; + +// FROM https://github.com/akiran/react-slick/blob/master/test-setup.js +window.matchMedia = + window.matchMedia || + function () { + return { + matches: false, + addListener: function () {}, + removeListener: function () {}, + }; + }; + +window.requestAnimationFrame = + window.requestAnimationFrame || + function (callback) { + setTimeout(callback, 0); + };