-
Notifications
You must be signed in to change notification settings - Fork 9
/
AbstractIcon.spec.jsx
executable file
·54 lines (47 loc) · 1.72 KB
/
AbstractIcon.spec.jsx
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
import React from 'react';
import { shallow, mount } from 'enzyme';
import AbstractIcon from './Icon';
describe('AbstractIcon', () => {
it('renders', () => {
const wrapper = shallow(<AbstractIcon />);
expect(wrapper.find('div').length).toBeTruthy();
});
it('renders button when passed onclick', () => {
const wrapper = shallow(<AbstractIcon onClick={jest.fn()} />);
expect(wrapper.find('button').length).toBeTruthy();
});
it('onclick focuses and fires prop', () => {
const clickFunc = jest.fn();
const wrapper = mount(<AbstractIcon onClick={clickFunc} />);
wrapper.simulate('click');
expect(clickFunc).toHaveBeenCalled();
});
it('onDoubleClick if passed in as prop', () => {
const dblClck = jest.fn();
const wrapper = mount(<AbstractIcon onDoubleClick={dblClck} />);
wrapper.simulate('click');
expect(wrapper.state().doubleReady).toEqual(true);
wrapper.simulate('click');
expect(dblClck).toHaveBeenCalled();
});
it('onDoubleClick if touchend', () => {
const dblClck = jest.fn();
const wrapper = shallow(<AbstractIcon onDoubleClick={dblClck} />);
wrapper.simulate('touchend');
expect(dblClck).toHaveBeenCalled();
});
it('onContextMenu on works if passed in as prop', () => {
const mockEvent = {
preventDefault: jest.fn(),
stopPropagation: jest.fn(),
};
const onContextMenu = jest.fn();
const wrapper = mount(<AbstractIcon onClick={jest.fn()} />);
wrapper.simulate('contextmenu');
expect(onContextMenu).not.toHaveBeenCalled();
wrapper.setProps({ onContextMenu });
wrapper.simulate('contextmenu', mockEvent);
expect(onContextMenu).toHaveBeenCalled();
expect(mockEvent.preventDefault).toHaveBeenCalled();
});
});