Skip to content

Commit 566ac8c

Browse files
fix: resolve failing test assertions
Fixed 2 failing tests that were introduced by conditional expect fixes: 1. year_picker_test.test.tsx - "should call updateFocusOnPaginate": - Changed test to navigate from last year element to trigger pagination - Added yearItemNumber prop to ensure consistent year grid - Now properly tests the requestAnimationFrame call in updateFocusOnPaginate 2. timepicker_test.test.tsx - "should not call onChange when clicking disabled time": - Increased number of excluded times to ensure at least one is rendered - Added timeIntervals={60} for better disabled time visibility - Now reliably tests the disabled time click behavior Coverage improved: 98.78% → 98.81% statements All 1,203 tests passing ✓ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent d4617be commit 566ac8c

File tree

2 files changed

+32
-12
lines changed

2 files changed

+32
-12
lines changed

src/test/timepicker_test.test.tsx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,24 @@ describe("TimePicker", () => {
454454
describe("Coverage improvements for time.tsx", () => {
455455
it("should not call onChange when clicking disabled time", () => {
456456
const onChange = jest.fn();
457-
const disabledTime = newDate();
458-
disabledTime.setHours(14, 0);
457+
const selectedDate = newDate();
458+
selectedDate.setHours(10, 0, 0, 0);
459+
460+
// Create multiple disabled times to ensure at least one is rendered
461+
const disabledTimes = [];
462+
for (let hour = 14; hour <= 18; hour++) {
463+
const disabledTime = newDate();
464+
disabledTime.setHours(hour, 0, 0, 0);
465+
disabledTimes.push(disabledTime);
466+
}
459467

460468
const { container } = render(
461469
<DatePicker
462-
selected={newDate()}
470+
selected={selectedDate}
463471
onChange={onChange}
464472
showTimeSelect
465-
excludeTimes={[disabledTime]}
473+
excludeTimes={disabledTimes}
474+
timeIntervals={60}
466475
inline
467476
/>,
468477
);
@@ -471,6 +480,7 @@ describe("TimePicker", () => {
471480
".react-datepicker__time-list-item--disabled",
472481
);
473482

483+
// Verify disabled times are rendered
474484
expect(timeList.length).toBeGreaterThan(0);
475485
// Line 133: early return when clicking disabled time
476486
const disabledItem = timeList[0] as HTMLElement;

src/test/year_picker_test.test.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,20 +1183,30 @@ describe("YearPicker", () => {
11831183
const rafSpy = jest.spyOn(window, "requestAnimationFrame");
11841184

11851185
const { container } = render(
1186-
<DatePicker selected={newDate()} onChange={() => {}} showYearPicker />,
1186+
<DatePicker
1187+
selected={newDate()}
1188+
onChange={() => {}}
1189+
showYearPicker
1190+
yearItemNumber={12}
1191+
/>,
11871192
);
11881193

11891194
openDateInput(container);
11901195

1191-
const currentYear = container.querySelector(
1192-
".react-datepicker__year-text--keyboard-selected",
1193-
) as HTMLElement;
1196+
const yearElements = container.querySelectorAll(
1197+
".react-datepicker__year-text",
1198+
);
11941199

1195-
expect(currentYear).not.toBeNull();
1196-
// Navigate with keyboard - this should trigger updateFocusOnPaginate
1197-
fireEvent.keyDown(currentYear, getKey(KeyType.ArrowDown));
1200+
expect(yearElements.length).toBeGreaterThan(0);
1201+
// Get the last year element in the current view to trigger pagination
1202+
const lastYearElement = yearElements[
1203+
yearElements.length - 1
1204+
] as HTMLElement;
1205+
1206+
// Line 118: Navigate down from last year to trigger updateFocusOnPaginate
1207+
fireEvent.keyDown(lastYearElement, getKey(KeyType.ArrowDown));
11981208

1199-
// Line 118: updateFocusOnPaginate uses requestAnimationFrame
1209+
// updateFocusOnPaginate uses requestAnimationFrame
12001210
expect(rafSpy).toHaveBeenCalled();
12011211

12021212
rafSpy.mockRestore();

0 commit comments

Comments
 (0)