mirror of
https://github.com/element-plus/element-plus.git
synced 2026-03-13 07:51:17 +08:00
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:
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user