fix(components): [calendar] fix range cross year bug (#10574)

* fix(components): [calendar] (#5595)

fix(components): [calendar] fix  range cross year bug

closed #5595

* test(components): [calendar] add test

Co-authored-by: tolking <qw13131wang@gmail.com>
This commit is contained in:
Sun Yuu
2022-11-11 22:42:48 +08:00
committed by GitHub
parent ab8e484085
commit 531ffccda1
2 changed files with 22 additions and 1 deletions

View File

@@ -203,6 +203,27 @@ describe('Calendar.vue', () => {
expect(cell?.classList.contains('is-selected')).toBeTruthy()
})
it('range two years', async () => {
const wrapper = mount(() => (
<Calendar range={[new Date(2021, 11, 20), new Date(2022, 0, 10)]} />
))
const titleEl = wrapper.find('.el-calendar__title')
expect(/2021.*December/.test(titleEl.element.innerHTML)).toBeTruthy()
const dateTables = wrapper.element.querySelectorAll(
'.el-calendar-table.is-range'
)
expect(dateTables.length).toBe(2)
const rows = wrapper.element.querySelectorAll('.el-calendar-table__row')
expect(rows.length).toBe(4)
const cell = rows[rows.length - 1].firstElementChild as HTMLElement
cell.click()
await nextTick()
expect(/2022.*January/.test(titleEl.element.innerHTML)).toBeTruthy()
expect(cell?.classList.contains('is-selected')).toBeTruthy()
})
it('slots', async () => {
const wrapper = mount(() => (
<Calendar

View File

@@ -133,7 +133,7 @@ export const useCalendar = (
return [[firstDay, lastDay]]
}
// Two adjacent months
else if (firstMonth + 1 === lastMonth) {
else if ((firstMonth + 1) % 12 === lastMonth) {
return adjacentMonth(firstDay, lastDay)
}
// Three consecutive months (compatible: 2021-01-30 to 2021-02-28)