@@ -63,4 +63,68 @@ describe('Component', () => {
6363 fireEvent . click ( await getByText ( container . parentElement as any as HTMLElement , 'Past Week' ) ) ;
6464 expect ( onQuickSelectChange ) . toHaveBeenCalledWith ( expect . objectContaining ( { id : 'Past Week' } ) ) ;
6565 } ) ;
66+
67+ it ( 'constrains time options when selected date matches minDate' , ( ) => {
68+ const minDate = new Date ( '2021-11-10T14:00:00' ) ;
69+ const value = new Date ( '2021-11-10T15:00:00' ) ;
70+ const { container } = render (
71+ < TestBaseProvider >
72+ < Calendar
73+ value = { value }
74+ minDate = { minDate }
75+ timeSelectStart
76+ overrides = { {
77+ TimeSelectContainer : { props : { 'data-testid' : 'time-select' } } ,
78+ } }
79+ />
80+ </ TestBaseProvider >
81+ ) ;
82+
83+ const timeSelect = queryByTestId ( container , 'time-select' ) ;
84+ expect ( timeSelect ) . not . toBeNull ( ) ;
85+
86+ const selectInput = timeSelect ! . querySelector ( '[data-baseweb="select"]' ) ;
87+ if ( selectInput ?. firstChild ) {
88+ fireEvent . click ( selectInput . firstChild as HTMLElement ) ;
89+ }
90+
91+ const listbox = container . parentElement ! . querySelector ( '[role="listbox"]' ) ;
92+ expect ( listbox ) . not . toBeNull ( ) ;
93+ const options = Array . from ( listbox ! . querySelectorAll ( '[role="option"]' ) ) ;
94+ const optionTexts = options . map ( ( o ) => o . textContent ) ;
95+ expect ( optionTexts ) . not . toContain ( '12:00 PM' ) ;
96+ expect ( optionTexts ) . toContain ( '3:00 PM' ) ;
97+ } ) ;
98+
99+ it ( 'does not constrain time when selected date differs from minDate' , ( ) => {
100+ const minDate = new Date ( '2021-11-10T14:00:00' ) ;
101+ const value = new Date ( '2021-11-11T10:00:00' ) ;
102+ const { container } = render (
103+ < TestBaseProvider >
104+ < Calendar
105+ value = { value }
106+ minDate = { minDate }
107+ timeSelectStart
108+ overrides = { {
109+ TimeSelectContainer : { props : { 'data-testid' : 'time-select' } } ,
110+ } }
111+ />
112+ </ TestBaseProvider >
113+ ) ;
114+
115+ const timeSelect = queryByTestId ( container , 'time-select' ) ;
116+ expect ( timeSelect ) . not . toBeNull ( ) ;
117+
118+ const selectInput = timeSelect ! . querySelector ( '[data-baseweb="select"]' ) ;
119+ if ( selectInput ?. firstChild ) {
120+ fireEvent . click ( selectInput . firstChild as HTMLElement ) ;
121+ }
122+
123+ const listbox = container . parentElement ! . querySelector ( '[role="listbox"]' ) ;
124+ expect ( listbox ) . not . toBeNull ( ) ;
125+ const options = Array . from ( listbox ! . querySelectorAll ( '[role="option"]' ) ) ;
126+ const optionTexts = options . map ( ( o ) => o . textContent ) ;
127+ expect ( optionTexts ) . toContain ( '12:00 AM' ) ;
128+ expect ( optionTexts ) . toContain ( '12:00 PM' ) ;
129+ } ) ;
66130} ) ;
0 commit comments