-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathPicker.test.tsx
63 lines (52 loc) · 2.23 KB
/
Picker.test.tsx
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
57
58
59
60
61
62
63
import * as React from 'react';
import { shallow, mount, ReactWrapper } from 'enzyme';
import Picker, { Props, State } from '../src/components/Picker';
describe('<Picker/>', () => {
const defaultProps = {
portal: false,
className: 'test-picker',
renderTrigger: () => <div className="test">test</div>,
renderContents: () => <div className="contents">contents</div>,
};
describe('show & hide', () => {
let mountComponent: ReactWrapper<Props, State>;
beforeEach(() => {
mountComponent = mount(<Picker {...defaultProps} />);
});
it('should trigger DOM click show backdrop & picker dialog', () => {
mountComponent.find('.picker__trigger').simulate('click');
expect(mountComponent.state('show')).toBeTruthy();
});
it('shoudl prop disabled click -> dilaog show not working', () => {
mountComponent = mount(<Picker {...defaultProps} disabled />);
mountComponent.find('.picker__trigger').simulate('click');
expect(mountComponent.state('show')).toBeFalsy();
});
it('shoudl prop disabled click -> dilaog show not working', () => {
mountComponent = mount(<Picker {...defaultProps} readOnly />);
mountComponent.find('.picker__trigger').simulate('click');
expect(mountComponent.state('show')).toBeFalsy();
});
it('should show state & backdrop click -> hide dialog', () => {
mountComponent.setState({
show: true,
});
mountComponent.find('Backdrop').simulate('click');
});
});
describe('position', () => {
let mountComponent: ReactWrapper<Props, State>;
it('should portal false setPosition correctly', () => {
mountComponent = mount(<Picker {...defaultProps} portal={false} />);
mountComponent.find('.picker__trigger').simulate('click');
expect(mountComponent.state().position.left).not.toEqual('');
expect(mountComponent.state().position.top).not.toEqual('');
});
it('should portal true position not set', () => {
mountComponent = mount(<Picker {...defaultProps} portal={true} />);
mountComponent.find('.picker__trigger').simulate('click');
expect(mountComponent.state().position.left).toEqual('');
expect(mountComponent.state().position.top).toEqual('');
});
});
});