@@ -2466,6 +2466,95 @@ describe("DatePicker", () => {
24662466 expect ( instance ! . state . preSelection ?. getMonth ( ) ) . toBe ( 1 ) ; // February (0-indexed)
24672467 expect ( instance ! . state . preSelection ?. getDate ( ) ) . toBe ( 10 ) ;
24682468 } ) ;
2469+ it ( "should update calendar view when typing a partial date (year only)" , ( ) => {
2470+ let instance : DatePicker | null = null ;
2471+
2472+ render (
2473+ < DatePicker
2474+ ref = { ( node ) => {
2475+ instance = node ;
2476+ } }
2477+ selected = { newDate ( "2024-06-15" ) }
2478+ onChange = { jest . fn ( ) }
2479+ dateFormat = "MM/dd/yyyy"
2480+ open
2481+ /> ,
2482+ ) ;
2483+ expect ( instance ) . toBeTruthy ( ) ;
2484+
2485+ // Verify initial calendar shows June 2024
2486+ expect ( instance ! . state . preSelection ?. getFullYear ( ) ) . toBe ( 2024 ) ;
2487+ expect ( instance ! . state . preSelection ?. getMonth ( ) ) . toBe ( 5 ) ; // June
2488+
2489+ // Type a partial date - just a year (use 2000 which won't match as a month)
2490+ fireEvent . change ( instance ! . input ! , {
2491+ target : {
2492+ value : "2000" ,
2493+ } ,
2494+ } ) ;
2495+
2496+ // Calendar should navigate to 2000 with the same month (June) from the selected date
2497+ expect ( instance ! . state . preSelection ?. getFullYear ( ) ) . toBe ( 2000 ) ;
2498+ expect ( instance ! . state . preSelection ?. getMonth ( ) ) . toBe ( 5 ) ; // June preserved from refDate
2499+ } ) ;
2500+ it ( "should update calendar view when typing a partial date (month and year)" , ( ) => {
2501+ let instance : DatePicker | null = null ;
2502+
2503+ render (
2504+ < DatePicker
2505+ ref = { ( node ) => {
2506+ instance = node ;
2507+ } }
2508+ selected = { newDate ( "2024-06-15" ) }
2509+ onChange = { jest . fn ( ) }
2510+ dateFormat = "MM/dd/yyyy"
2511+ open
2512+ /> ,
2513+ ) ;
2514+ expect ( instance ) . toBeTruthy ( ) ;
2515+
2516+ // Type a partial date - month and year
2517+ fireEvent . change ( instance ! . input ! , {
2518+ target : {
2519+ value : "03/2014" ,
2520+ } ,
2521+ } ) ;
2522+
2523+ // Calendar should navigate to March 2014
2524+ expect ( instance ! . state . preSelection ?. getFullYear ( ) ) . toBe ( 2014 ) ;
2525+ expect ( instance ! . state . preSelection ?. getMonth ( ) ) . toBe ( 2 ) ; // March (0-indexed)
2526+ } ) ;
2527+ it ( "should not update calendar view when typing text without a valid year" , ( ) => {
2528+ let instance : DatePicker | null = null ;
2529+
2530+ render (
2531+ < DatePicker
2532+ ref = { ( node ) => {
2533+ instance = node ;
2534+ } }
2535+ selected = { newDate ( "2024-06-15" ) }
2536+ onChange = { jest . fn ( ) }
2537+ dateFormat = "MM/dd/yyyy"
2538+ open
2539+ /> ,
2540+ ) ;
2541+ expect ( instance ) . toBeTruthy ( ) ;
2542+
2543+ // Verify initial calendar shows 2024
2544+ expect ( instance ! . state . preSelection ?. getFullYear ( ) ) . toBe ( 2024 ) ;
2545+ expect ( instance ! . state . preSelection ?. getMonth ( ) ) . toBe ( 5 ) ; // June (0-indexed)
2546+
2547+ // Type text without a valid 4-digit year
2548+ fireEvent . change ( instance ! . input ! , {
2549+ target : {
2550+ value : "03/" ,
2551+ } ,
2552+ } ) ;
2553+
2554+ // Calendar should remain on the original date since no valid year was found
2555+ expect ( instance ! . state . preSelection ?. getFullYear ( ) ) . toBe ( 2024 ) ;
2556+ expect ( instance ! . state . preSelection ?. getMonth ( ) ) . toBe ( 5 ) ; // June (0-indexed)
2557+ } ) ;
24692558 it ( "should correctly update the input when the value prop changes" , ( ) => {
24702559 let instance : DatePicker | null = null ;
24712560 const { rerender } = render (
0 commit comments