fix(Calendar): allow default date to be maxDate when enable allowSameDay (#10976)

This commit is contained in:
neverland 2022-08-27 11:29:30 +08:00 committed by GitHub
parent 35f81fb208
commit 8d15fa4fdf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -149,7 +149,7 @@ export default defineComponent({
const start = limitDateRange(
defaultDate[0] || now,
minDate,
getPrevDay(maxDate)
allowSameDay ? maxDate : getPrevDay(maxDate)
);
const end = limitDateRange(
defaultDate[1] || now,

View File

@ -270,3 +270,41 @@ test('should emit over-range when exceeded max range', async () => {
expect(onOverRange).toHaveBeenCalledTimes(1);
});
test('should allow default date to be minDate when using allowSameDay prop', () => {
const minDate = new Date(1800, 0, 1);
const maxDate = new Date(1800, 0, 29);
const wrapper = mount(Calendar, {
props: {
type: 'range',
poppable: false,
minDate,
maxDate,
defaultDate: [minDate, minDate],
lazyRender: false,
allowSameDay: true,
},
});
wrapper.find('.van-calendar__confirm').trigger('click');
expect(wrapper.emitted<[Date]>('confirm')![0][0]).toEqual([minDate, minDate]);
});
test('should allow default date to be maxDate when using allowSameDay prop', () => {
const minDate = new Date(1800, 0, 1);
const maxDate = new Date(1800, 0, 29);
const wrapper = mount(Calendar, {
props: {
type: 'range',
poppable: false,
minDate,
maxDate,
defaultDate: [maxDate, maxDate],
lazyRender: false,
allowSameDay: true,
},
});
wrapper.find('.van-calendar__confirm').trigger('click');
expect(wrapper.emitted<[Date]>('confirm')![0][0]).toEqual([maxDate, maxDate]);
});