@@ -107,6 +107,47 @@ describe("YearPicker", () => {
107107 expect ( year ) . toBe ( getYear ( date ) . toString ( ) ) ;
108108 } ) ;
109109
110+ it ( "should has selected class applied for all the selectedDates when selectsMultiple is set" , ( ) => {
111+ const selectedDates = [ new Date ( "2025-01-01" ) , new Date ( "2026-01-01" ) ] ;
112+ const { container } = render (
113+ < Year
114+ selectsMultiple
115+ selectedDates = { selectedDates }
116+ date = { selectedDates [ 0 ] }
117+ onYearMouseEnter = { ( ) => { } }
118+ onYearMouseLeave = { ( ) => { } }
119+ /> ,
120+ ) ;
121+ const yearElements = Array . from (
122+ container . querySelectorAll ( ".react-datepicker__year-text--selected" ) ,
123+ ) ;
124+
125+ expect ( yearElements . length ) . toBe ( selectedDates . length ) ;
126+
127+ const isSelectedDatesHighlighted = yearElements . every ( ( yearElement ) => {
128+ const yearValue = yearElement ?. textContent ;
129+ return selectedDates . some (
130+ ( selectedDate ) => getYear ( selectedDate ) . toString ( ) === yearValue ,
131+ ) ;
132+ } ) ;
133+ expect ( isSelectedDatesHighlighted ) . toBe ( true ) ;
134+ } ) ;
135+
136+ it ( "should not has selected class where there is no selectedDates when selectsMultiple is set" , ( ) => {
137+ const { container } = render (
138+ < Year
139+ selectsMultiple
140+ date = { new Date ( ) }
141+ onYearMouseEnter = { ( ) => { } }
142+ onYearMouseLeave = { ( ) => { } }
143+ /> ,
144+ ) ;
145+ const yearElements = Array . from (
146+ container . querySelectorAll ( ".react-datepicker__year-text--selected" ) ,
147+ ) ;
148+ expect ( yearElements . length ) . toBe ( 0 ) ;
149+ } ) ;
150+
110151 it ( "should have current year class when element of array equal of current year" , ( ) => {
111152 const date = new Date ( ) ;
112153 const { container } = render (
0 commit comments