diff --git a/src/components/calendar/Calendar.spec.js b/src/components/calendar/Calendar.spec.js index d1e1b325a..85470bb6d 100644 --- a/src/components/calendar/Calendar.spec.js +++ b/src/components/calendar/Calendar.spec.js @@ -23,7 +23,7 @@ describe('Calendar.vue', () => { expect(wrapper.find('.p-inputtext').exists()).toBe(true); let input = wrapper.find('.p-inputtext'); - + await input.trigger('focus'); expect(wrapper.find('.p-datepicker.p-component').exists()).toBe(true); @@ -42,4 +42,12 @@ describe('Calendar.vue', () => { await wrapper.vm.onDateSelect({currentTarget: {focus: () => {}}}, event); expect(onDateSelect).toHaveBeenCalled() }); -}); \ No newline at end of file + it('should calculate the correct view date when in range mode', async () => { + const dateOne = new Date(); + const dateTwo = new Date(); + dateTwo.setFullYear(dateOne.getFullYear(), dateOne.getMonth(), dateOne.getDate() + 1) + await wrapper.setProps({ selectionMode: 'range', showTime: true, modelValue: [dateOne, dateTwo] }); + + expect(wrapper.vm.viewDate).toEqual(dateTwo) + }); +}); diff --git a/src/components/calendar/Calendar.vue b/src/components/calendar/Calendar.vue index d9e6874b1..dc985ce3e 100755 --- a/src/components/calendar/Calendar.vue +++ b/src/components/calendar/Calendar.vue @@ -2288,13 +2288,16 @@ export default { viewDate() { let propValue = this.modelValue; if (propValue && Array.isArray(propValue)) { - propValue = propValue[0]; + if (this.isRangeSelection()) { + propValue = propValue[1] || propValue[0]; + } else if (this.isMultipleSelection()) { + propValue = propValue[propValue.length - 1]; + } } if (propValue && typeof propValue !== 'string') { return propValue; - } - else { + } else { let today = new Date(); if (this.maxDate && this.maxDate < today) { return this.maxDate;