Skip to content

Commit 4e75254

Browse files
committed
feat: update test
1 parent 555a775 commit 4e75254

File tree

2 files changed

+75
-1
lines changed

2 files changed

+75
-1
lines changed

tests/range.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,4 +2120,32 @@ describe('Picker.Range', () => {
21202120
openPicker(container, 1);
21212121
expect(container.querySelectorAll('.rc-picker-input')[0]).toHaveClass('rc-picker-input-active');
21222122
});
2123+
2124+
it('should not update preview value in input when showPreviewValue is false', () => {
2125+
const { container } = render(
2126+
<DayRangePicker
2127+
minDate={dayjs('2024')}
2128+
open
2129+
mode={['year', 'year']}
2130+
showTime
2131+
showPreviewValue={false}
2132+
needConfirm
2133+
value={[dayjs('2024-01-01'), dayjs('2025-01-01')]}
2134+
/>,
2135+
);
2136+
2137+
// 找到第一个输入框并保存初始值
2138+
const inputStart = container.querySelectorAll<HTMLInputElement>('.rc-picker-input input')[0];
2139+
const initialValueStart = inputStart.value;
2140+
2141+
// 打开第一个面板并 hover 一个新值(例如 2028 年)
2142+
const targetCell = document.querySelector('[title="2028"]') as HTMLElement;
2143+
expect(targetCell).toBeTruthy(); // 确保存在
2144+
2145+
// 2. 模拟鼠标移入(hover)
2146+
fireEvent.mouseEnter(targetCell);
2147+
2148+
// 确保值未更新(仍为原值)
2149+
expect(inputStart.value).toBe(initialValueStart);
2150+
});
21232151
});

tests/time.spec.tsx

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { fireEvent, render } from '@testing-library/react';
22
import { resetWarned } from '@rc-component/util/lib/warning';
33
import React from 'react';
4-
import { DayPicker, getDay, openPicker, selectCell, findCell } from './util/commonUtil';
4+
import dayjs from 'dayjs';
5+
import { DayPicker, getDay, openPicker, selectCell } from './util/commonUtil';
56

67
describe('Picker.Time', () => {
78
beforeEach(() => {
@@ -68,4 +69,49 @@ describe('Picker.Time', () => {
6869
fireEvent.mouseEnter(getColCell(4, 1));
6970
expect(container.querySelector('input')).toHaveValue('1990-09-03 12:00:00.000 PM');
7071
});
72+
73+
it('hover should not update preview value in input when showPreviewValue is false', async () => {
74+
const { container } = render(
75+
<DayPicker
76+
showTime={{
77+
showMillisecond: true,
78+
use12Hours: true,
79+
}}
80+
showPreviewValue={false}
81+
defaultValue={dayjs('1990-09-03 01:02:03')}
82+
/>,
83+
);
84+
openPicker(container);
85+
86+
const getColCell = (colIndex: number, cellIndex: number) => {
87+
const column = document.querySelectorAll('.rc-picker-time-panel-column')[colIndex];
88+
const cell = column.querySelectorAll('.rc-picker-time-panel-cell-inner')[cellIndex];
89+
90+
return cell;
91+
};
92+
93+
// Hour
94+
fireEvent.mouseEnter(getColCell(0, 3));
95+
expect(container.querySelector('input')).toHaveValue('1990-09-03 01:02:03.000 AM');
96+
97+
// Let test for mouse leave
98+
fireEvent.mouseLeave(getColCell(0, 3));
99+
expect(container.querySelector('input')).toHaveValue('1990-09-03 01:02:03.000 AM');
100+
101+
// Minute
102+
fireEvent.mouseEnter(getColCell(1, 2));
103+
expect(container.querySelector('input')).toHaveValue('1990-09-03 01:02:03.000 AM');
104+
105+
// Second
106+
fireEvent.mouseEnter(getColCell(2, 1));
107+
expect(container.querySelector('input')).toHaveValue('1990-09-03 01:02:03.000 AM');
108+
109+
// Millisecond
110+
fireEvent.mouseEnter(getColCell(3, 1));
111+
expect(container.querySelector('input')).toHaveValue('1990-09-03 01:02:03.000 AM');
112+
113+
// Meridiem
114+
fireEvent.mouseEnter(getColCell(4, 1));
115+
expect(container.querySelector('input')).toHaveValue('1990-09-03 01:02:03.000 AM');
116+
});
71117
});

0 commit comments

Comments
 (0)