From ed1871fe284702b99306d81bec97f914a6fa75bc Mon Sep 17 00:00:00 2001 From: BeADre Date: Mon, 25 Jan 2021 19:44:00 +0800 Subject: [PATCH] fix(date-picker): modify the judgment logic of startDate and endDate (#1322) --- .../date-picker/__tests__/date-picker.spec.ts | 75 +++++++++++++++++++ .../src/date-picker-com/basic-date-table.vue | 15 +++- .../src/date-picker-com/basic-month-table.vue | 16 +++- 3 files changed, 100 insertions(+), 6 deletions(-) diff --git a/packages/date-picker/__tests__/date-picker.spec.ts b/packages/date-picker/__tests__/date-picker.spec.ts index f510bf9667..d0018468cd 100644 --- a/packages/date-picker/__tests__/date-picker.spec.ts +++ b/packages/date-picker/__tests__/date-picker.spec.ts @@ -475,6 +475,43 @@ describe('DateRangePicker', () => { expect(vm.value[0].getTime() < vm.value[1].getTime()).toBeTruthy() }) + it('range, start-date and end-date', async () => { + _mount(``, () => ({ value: '' })) + + const table = document.querySelector('.el-date-table') + const availableTds = (table as HTMLTableElement).querySelectorAll('td.available'); + + (availableTds[0] as HTMLElement).click() + await nextTick(); + (availableTds[1] as HTMLElement).click() + await nextTick() + + expect(availableTds[0].classList.contains('in-range')).toBeTruthy() + expect(availableTds[0].classList.contains('start-date')).toBeTruthy() + expect(availableTds[1].classList.contains('in-range')).toBeTruthy() + expect(availableTds[1].classList.contains('end-date')).toBeTruthy(); + + (availableTds[1] as HTMLElement).click() + await nextTick(); + (availableTds[0] as HTMLElement).click() + await nextTick() + + expect(availableTds[0].classList.contains('in-range')).toBeTruthy() + expect(availableTds[0].classList.contains('start-date')).toBeTruthy() + expect(availableTds[1].classList.contains('in-range')).toBeTruthy() + expect(availableTds[1].classList.contains('end-date')).toBeTruthy() + + const startDate = document.querySelectorAll('.start-date') + const endDate = document.querySelectorAll('.end-date') + const inRangeDate = document.querySelectorAll('.in-range') + expect(startDate.length).toBe(1) + expect(endDate.length).toBe(1) + expect(inRangeDate.length).toBe(2) + }) + it('unlink:true', async () => { const wrapper = _mount(` { expect(vm.value[0].getTime() < vm.value[1].getTime()).toBeTruthy() }) + it('range, start-date and end-date', async () => { + _mount(``, () => ({ value: '' })) + + const table = document.querySelector('.el-month-table') + const tds = (table as HTMLTableElement).querySelectorAll('td'); + + (tds[0] as HTMLElement).click() + await nextTick(); + (tds[1] as HTMLElement).click() + await nextTick() + + expect(tds[0].classList.contains('in-range')).toBeTruthy() + expect(tds[0].classList.contains('start-date')).toBeTruthy() + expect(tds[1].classList.contains('in-range')).toBeTruthy() + expect(tds[1].classList.contains('end-date')).toBeTruthy(); + + (tds[1] as HTMLElement).click() + await nextTick(); + (tds[0] as HTMLElement).click() + await nextTick() + + expect(tds[0].classList.contains('in-range')).toBeTruthy() + expect(tds[0].classList.contains('start-date')).toBeTruthy() + expect(tds[1].classList.contains('in-range')).toBeTruthy() + expect(tds[1].classList.contains('end-date')).toBeTruthy() + + const startDate = document.querySelectorAll('.start-date') + const endDate = document.querySelectorAll('.end-date') + const inRangeDate = document.querySelectorAll('.in-range') + expect(startDate.length).toBe(1) + expect(endDate.length).toBe(1) + expect(inRangeDate.length).toBe(2) + }) + + it('type:monthrange unlink:true', async () => { const wrapper = _mount(`