mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
fix(Calendar): should reset to default date when calling reset method (#7967)
This commit is contained in:
parent
c71b48ed9f
commit
c30740ecc5
@ -311,7 +311,7 @@ export default createComponent({
|
||||
});
|
||||
};
|
||||
|
||||
const reset = (date = getInitialDate(state.currentDate)) => {
|
||||
const reset = (date = getInitialDate()) => {
|
||||
state.currentDate = date;
|
||||
scrollIntoView();
|
||||
};
|
||||
@ -500,7 +500,9 @@ export default createComponent({
|
||||
);
|
||||
|
||||
watch(() => props.show, init);
|
||||
watch([() => props.type, () => props.minDate, () => props.maxDate], reset);
|
||||
watch([() => props.type, () => props.minDate, () => props.maxDate], () => {
|
||||
reset(getInitialDate(state.currentDate));
|
||||
});
|
||||
watch(
|
||||
() => props.defaultDate,
|
||||
(value) => {
|
||||
|
@ -196,31 +196,6 @@ test('default range date', async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('reset method', async () => {
|
||||
const wrapper = mount(Calendar, {
|
||||
props: {
|
||||
minDate,
|
||||
maxDate,
|
||||
type: 'range',
|
||||
poppable: false,
|
||||
defaultDate: [minDate, getNextDay(minDate)],
|
||||
},
|
||||
});
|
||||
|
||||
await later();
|
||||
|
||||
const days = wrapper.findAll('.van-calendar__day');
|
||||
days.at(15).trigger('click');
|
||||
days.at(18).trigger('click');
|
||||
|
||||
wrapper.vm.reset();
|
||||
|
||||
wrapper.find('.van-calendar__confirm').trigger('click');
|
||||
expect(formatRange(wrapper.emitted('confirm')[0][0])).toEqual(
|
||||
'2010/1/10-2010/1/11'
|
||||
);
|
||||
});
|
||||
|
||||
test('set show-confirm to false', async () => {
|
||||
const wrapper = mount(Calendar, {
|
||||
props: {
|
||||
|
50
src/calendar/test/index.spec.js
Normal file
50
src/calendar/test/index.spec.js
Normal file
@ -0,0 +1,50 @@
|
||||
import Calendar from '..';
|
||||
import { mount } from '../../../test';
|
||||
import { getNextDay, getPrevDay } from '../utils';
|
||||
import { minDate, maxDate } from './utils';
|
||||
|
||||
test('should reset to default date when calling reset method', async () => {
|
||||
const defaultDate = [minDate, getNextDay(minDate)];
|
||||
const wrapper = mount(Calendar, {
|
||||
props: {
|
||||
minDate,
|
||||
maxDate,
|
||||
type: 'range',
|
||||
poppable: false,
|
||||
lazyRender: false,
|
||||
defaultDate,
|
||||
},
|
||||
});
|
||||
|
||||
const days = wrapper.findAll('.van-calendar__day');
|
||||
await days[15].trigger('click');
|
||||
await days[18].trigger('click');
|
||||
|
||||
wrapper.vm.reset();
|
||||
|
||||
wrapper.find('.van-calendar__confirm').trigger('click');
|
||||
expect(wrapper.emitted('confirm')[0][0]).toEqual(defaultDate);
|
||||
});
|
||||
|
||||
test('should reset to specific date when calling reset method with date', async () => {
|
||||
const wrapper = mount(Calendar, {
|
||||
props: {
|
||||
minDate,
|
||||
maxDate,
|
||||
type: 'range',
|
||||
poppable: false,
|
||||
lazyRender: false,
|
||||
defaultDate: [minDate, getNextDay(minDate)],
|
||||
},
|
||||
});
|
||||
|
||||
const days = wrapper.findAll('.van-calendar__day');
|
||||
await days[15].trigger('click');
|
||||
await days[18].trigger('click');
|
||||
|
||||
const newDate = [getPrevDay(maxDate), maxDate];
|
||||
wrapper.vm.reset(newDate);
|
||||
|
||||
wrapper.find('.van-calendar__confirm').trigger('click');
|
||||
expect(wrapper.emitted('confirm')[0][0]).toEqual(newDate);
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user