@@ -13,15 +13,40 @@ describe('TwoMonthPicker', () => {
13
13
value : moment ( ) ,
14
14
} ;
15
15
16
- it ( 'should render TwoMonthPicker component' , ( ) => {
17
- render ( < TwoMonthPicker { ...mockProps } /> ) ;
18
- const currentMonth = moment ( ) . format ( 'MMM' ) ;
19
- const prevMonth = moment ( ) . subtract ( 1 , 'month' ) . format ( 'MMM' ) ;
20
- const currentYear = moment ( ) . format ( 'YYYY' ) ;
21
- expect ( screen . getByText ( prevMonth ) ) . toBeInTheDocument ( ) ;
22
- expect ( screen . getByText ( currentMonth ) ) . toBeInTheDocument ( ) ;
23
- expect ( screen . getByText ( currentYear ) ) . toBeInTheDocument ( ) ;
16
+ describe ( 'should render TwoMonthPicker component' , ( ) => {
17
+ it ( 'should render TwoMonthPicker component with different years for December/January months' , ( ) => {
18
+ const january_10th_2025 = moment ( '2025-01-10' , 'YYYY-MM-DD' ) ;
19
+
20
+ render ( < TwoMonthPicker { ...mockProps } value = { january_10th_2025 } /> ) ;
21
+
22
+ const currentMonth = moment ( ) . month ( 0 ) . format ( 'MMM' ) ; // January
23
+ const prevMonth = moment ( ) . month ( 0 ) . subtract ( 1 , 'month' ) . format ( 'MMM' ) ; // December
24
+ const currentYear = moment ( ) . year ( 2025 ) . format ( 'YYYY' ) ; // 2025
25
+ const prevYear = moment ( ) . year ( 2024 ) . format ( 'YYYY' ) ; // 2024
26
+
27
+ expect ( screen . getByText ( currentMonth ) ) . toBeInTheDocument ( ) ;
28
+ expect ( screen . getByText ( prevMonth ) ) . toBeInTheDocument ( ) ;
29
+ expect ( screen . getByTestId ( 'first-month' ) ) . toHaveTextContent ( prevYear ) ;
30
+ expect ( screen . getByTestId ( 'second-month' ) ) . toHaveTextContent ( currentYear ) ;
31
+ } ) ;
32
+
33
+ it ( 'should render TwoMonthPicker component with same years for January/February months' , ( ) => {
34
+ const february_10th_2025 = moment ( '2025-02-10' , 'YYYY-MM-DD' ) ;
35
+
36
+ render ( < TwoMonthPicker { ...mockProps } value = { february_10th_2025 } /> ) ;
37
+
38
+ const currentMonth = moment ( ) . month ( 1 ) . format ( 'MMM' ) ; // February
39
+ const prevMonth = moment ( ) . month ( 1 ) . subtract ( 1 , 'month' ) . format ( 'MMM' ) ; // January
40
+ const currentYear = moment ( ) . year ( 2025 ) . format ( 'YYYY' ) ; // 2025
41
+ const prevYear = moment ( ) . year ( 2025 ) . format ( 'YYYY' ) ; // 2025
42
+
43
+ expect ( screen . getByText ( currentMonth ) ) . toBeInTheDocument ( ) ;
44
+ expect ( screen . getByText ( prevMonth ) ) . toBeInTheDocument ( ) ;
45
+ expect ( screen . getByTestId ( 'first-month' ) ) . toHaveTextContent ( prevYear ) ;
46
+ expect ( screen . getByTestId ( 'second-month' ) ) . toHaveTextContent ( currentYear ) ;
47
+ } ) ;
24
48
} ) ;
49
+
25
50
it ( 'should call onChange when a date is selected' , async ( ) => {
26
51
render ( < TwoMonthPicker { ...mockProps } /> ) ;
27
52
const prevMonthDate = moment ( ) . date ( 1 ) . subtract ( 1 , 'month' ) ;
0 commit comments