2017-03-07 18:49:22 +08:00
|
|
|
import React from 'react';
|
|
|
|
import { mount } from 'enzyme';
|
2018-12-18 10:36:51 +08:00
|
|
|
import moment from 'moment';
|
2018-06-22 21:05:13 +08:00
|
|
|
import DatePicker from '..';
|
2018-01-13 19:11:53 +08:00
|
|
|
|
|
|
|
const { RangePicker } = DatePicker;
|
2017-03-07 18:49:22 +08:00
|
|
|
|
|
|
|
describe('DatePicker with showTime', () => {
|
|
|
|
it('should trigger onChange when select value', () => {
|
|
|
|
const onChangeFn = jest.fn();
|
|
|
|
const onOpenChangeFn = jest.fn();
|
|
|
|
const wrapper = mount(
|
2018-12-07 16:17:45 +08:00
|
|
|
<DatePicker showTime open onChange={onChangeFn} onOpenChange={onOpenChangeFn} />,
|
2017-03-07 18:49:22 +08:00
|
|
|
);
|
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
const calendarWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
);
|
|
|
|
calendarWrapper
|
|
|
|
.find('.ant-calendar-date')
|
|
|
|
.at(0)
|
|
|
|
.simulate('click');
|
2017-03-07 18:49:22 +08:00
|
|
|
expect(onChangeFn).toHaveBeenCalled();
|
|
|
|
expect(onOpenChangeFn).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should trigger onOk when press ok button', () => {
|
|
|
|
const onOkFn = jest.fn();
|
|
|
|
const onOpenChangeFn = jest.fn();
|
|
|
|
const onChangeFn = jest.fn();
|
|
|
|
|
|
|
|
const wrapper = mount(
|
2018-12-07 16:17:45 +08:00
|
|
|
<DatePicker
|
|
|
|
showTime
|
|
|
|
open
|
|
|
|
onChange={onChangeFn}
|
|
|
|
onOk={onOkFn}
|
|
|
|
onOpenChange={onOpenChangeFn}
|
2018-12-18 10:36:51 +08:00
|
|
|
defaultValue={moment()}
|
2018-12-07 16:17:45 +08:00
|
|
|
/>,
|
2017-03-07 18:49:22 +08:00
|
|
|
);
|
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
const calendarWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
);
|
2017-03-07 18:49:22 +08:00
|
|
|
calendarWrapper.find('.ant-calendar-ok-btn').simulate('click');
|
|
|
|
expect(onOkFn).toHaveBeenCalled();
|
|
|
|
expect(onOpenChangeFn).toHaveBeenCalledWith(false);
|
|
|
|
expect(onChangeFn).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should trigger onChange when click Now link', () => {
|
|
|
|
const onOpenChangeFn = jest.fn();
|
|
|
|
const onChangeFn = jest.fn();
|
|
|
|
|
|
|
|
const wrapper = mount(
|
2018-12-07 16:17:45 +08:00
|
|
|
<DatePicker showTime open onChange={onChangeFn} onOpenChange={onOpenChangeFn} />,
|
2017-03-07 18:49:22 +08:00
|
|
|
);
|
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
const calendarWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
|
|
|
);
|
2017-03-07 18:49:22 +08:00
|
|
|
calendarWrapper.find('.ant-calendar-today-btn').simulate('click');
|
|
|
|
expect(onOpenChangeFn).toHaveBeenCalledWith(false);
|
|
|
|
expect(onChangeFn).toHaveBeenCalled();
|
|
|
|
});
|
2017-05-02 16:24:29 +08:00
|
|
|
|
|
|
|
it('should have correct className when use12Hours is true', () => {
|
2018-12-07 16:17:45 +08:00
|
|
|
const wrapper = mount(<DatePicker showTime={{ use12Hours: true }} open />);
|
|
|
|
const calendarWrapper = mount(
|
|
|
|
wrapper
|
|
|
|
.find('Trigger')
|
|
|
|
.instance()
|
|
|
|
.getComponent(),
|
2017-05-02 16:24:29 +08:00
|
|
|
);
|
|
|
|
expect(calendarWrapper.find('.ant-calendar-time-picker-column-4').length).toBe(0);
|
2018-12-07 16:17:45 +08:00
|
|
|
calendarWrapper
|
|
|
|
.find('.ant-calendar-time-picker-btn')
|
|
|
|
.at(0)
|
|
|
|
.simulate('click');
|
2017-09-20 16:26:18 +08:00
|
|
|
expect(calendarWrapper.find('.ant-calendar-time-picker-column-4').hostNodes().length).toBe(1);
|
2017-05-02 16:24:29 +08:00
|
|
|
});
|
2017-03-07 18:49:22 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('RangePicker with showTime', () => {
|
|
|
|
it('should trigger onChange when select value', () => {
|
|
|
|
const onChangeFn = jest.fn();
|
|
|
|
const onOpenChangeFn = jest.fn();
|
|
|
|
const wrapper = mount(
|
2018-12-07 16:17:45 +08:00
|
|
|
<RangePicker showTime open onChange={onChangeFn} onOpenChange={onOpenChangeFn} />,
|
2017-03-07 18:49:22 +08:00
|
|
|
);
|
|
|
|
|
2019-01-03 11:52:31 +08:00
|
|
|
function findNode(selector) {
|
|
|
|
return wrapper.find('Trigger').find(selector);
|
|
|
|
}
|
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
2019-01-03 11:52:31 +08:00
|
|
|
findNode('.ant-calendar-time-picker-btn').hasClass('ant-calendar-time-picker-btn-disabled'),
|
2018-12-07 16:17:45 +08:00
|
|
|
).toBe(true);
|
2019-01-03 11:52:31 +08:00
|
|
|
expect(findNode('.ant-calendar-ok-btn').hasClass('ant-calendar-ok-btn-disabled')).toBe(true);
|
|
|
|
findNode('.ant-calendar-date')
|
2018-12-07 16:17:45 +08:00
|
|
|
.at(10)
|
|
|
|
.simulate('click');
|
2019-01-03 11:52:31 +08:00
|
|
|
findNode('.ant-calendar-date')
|
2018-12-07 16:17:45 +08:00
|
|
|
.at(11)
|
|
|
|
.simulate('click');
|
2019-01-03 11:52:31 +08:00
|
|
|
|
2018-12-07 16:17:45 +08:00
|
|
|
expect(
|
2019-01-03 11:52:31 +08:00
|
|
|
findNode('.ant-calendar-time-picker-btn').hasClass('ant-calendar-time-picker-btn-disabled'),
|
2018-12-07 16:17:45 +08:00
|
|
|
).toBe(false);
|
2019-01-03 11:52:31 +08:00
|
|
|
expect(findNode('.ant-calendar-ok-btn').hasClass('ant-calendar-ok-btn-disabled')).toBe(false);
|
2017-03-07 18:49:22 +08:00
|
|
|
expect(onChangeFn).toHaveBeenCalled();
|
|
|
|
expect(onOpenChangeFn).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
2019-01-03 11:52:31 +08:00
|
|
|
it('should trigger onOk when press ok button', () => {
|
2017-03-07 18:49:22 +08:00
|
|
|
const onOkFn = jest.fn();
|
|
|
|
const onChangeFn = jest.fn();
|
|
|
|
const onOpenChangeFn = jest.fn();
|
|
|
|
const wrapper = mount(
|
2018-11-28 15:00:03 +08:00
|
|
|
<RangePicker
|
|
|
|
showTime
|
|
|
|
open
|
|
|
|
onOk={onOkFn}
|
|
|
|
onChange={onChangeFn}
|
|
|
|
onOpenChange={onOpenChangeFn}
|
2018-12-07 16:17:45 +08:00
|
|
|
/>,
|
2017-03-07 18:49:22 +08:00
|
|
|
);
|
|
|
|
|
2019-01-03 11:52:31 +08:00
|
|
|
function findNode(selector) {
|
|
|
|
return wrapper.find('Trigger').find(selector);
|
|
|
|
}
|
|
|
|
|
|
|
|
findNode('.ant-calendar-date')
|
2018-12-07 16:17:45 +08:00
|
|
|
.at(10)
|
|
|
|
.simulate('click');
|
2019-01-03 11:52:31 +08:00
|
|
|
findNode('.ant-calendar-date')
|
2018-12-07 16:17:45 +08:00
|
|
|
.at(11)
|
|
|
|
.simulate('click');
|
2017-03-07 18:49:22 +08:00
|
|
|
onChangeFn.mockClear();
|
2019-01-03 11:52:31 +08:00
|
|
|
findNode('.ant-calendar-ok-btn').simulate('click');
|
2017-03-07 18:49:22 +08:00
|
|
|
expect(onOkFn).toHaveBeenCalled();
|
|
|
|
expect(onOpenChangeFn).toHaveBeenCalledWith(false);
|
|
|
|
expect(onChangeFn).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|