|
1 | | -import { shallow } from 'enzyme'; |
2 | | -// import renderer from 'react-test-renderer'; |
| 1 | +import { shallow, mount } from 'enzyme'; |
| 2 | +import { PopoverVanilla } from '../index'; |
3 | 3 |
|
4 | | -import Popover from '../index'; |
| 4 | +const interactivePopover = { |
| 5 | + className: 'example', |
| 6 | + popOverHeader: 'This is a popover header text', |
| 7 | + trigger: <button id="popover-trigger">Click to Open</button>, |
| 8 | +}; |
5 | 9 |
|
6 | | -describe('<Popover />', () => { |
7 | | - let PopoverComponent = ''; |
| 10 | +describe('<Popover /> Rendering', () => { |
| 11 | + let PopoverComponent; |
8 | 12 | beforeEach(() => { |
9 | | - PopoverComponent = shallow(<Popover>Test</Popover>); |
| 13 | + PopoverComponent = shallow(<PopoverVanilla>Test</PopoverVanilla>); |
10 | 14 | }); |
11 | 15 |
|
12 | 16 | test('should render correctly', () => { |
13 | 17 | expect(PopoverComponent).toMatchSnapshot(); |
14 | 18 | }); |
15 | 19 | }); |
| 20 | + |
| 21 | +describe('Popover functional behavior', () => { |
| 22 | + let PopoverComponent; |
| 23 | + |
| 24 | + test('Should have Close Button By Default and can be closed', () => { |
| 25 | + PopoverComponent = mount( |
| 26 | + <PopoverVanilla {...interactivePopover} isVisible> |
| 27 | + Test |
| 28 | + </PopoverVanilla> |
| 29 | + ); |
| 30 | + expect(PopoverComponent.find('.popover__close').length).toEqual(1); |
| 31 | + PopoverComponent = mount( |
| 32 | + <PopoverVanilla {...interactivePopover} hidePopoverCloseBtn> |
| 33 | + Test |
| 34 | + </PopoverVanilla> |
| 35 | + ); |
| 36 | + expect(PopoverComponent.find('.popover__close').length).toEqual(0); |
| 37 | + }); |
| 38 | + |
| 39 | + test('Should open By Default when isVisible set to true', () => { |
| 40 | + PopoverComponent = mount( |
| 41 | + <PopoverVanilla {...interactivePopover} isVisible> |
| 42 | + Test |
| 43 | + </PopoverVanilla> |
| 44 | + ); |
| 45 | + expect(PopoverComponent.find('.popover__header').length).toEqual(1); |
| 46 | + }); |
| 47 | + |
| 48 | + test('Should open and close on Trigger and X button click', () => { |
| 49 | + PopoverComponent = mount( |
| 50 | + <div> |
| 51 | + <p className="test">Test Content</p> |
| 52 | + <PopoverVanilla {...interactivePopover}>Test</PopoverVanilla> |
| 53 | + </div> |
| 54 | + ); |
| 55 | + // Test Default Open through trigger |
| 56 | + PopoverComponent.find('#popover-trigger').simulate('click'); |
| 57 | + expect(PopoverComponent.find('.popover__header').length).toEqual(1); |
| 58 | + // Test Close Popover when clicking outside through trigger the popover |
| 59 | + // Test Close through X button |
| 60 | + PopoverComponent.find('.popover__close').simulate('click'); |
| 61 | + expect(PopoverComponent.find('.popover__header').length).toEqual(0); |
| 62 | + }); |
| 63 | +}); |
0 commit comments