2019-01-12 03:33:27 +00:00
|
|
|
import { mount } from '@vue/test-utils';
|
|
|
|
import { asyncExpect } from '@/tests/utils';
|
|
|
|
import moment from 'moment';
|
|
|
|
import DatePicker from '../';
|
2020-07-29 07:34:19 +00:00
|
|
|
import { $$ } from './utils';
|
|
|
|
import { sleep } from '../../../tests/utils';
|
2018-06-09 05:14:14 +00:00
|
|
|
|
2019-01-12 03:33:27 +00:00
|
|
|
const { RangePicker } = DatePicker;
|
2018-06-09 05:14:14 +00:00
|
|
|
|
|
|
|
describe('DatePicker with showTime', () => {
|
2020-07-29 07:34:19 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
document.body.outerHTML = '';
|
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
it('should trigger onChange when select value', async () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const onChangeFn = jest.fn();
|
|
|
|
const onOpenChangeFn = jest.fn();
|
2020-07-29 07:34:19 +00:00
|
|
|
mount(
|
2019-01-12 03:33:27 +00:00
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return <DatePicker showTime open onChange={onChangeFn} onOpenChange={onOpenChangeFn} />;
|
|
|
|
},
|
2018-06-09 05:14:14 +00:00
|
|
|
},
|
2020-07-29 07:34:19 +00:00
|
|
|
{ sync: false, attachTo: 'body' },
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-06-09 05:14:14 +00:00
|
|
|
|
|
|
|
await asyncExpect(() => {
|
2020-07-29 07:34:19 +00:00
|
|
|
$$('.ant-calendar-date')[0].click();
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(onChangeFn).toHaveBeenCalled();
|
|
|
|
expect(onOpenChangeFn).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
|
|
|
|
it('should trigger onOk when press ok button', async () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const onOkFn = jest.fn();
|
|
|
|
const onOpenChangeFn = jest.fn();
|
|
|
|
const onChangeFn = jest.fn();
|
2020-07-29 07:34:19 +00:00
|
|
|
mount(
|
2019-01-12 03:33:27 +00:00
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<DatePicker
|
|
|
|
showTime
|
|
|
|
open
|
|
|
|
onChange={onChangeFn}
|
|
|
|
onOk={onOkFn}
|
|
|
|
onOpenChange={onOpenChangeFn}
|
|
|
|
defaultValue={moment()}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
2018-06-09 05:14:14 +00:00
|
|
|
},
|
2020-07-29 07:34:19 +00:00
|
|
|
{ sync: false, attachTo: 'body' },
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-06-09 05:14:14 +00:00
|
|
|
|
|
|
|
await asyncExpect(() => {
|
2020-07-29 07:34:19 +00:00
|
|
|
$$('.ant-calendar-ok-btn')[0].click();
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(onOkFn).toHaveBeenCalled();
|
|
|
|
expect(onOpenChangeFn).toHaveBeenCalledWith(false);
|
|
|
|
expect(onChangeFn).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
|
|
|
|
it('should trigger onChange when click Now link', async () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const onOpenChangeFn = jest.fn();
|
|
|
|
const onChangeFn = jest.fn();
|
2020-07-29 07:34:19 +00:00
|
|
|
mount(
|
2019-01-12 03:33:27 +00:00
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return <DatePicker showTime open onChange={onChangeFn} onOpenChange={onOpenChangeFn} />;
|
|
|
|
},
|
2018-06-09 05:14:14 +00:00
|
|
|
},
|
2020-07-29 07:34:19 +00:00
|
|
|
{ sync: false, attachTo: 'body' },
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-06-09 05:14:14 +00:00
|
|
|
|
|
|
|
await asyncExpect(() => {
|
2020-07-29 07:34:19 +00:00
|
|
|
$$('.ant-calendar-today-btn')[0].click();
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
await asyncExpect(() => {
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(onOpenChangeFn).toHaveBeenCalledWith(false);
|
|
|
|
expect(onChangeFn).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
|
|
|
|
it('should have correct className when use12Hours is true', async () => {
|
2020-07-29 07:34:19 +00:00
|
|
|
mount(
|
2018-06-09 05:14:14 +00:00
|
|
|
{
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return <DatePicker showTime={{ use12Hours: true }} open />;
|
2018-06-09 05:14:14 +00:00
|
|
|
},
|
|
|
|
},
|
2020-07-29 07:34:19 +00:00
|
|
|
{ sync: false, attachTo: 'body' },
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2020-07-29 07:34:19 +00:00
|
|
|
|
2018-06-09 05:14:14 +00:00
|
|
|
await asyncExpect(() => {
|
2020-07-29 07:34:19 +00:00
|
|
|
expect($$('.ant-calendar-time-picker-column-4').length).toBe(0);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2020-07-29 07:34:19 +00:00
|
|
|
$$('.ant-calendar-today')[0].click();
|
|
|
|
await sleep();
|
|
|
|
$$('.ant-calendar-time-picker-btn')[0].click();
|
2018-06-09 05:14:14 +00:00
|
|
|
await asyncExpect(() => {
|
2020-07-29 07:34:19 +00:00
|
|
|
expect($$('.ant-calendar-time-picker-column-4').length).toBe(1);
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
|
2019-07-30 11:51:49 +00:00
|
|
|
describe('RangePicker with showTime', () => {
|
2020-07-29 07:34:19 +00:00
|
|
|
beforeEach(() => {
|
|
|
|
document.body.outerHTML = '';
|
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
it('should trigger onChange when select value', async () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const onChangeFn = jest.fn();
|
|
|
|
const onOpenChangeFn = jest.fn();
|
2020-07-29 07:34:19 +00:00
|
|
|
mount(
|
2018-06-09 05:14:14 +00:00
|
|
|
{
|
2019-01-12 03:33:27 +00:00
|
|
|
render() {
|
|
|
|
return <RangePicker showTime open onChange={onChangeFn} onOpenChange={onOpenChangeFn} />;
|
2018-06-09 05:14:14 +00:00
|
|
|
},
|
2019-01-12 03:33:27 +00:00
|
|
|
},
|
|
|
|
{ sync: false },
|
|
|
|
);
|
2018-06-09 05:14:14 +00:00
|
|
|
|
|
|
|
await asyncExpect(() => {
|
2020-07-29 07:34:19 +00:00
|
|
|
expect(
|
|
|
|
$$('.ant-calendar-time-picker-btn')[0]
|
|
|
|
.getAttribute('class')
|
|
|
|
.split(' '),
|
|
|
|
).toContain('ant-calendar-time-picker-btn-disabled');
|
|
|
|
expect(
|
|
|
|
$$('.ant-calendar-ok-btn')[0]
|
|
|
|
.getAttribute('class')
|
|
|
|
.split(' '),
|
|
|
|
).toContain('ant-calendar-ok-btn-disabled');
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
2020-07-29 07:34:19 +00:00
|
|
|
$$('.ant-calendar-date')[10].click();
|
|
|
|
$$('.ant-calendar-date')[11].click();
|
2018-06-09 05:14:14 +00:00
|
|
|
await asyncExpect(() => {
|
2020-07-29 07:34:19 +00:00
|
|
|
expect(
|
|
|
|
$$('.ant-calendar-time-picker-btn')[0]
|
|
|
|
.getAttribute('class')
|
|
|
|
.split(' '),
|
|
|
|
).not.toContain('ant-calendar-time-picker-btn-disabled');
|
|
|
|
expect(
|
|
|
|
$$('.ant-calendar-ok-btn')[0]
|
|
|
|
.getAttribute('class')
|
|
|
|
.split(' '),
|
|
|
|
).not.toContain('ant-calendar-ok-btn-disabled');
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
expect(onChangeFn).toHaveBeenCalled();
|
|
|
|
expect(onOpenChangeFn).not.toHaveBeenCalled();
|
|
|
|
});
|
2018-06-09 05:14:14 +00:00
|
|
|
|
|
|
|
it('hould trigger onOk when press ok button', async () => {
|
2019-01-12 03:33:27 +00:00
|
|
|
const onOkFn = jest.fn();
|
|
|
|
const onChangeFn = jest.fn();
|
|
|
|
const onOpenChangeFn = jest.fn();
|
2020-07-29 07:34:19 +00:00
|
|
|
mount(
|
2019-01-12 03:33:27 +00:00
|
|
|
{
|
|
|
|
render() {
|
|
|
|
return (
|
|
|
|
<RangePicker
|
|
|
|
showTime
|
|
|
|
open
|
|
|
|
onOk={onOkFn}
|
|
|
|
onChange={onChangeFn}
|
|
|
|
onOpenChange={onOpenChangeFn}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
},
|
2018-06-09 05:14:14 +00:00
|
|
|
},
|
2020-07-29 07:34:19 +00:00
|
|
|
{ sync: false, attachTo: 'body' },
|
2019-01-12 03:33:27 +00:00
|
|
|
);
|
2018-06-09 05:14:14 +00:00
|
|
|
await asyncExpect(() => {
|
2020-07-29 07:34:19 +00:00
|
|
|
$$('.ant-calendar-date')[10].click();
|
|
|
|
$$('.ant-calendar-date')[11].click();
|
2019-01-12 03:33:27 +00:00
|
|
|
});
|
|
|
|
onChangeFn.mockClear();
|
2020-07-29 07:34:19 +00:00
|
|
|
$$('.ant-calendar-ok-btn')[0].click();
|
2019-01-12 03:33:27 +00:00
|
|
|
expect(onOkFn).toHaveBeenCalled();
|
|
|
|
expect(onOpenChangeFn).toHaveBeenCalledWith(false);
|
|
|
|
expect(onChangeFn).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|