blob: 9262319dd2f5dbf7fbc069491c7206ce9143b03e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
import React from 'react';
import PopupMenuItem from '../../src/react/PopupMenuItem.js';
import PopupMenu from '../../src/react/PopupMenu.js';
import renderer from 'react-test-renderer';
import {mount} from 'enzyme';
describe('PopupMenuItem', () => {
test('check selected', () => {
const menuItem = renderer.create(<PopupMenuItem itemId='1' value='item 1' selected/>).toJSON();
expect(menuItem).toMatchSnapshot();
});
test('check disabled', () => {
const menuItem = renderer.create(<PopupMenuItem itemId='2' value='item 2' disabled/>).toJSON();
expect(menuItem).toMatchSnapshot();
});
test('check parent onclick invoked by child', () => {
const mockFunc = jest.fn();
const menu = mount(
<PopupMenu onMenuItemClick={mockFunc}>
<PopupMenuItem itemId='1' value='item 1'/>
</PopupMenu>
);
expect(menu.find('li')).toHaveLength(1);
menu.find('li').simulate('click');
expect(mockFunc).toHaveBeenCalled();
});
test('check custom onclick invoked by child', () => {
const mockParentFunc = jest.fn();
const mockChildFunc = jest.fn();
const menu = mount(
<PopupMenu onMenuItemClick={mockParentFunc}>
<PopupMenuItem itemId='1' value='item 1' onClick={mockChildFunc}/>
</PopupMenu>
);
expect(menu.find('li')).toHaveLength(1);
menu.find('li').simulate('click');
expect(mockChildFunc).toHaveBeenCalled();
expect(mockParentFunc).not.toHaveBeenCalled();
});
test('check no click handler if item is disabled', () => {
const mockFunc = jest.fn();
const menu = mount(
<PopupMenu onMenuItemClick={mockFunc}>
<PopupMenuItem itemId='1' value='item 1' disabled/>
</PopupMenu>
);
expect(menu.find('li')).toHaveLength(1);
menu.find('li').simulate('click');
expect(mockFunc).not.toHaveBeenCalled();
});
});
|