-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathRangePickerInput.test.tsx
51 lines (42 loc) · 1.78 KB
/
RangePickerInput.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
import * as React from 'react';
import * as sinon from 'sinon';
import { shallow, mount, ShallowWrapper, ReactWrapper, HTMLAttributes } from 'enzyme';
import RangePickerInput, { FieldType } from '../src/components/RangePickerInput';
describe('<RagePickerInput />', () => {
let shallowComponent: ShallowWrapper;
beforeEach(() => {
shallowComponent = shallow(<RangePickerInput />);
});
it('should render without crash', () => {
expect(shallowComponent).toBeTruthy();
expect(shallowComponent).toMatchSnapshot();
});
describe('event test', () => {
let onChange: sinon.SinonSpy;
let onClick: sinon.SinonSpy;
let mountComponent: ReactWrapper;
let startInput: ReactWrapper<HTMLAttributes>;
let endInput: ReactWrapper<HTMLAttributes>;
beforeEach(() => {
onChange = sinon.spy();
onClick = sinon.spy();
mountComponent = mount(<RangePickerInput onClick={onClick} onChange={onChange} />);
startInput = mountComponent.find('.range-picker-input__start .picker-input__text');
endInput = mountComponent.find('.range-picker-input__end .picker-input__text');
});
it('should onClick start & end operate separately', () => {
startInput.simulate('click');
expect(onClick.getCalls()[0].args[0]).toEqual(FieldType.START);
endInput.simulate('click');
expect(onClick.getCalls()[1].args[0]).toEqual(FieldType.END);
expect(onClick).toHaveProperty('callCount', 2);
});
it('should onChange start & end operate separately', () => {
startInput.simulate('change');
expect(onChange.getCalls()[0].args[0]).toEqual(FieldType.START);
endInput.simulate('change');
expect(onChange.getCalls()[1].args[0]).toEqual(FieldType.END);
expect(onChange).toHaveProperty('callCount', 2);
});
});
});