Skip to content

Commit 0b081c6

Browse files
test: Add coverage for parseDateForNavigation when no year is found
Add test case to verify calendar view remains unchanged when typing partial date input without a valid 4-digit year. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent b335197 commit 0b081c6

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/test/datepicker_test.test.tsx

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2522,6 +2522,37 @@ describe("DatePicker", () => {
25222522
expect(instance!.state.preSelection?.getFullYear()).toBe(2014);
25232523
expect(instance!.state.preSelection?.getMonth()).toBe(2); // March (0-indexed)
25242524
});
2525+
it("should not update calendar view when typing text without a valid year", () => {
2526+
let instance: DatePicker | null = null;
2527+
2528+
render(
2529+
<DatePicker
2530+
ref={(node) => {
2531+
instance = node;
2532+
}}
2533+
selected={newDate("2024-06-15")}
2534+
onChange={jest.fn()}
2535+
dateFormat="MM/dd/yyyy"
2536+
open
2537+
/>,
2538+
);
2539+
expect(instance).toBeTruthy();
2540+
2541+
// Verify initial calendar shows 2024
2542+
expect(instance!.state.preSelection?.getFullYear()).toBe(2024);
2543+
expect(instance!.state.preSelection?.getMonth()).toBe(5); // June (0-indexed)
2544+
2545+
// Type text without a valid 4-digit year
2546+
fireEvent.change(instance!.input!, {
2547+
target: {
2548+
value: "03/",
2549+
},
2550+
});
2551+
2552+
// Calendar should remain on the original date since no valid year was found
2553+
expect(instance!.state.preSelection?.getFullYear()).toBe(2024);
2554+
expect(instance!.state.preSelection?.getMonth()).toBe(5); // June (0-indexed)
2555+
});
25252556
it("should correctly update the input when the value prop changes", () => {
25262557
let instance: DatePicker | null = null;
25272558
const { rerender } = render(

0 commit comments

Comments
 (0)