|
| 1 | +import React from 'react'; |
| 2 | +import { mount } from 'enzyme'; |
| 3 | + |
| 4 | +import ContextMenu from '../src/ContextMenu'; |
| 5 | +import ContextMenuTrigger from '../src/ContextMenuTrigger'; |
| 6 | + |
| 7 | +describe('ContextMenuTrigger tests', () => { |
| 8 | + function baseSetup(options = {}) { |
| 9 | + const ID = 'CORRECT_ID'; |
| 10 | + const component = mount(<> |
| 11 | + <ContextMenu id={ID} /> |
| 12 | + <ContextMenuTrigger id={ID} {...options} /> |
| 13 | + </>); |
| 14 | + |
| 15 | + const wrapper = () => component.find('.react-contextmenu-wrapper'); |
| 16 | + const contextMenu = () => component.find('.react-contextmenu'); |
| 17 | + return { component, contextMenu, wrapper }; |
| 18 | + } |
| 19 | + |
| 20 | + describe('without triggerOnLeftClick', () => { |
| 21 | + const setup = baseSetup; |
| 22 | + test('shows a ContextMenu when right clicking', () => { |
| 23 | + const { contextMenu, wrapper } = setup(); |
| 24 | + wrapper().simulate('contextmenu', { button: 2, buttons: 2 }); |
| 25 | + expect(contextMenu().hasClass('react-contextmenu--visible')).toBe(true); |
| 26 | + }); |
| 27 | + |
| 28 | + test('shows a ContextMenu when ctrl + left clicking', () => { |
| 29 | + const { contextMenu, wrapper } = setup(); |
| 30 | + wrapper().simulate('contextmenu', { button: 0, buttons: 1 }); |
| 31 | + expect(contextMenu().hasClass('react-contextmenu--visible')).toBe(true); |
| 32 | + }); |
| 33 | + |
| 34 | + test('does not show a ContextMenu when left clicking without a modifier', () => { |
| 35 | + const { contextMenu, wrapper } = setup(); |
| 36 | + wrapper().simulate('click', { button: 0, buttons: 1 }); |
| 37 | + expect(contextMenu().hasClass('react-contextmenu--visible')).toBe(false); |
| 38 | + }); |
| 39 | + }); |
| 40 | + |
| 41 | + describe('with triggerOnLeftClick', () => { |
| 42 | + function setup() { |
| 43 | + return baseSetup({ triggerOnLeftClick: true }); |
| 44 | + } |
| 45 | + |
| 46 | + test('shows a ContextMenu when right clicking', () => { |
| 47 | + const { contextMenu, wrapper } = setup(); |
| 48 | + wrapper().simulate('contextmenu', { button: 2, buttons: 2 }); |
| 49 | + expect(contextMenu().hasClass('react-contextmenu--visible')).toBe(true); |
| 50 | + }); |
| 51 | + |
| 52 | + test('shows a ContextMenu when ctrl + left clicking', () => { |
| 53 | + const { contextMenu, wrapper } = setup(); |
| 54 | + wrapper().simulate('contextmenu', { button: 0, buttons: 1 }); |
| 55 | + expect(contextMenu().hasClass('react-contextmenu--visible')).toBe(true); |
| 56 | + }); |
| 57 | + |
| 58 | + test('shows a ContextMenu when left clicking without a modifier', () => { |
| 59 | + const { contextMenu, wrapper } = setup(); |
| 60 | + wrapper().simulate('click', { button: 0, buttons: 1 }); |
| 61 | + expect(contextMenu().hasClass('react-contextmenu--visible')).toBe(true); |
| 62 | + }); |
| 63 | + }); |
| 64 | +}); |
| 65 | + |
0 commit comments