From b73656cb0d226c8fadbd0f1843dfa8b7333829aa Mon Sep 17 00:00:00 2001 From: zcj <18137693952@163.com> Date: Fri, 28 Oct 2022 22:17:46 +0800 Subject: [PATCH] =?UTF-8?q?fix(date-picker-pro):=20=E4=BF=AE=E5=A4=8D=20ra?= =?UTF-8?q?nge-date-picker-pro=20v-model=20=E6=B5=8B=E8=AF=95=E7=94=A8?= =?UTF-8?q?=E4=BE=8B=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../__tests__/range-date-picker-pro.spec.tsx | 32 ++++++++++++------- .../devui/date-picker-pro/__tests__/utils.ts | 4 +-- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/packages/devui-vue/devui/date-picker-pro/__tests__/range-date-picker-pro.spec.tsx b/packages/devui-vue/devui/date-picker-pro/__tests__/range-date-picker-pro.spec.tsx index 5f76e73bba..292a087477 100644 --- a/packages/devui-vue/devui/date-picker-pro/__tests__/range-date-picker-pro.spec.tsx +++ b/packages/devui-vue/devui/date-picker-pro/__tests__/range-date-picker-pro.spec.tsx @@ -126,9 +126,16 @@ describe('range-date-picker-pro test', () => { }); const container = wrapper.find(baseClass); - datePickerProValue.value[0] = new Date(); + + const date = new Date(); + datePickerProValue.value[0] = date; const time = 5 * 24 * 3600 * 1000; - datePickerProValue.value[1] = new Date().getDate() > 20 ? new Date() : new Date(new Date().getTime() + time); + + const todayIndex = getDateIndex(date); + // todayIndex 大于 20 赋值当前日期 否则加五天 对应下方getSelectedIndex逻辑 + datePickerProValue.value[1] = todayIndex > 20 ? new Date() : new Date(new Date().getTime() + time); + const selectIndex = getSelectedIndex(todayIndex, 5); + await nextTick(); const inputs = container.findAll('input'); await inputs[0].trigger('focus'); @@ -138,13 +145,11 @@ describe('range-date-picker-pro test', () => { expect(pickerPanel).toBeTruthy(); const tableMonthItems = pickerPanel?.querySelectorAll(tableMonthClass); - const date = new Date(); - const todayIndx = getDateIndex(date); - const selectIndex = getSelectedIndex(todayIndx, 5); + // 虚拟列表 当前面板呈现月为虚拟列表的第二个tableMonthItem const monthContentContainer = tableMonthItems?.[1].querySelector(datePickerNs.e('table-month-content')); const Items = monthContentContainer?.getElementsByTagName('td'); - expect(Items?.[todayIndx].classList).toContain(noDotDatePickerNs.e('table-date-start')); + expect(Items?.[todayIndex].classList).toContain(noDotDatePickerNs.e('table-date-start')); await inputs[1].trigger('focus'); await nextTick(); @@ -170,7 +175,8 @@ describe('range-date-picker-pro test', () => { onToggleChange={onToggleChange} onConfirmEvent={onConfirmEvent} onFocus={onFocus} - onBlur={onBlur}> + onBlur={onBlur} + > ); }, }); @@ -277,13 +283,15 @@ describe('range-date-picker-pro test', () => { color="primary" onClick={() => { setDate(-30); - }}> + }} + > 一个月前 ), - }}> + }} + > ); }, }); @@ -334,7 +342,8 @@ describe('range-date-picker-pro test', () => { ), - }}> + }} + > ); }, }); @@ -379,7 +388,8 @@ describe('range-date-picker-pro test', () => { + limitDateRange={limitDateRange.value} + > ); }, }); diff --git a/packages/devui-vue/devui/date-picker-pro/__tests__/utils.ts b/packages/devui-vue/devui/date-picker-pro/__tests__/utils.ts index 017f5e685c..2f4ba9fedf 100644 --- a/packages/devui-vue/devui/date-picker-pro/__tests__/utils.ts +++ b/packages/devui-vue/devui/date-picker-pro/__tests__/utils.ts @@ -6,9 +6,9 @@ export const getDateIndex = (date: Date): number => { }; export const getSelectedIndex = (todayIndex: number, intervalDay = 1): number => { - return todayIndex > 20 ? todayIndex - 1 : todayIndex + intervalDay; + return todayIndex > 20 ? todayIndex : todayIndex + intervalDay; }; export const getSelectedDate = (todayIndex: number, date: Date, intervalDay = 1): string => { - return todayIndex > 20 ? dayjs(date).subtract(1, 'day').format(DATE_FORMAT) : dayjs(date).add(intervalDay, 'day').format(DATE_FORMAT); + return todayIndex > 20 ? dayjs(date).format(DATE_FORMAT) : dayjs(date).add(intervalDay, 'day').format(DATE_FORMAT); };