feat(Calendar): auto selected to max range (#5992)

This commit is contained in:
neverland
2020-04-03 15:22:02 +08:00
committed by GitHub
parent 3f8928b02d
commit 64e77f3d2a
7 changed files with 82 additions and 41 deletions
+8 -20
View File
@@ -1,26 +1,14 @@
import Calendar from '..';
import { mount, later } from '../../../test';
import { getNextDay } from '../utils';
const now = new Date();
const minDate = new Date(2010, 0, 10);
const maxDate = new Date(2010, 0, 20);
function formatDate(date) {
if (date) {
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
}
return '';
}
function formatRange([start, end]) {
return `${formatDate(start)}-${formatDate(end)}`;
}
function formatMultiple(dates) {
return dates.map(formatDate).join(',');
}
import {
now,
minDate,
maxDate,
formatDate,
formatRange,
formatMultiple,
} from './utils';
test('select event when type is single', async () => {
const wrapper = mount(Calendar, {
+33 -7
View File
@@ -1,16 +1,39 @@
import Calendar from '..';
import { mount, later } from '../../../test';
import { minDate, maxDate, formatRange } from './utils';
const minDate = new Date(2010, 0, 10);
const maxDate = new Date(2010, 0, 20);
test('max-range prop', async () => {
test('max-range prop when showConfirm is false', async () => {
const wrapper = mount(Calendar, {
propsData: {
type: 'range',
minDate,
maxDate,
maxRange: 1,
maxRange: 3,
poppable: false,
showConfirm: false,
},
});
await later();
const days = wrapper.findAll('.van-calendar__day');
days.at(12).trigger('click');
days.at(18).trigger('click');
expect(formatRange(wrapper.emitted('select')[0][0])).toEqual('2010/1/13-');
expect(formatRange(wrapper.emitted('select')[1][0])).toEqual(
'2010/1/13-2010/1/19'
);
expect(wrapper.emitted('confirm')).toBeFalsy();
});
test('max-range prop when showConfirm is true', async () => {
const wrapper = mount(Calendar, {
propsData: {
type: 'range',
minDate,
maxDate,
maxRange: 3,
poppable: false,
},
});
@@ -18,10 +41,13 @@ test('max-range prop', async () => {
await later();
const days = wrapper.findAll('.van-calendar__day');
days.at(15).trigger('click');
days.at(12).trigger('click');
days.at(18).trigger('click');
wrapper.find('.van-calendar__confirm').trigger('click');
expect(formatRange(wrapper.emitted('select')[0][0])).toEqual('2010/1/13-');
expect(formatRange(wrapper.emitted('select')[1][0])).toEqual(
'2010/1/13-2010/1/15'
);
expect(wrapper.emitted('confirm')).toBeFalsy();
});
+19
View File
@@ -0,0 +1,19 @@
export const now = new Date();
export const minDate = new Date(2010, 0, 10);
export const maxDate = new Date(2010, 0, 20);
export function formatDate(date) {
if (date) {
return `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`;
}
return '';
}
export function formatRange([start, end]) {
return `${formatDate(start)}-${formatDate(end)}`;
}
export function formatMultiple(dates) {
return dates.map(formatDate).join(',');
}