diff --git a/test/unit/components/__snapshots__/sprite-selector-item.test.jsx.snap b/test/unit/components/__snapshots__/sprite-selector-item.test.jsx.snap index 39146df349974556185db47203ad60931acb5c74..d30617f9aa25d3bcec9972f271d2cf7d76aeaf7d 100644 --- a/test/unit/components/__snapshots__/sprite-selector-item.test.jsx.snap +++ b/test/unit/components/__snapshots__/sprite-selector-item.test.jsx.snap @@ -2,23 +2,14 @@ exports[`SpriteSelectorItemComponent matches snapshot when selected 1`] = ` <div - className="ponies undefined" + className="react-contextmenu-wrapper ponies undefined" onClick={[Function]} - style={ - Object { - "alignContent": undefined, - "alignItems": undefined, - "alignSelf": undefined, - "flexBasis": undefined, - "flexDirection": undefined, - "flexGrow": undefined, - "flexShrink": undefined, - "flexWrap": undefined, - "height": undefined, - "justifyContent": undefined, - "width": undefined, - } - } + onContextMenu={[Function]} + onMouseDown={[Function]} + onMouseOut={[Function]} + onMouseUp={[Function]} + onTouchEnd={[Function]} + onTouchStart={[Function]} > <div className="" @@ -39,5 +30,35 @@ exports[`SpriteSelectorItemComponent matches snapshot when selected 1`] = ` > Pony sprite </div> + <nav + className="react-contextmenu" + onContextMenu={[Function]} + onMouseLeave={[Function]} + role="menu" + style={ + Object { + "opacity": 0, + "pointerEvents": "none", + "position": "fixed", + } + } + tabIndex="-1" + > + <div + aria-disabled="false" + aria-orientation={null} + className="react-contextmenu-item" + onClick={[Function]} + onMouseLeave={[Function]} + onMouseMove={[Function]} + onTouchEnd={[Function]} + role="menuitem" + tabIndex="-1" + > + <span> + delete + </span> + </div> + </nav> </div> `; diff --git a/test/unit/components/sprite-selector-item.test.jsx b/test/unit/components/sprite-selector-item.test.jsx index 8059b7152f973f9090aee8c019c8d260f61f1bb6..757155459341d04caceba6098d0a3ab5c2d856c0 100644 --- a/test/unit/components/sprite-selector-item.test.jsx +++ b/test/unit/components/sprite-selector-item.test.jsx @@ -1,11 +1,11 @@ /* eslint-env jest */ import React from 'react'; // eslint-disable-line no-unused-vars -import {shallow} from 'enzyme'; +import {mountWithIntl, shallowWithIntl, componentWithIntl} from '../../helpers/intl-helpers'; // eslint-disable-next-line no-unused-vars import SpriteSelectorItemComponent from '../../../src/components/sprite-selector-item/sprite-selector-item'; import CostumeCanvas from '../../../src/components/costume-canvas/costume-canvas'; import CloseButton from '../../../src/components/close-button/close-button'; // eslint-disable-line no-unused-vars -import renderer from 'react-test-renderer'; +import {MenuItem} from '../../../src/components/context-menu/context-menu'; // eslint-disable-line no-unused-vars describe('SpriteSelectorItemComponent', () => { let className; @@ -36,36 +36,46 @@ describe('SpriteSelectorItemComponent', () => { }); test('matches snapshot when selected', () => { - const component = renderer.create(getComponent()); + const component = componentWithIntl(getComponent()); expect(component.toJSON()).toMatchSnapshot(); }); test('does not have a close box when not selected', () => { selected = false; - const componentShallowWrapper = shallow(getComponent()); - expect(componentShallowWrapper.find(CloseButton).exists()).toBe(false); + const wrapper = shallowWithIntl(getComponent()); + expect(wrapper.find(CloseButton).exists()).toBe(false); }); test('triggers callback when Box component is clicked', () => { - const componentShallowWrapper = shallow(getComponent()); - componentShallowWrapper.simulate('click'); + // Use `mount` here because of the way ContextMenuTrigger consumes onClick + const wrapper = mountWithIntl(getComponent()); + wrapper.simulate('click'); expect(onClick).toHaveBeenCalled(); }); test('triggers callback when CloseButton component is clicked', () => { - const componentShallowWrapper = shallow(getComponent()); - componentShallowWrapper.find(CloseButton).simulate('click'); + const wrapper = shallowWithIntl(getComponent()); + wrapper.find(CloseButton).simulate('click'); expect(onDeleteButtonClick).toHaveBeenCalled(); }); test('creates a CostumeCanvas when a costume url is defined', () => { - const componentShallowWrapper = shallow(getComponent()); - expect(componentShallowWrapper.find(CostumeCanvas).exists()).toBe(true); + const wrapper = shallowWithIntl(getComponent()); + expect(wrapper.find(CostumeCanvas).exists()).toBe(true); }); test('does not create a CostumeCanvas when a costume url is null', () => { costumeURL = null; - const componentShallowWrapper = shallow(getComponent()); - expect(componentShallowWrapper.find(CostumeCanvas).exists()).toBe(false); + const wrapper = shallowWithIntl(getComponent()); + expect(wrapper.find(CostumeCanvas).exists()).toBe(false); + }); + + test('it has a context menu with delete menu item and callback', () => { + const wrapper = mountWithIntl(getComponent()); + const contextMenu = wrapper.find('ContextMenu'); + expect(contextMenu.exists()).toBe(true); + + contextMenu.find('[children="delete"]').simulate('click'); + expect(onDeleteButtonClick).toHaveBeenCalled(); }); }); diff --git a/test/unit/containers/sprite-selector-item.test.jsx b/test/unit/containers/sprite-selector-item.test.jsx index d5a822996b6a4f6b4958271bd4fa0fb19094f822..1efd40cb7cc05a26f9521dee06ad3935225fd7e8 100644 --- a/test/unit/containers/sprite-selector-item.test.jsx +++ b/test/unit/containers/sprite-selector-item.test.jsx @@ -1,6 +1,6 @@ /* eslint-env jest */ import React from 'react'; // eslint-disable-line no-unused-vars -import {mount} from 'enzyme'; +import {mountWithIntl} from '../../helpers/intl-helpers'; import configureStore from 'redux-mock-store'; import {Provider} from 'react-redux'; // eslint-disable-line no-unused-vars @@ -43,7 +43,7 @@ describe('SpriteSelectorItem Container', () => { }); test('should confirm if the user really wants to delete the sprite', () => { - const wrapper = mount(getContainer()); + const wrapper = mountWithIntl(getContainer()); wrapper.find(CloseButton).simulate('click'); expect(global.confirm).toHaveBeenCalled(); expect(onDeleteButtonClick).toHaveBeenCalledWith(1337); @@ -51,7 +51,7 @@ describe('SpriteSelectorItem Container', () => { test('should not delete the sprite if the user cancels', () => { global.confirm = jest.fn(() => false); - const wrapper = mount(getContainer()); + const wrapper = mountWithIntl(getContainer()); wrapper.find(CloseButton).simulate('click'); expect(global.confirm).toHaveBeenCalled(); expect(onDeleteButtonClick).not.toHaveBeenCalled();