From 9fc3b4208d6515e5f72edc23ffa0e14aecd5f842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Wed, 3 Jul 2024 11:22:41 +0800 Subject: [PATCH] test: update snapshot --- .../calendar-picker-view.tsx | 24 ++++++++++++------- .../calendar-picker-view.test.tsx.snap | 21 ---------------- .../tests/calendar-picker-view.test.tsx | 19 ++++++++++++--- .../calendar-picker/demos/demo1.tsx | 7 ++++-- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/src/components/calendar-picker-view/calendar-picker-view.tsx b/src/components/calendar-picker-view/calendar-picker-view.tsx index 660c1b98eb..83a38591e1 100644 --- a/src/components/calendar-picker-view/calendar-picker-view.tsx +++ b/src/components/calendar-picker-view/calendar-picker-view.tsx @@ -179,6 +179,20 @@ export const CalendarPickerView = forwardRef< const yearMonth = `${year}-${month}` + // 获取需要预先填充的空格,如果是 7 天则不需要填充 + const presetEmptyCellCount = + props.weekStartsOn === 'Monday' + ? monthIterator.date(1).isoWeekday() - 1 + : monthIterator.date(1).isoWeekday() + const presetEmptyCells = + presetEmptyCellCount == 7 + ? null + : Array(presetEmptyCellCount) + .fill(null) + .map((_, index) => ( +
+ )) + cells.push(
@@ -191,15 +205,7 @@ export const CalendarPickerView = forwardRef<
{/* 空格填充 */} - {Array( - props.weekStartsOn === 'Monday' - ? monthIterator.date(1).isoWeekday() - 1 - : monthIterator.date(1).isoWeekday() - ) - .fill(null) - .map((_, index) => ( -
- ))} + {presetEmptyCells} {/* 遍历每月 */} {Array(monthIterator.daysInMonth()) .fill(null) diff --git a/src/components/calendar-picker-view/tests/__snapshots__/calendar-picker-view.test.tsx.snap b/src/components/calendar-picker-view/tests/__snapshots__/calendar-picker-view.test.tsx.snap index cf673eba6e..45afafee4c 100644 --- a/src/components/calendar-picker-view/tests/__snapshots__/calendar-picker-view.test.tsx.snap +++ b/src/components/calendar-picker-view/tests/__snapshots__/calendar-picker-view.test.tsx.snap @@ -6456,27 +6456,6 @@ exports[`Calendar jump to a day 2`] = `
-
-
-
-
-
-
-
diff --git a/src/components/calendar-picker-view/tests/calendar-picker-view.test.tsx b/src/components/calendar-picker-view/tests/calendar-picker-view.test.tsx index 43eecb0f87..37d826643b 100644 --- a/src/components/calendar-picker-view/tests/calendar-picker-view.test.tsx +++ b/src/components/calendar-picker-view/tests/calendar-picker-view.test.tsx @@ -1,8 +1,8 @@ -import React, { useRef } from 'react' -import { render, testA11y, fireEvent } from 'testing' -import CalendarPickerView, { CalendarPickerViewRef } from '..' import dayjs from 'dayjs' import MockDate from 'mockdate' +import React, { useRef } from 'react' +import { fireEvent, render, testA11y } from 'testing' +import CalendarPickerView, { CalendarPickerViewRef } from '..' const classPrefix = `adm-calendar-picker-view` @@ -160,4 +160,17 @@ describe('Calendar', () => { ) expect(document.getElementsByClassName('custom-cell').length).toBe(31) }) + + test('not fill empty cells if unnecessary', () => { + const { container } = render( + + ) + + expect( + container.querySelectorAll('.adm-calendar-picker-view-cell') + ).toHaveLength(30) + }) }) diff --git a/src/components/calendar-picker/demos/demo1.tsx b/src/components/calendar-picker/demos/demo1.tsx index 82284fdaaa..c11184b48f 100644 --- a/src/components/calendar-picker/demos/demo1.tsx +++ b/src/components/calendar-picker/demos/demo1.tsx @@ -1,6 +1,6 @@ +import { CalendarPicker, List } from 'antd-mobile' import dayjs from 'dayjs' import React, { useState } from 'react' -import { CalendarPicker, List } from 'antd-mobile' const defaultRange: [Date, Date] = [ dayjs().toDate(), @@ -16,7 +16,8 @@ export default () => { const [visible2, setVisible2] = useState(false) const [visible3, setVisible3] = useState(false) - const singleDate: Date = new Date('2023-06-03') + // const singleDate: Date = new Date('2023-06-03') + const singleDate: Date = new Date('2024-09-01') return ( @@ -32,6 +33,8 @@ export default () => { defaultValue={singleDate} onClose={() => setVisible1(false)} onMaskClick={() => setVisible1(false)} + min={new Date('2024-09-01')} + max={new Date('2024-09-30')} />