@@ -141,6 +141,7 @@ describe( 'DateCalendar', () => {
141
141
} ) ;
142
142
143
143
it ( 'should select an initial date in controlled mode via the `selected` prop' , ( ) => {
144
+ // Note: the `defaultSelected` prop is ignored when the `selected` prop is set.
144
145
render ( < DateCalendar defaultSelected = { tomorrow } selected = { today } /> ) ;
145
146
146
147
expect ( getDateCell ( today , { selected : true } ) ) . toBeVisible ( ) ;
@@ -150,20 +151,43 @@ describe( 'DateCalendar', () => {
150
151
expect ( todayButton ) . toHaveAccessibleName ( / s e l e c t e d / i ) ;
151
152
} ) ;
152
153
153
- it ( 'should have no date selected in uncontrolled mode when the `selected` prop is set to `undefined`' , ( ) => {
154
- render ( < DateCalendar selected = { undefined } /> ) ;
154
+ it ( 'should have no date selected in uncontrolled mode when the `selected` and `defaultSelected` props are set to `undefined`' , ( ) => {
155
+ render ( < DateCalendar /> ) ;
155
156
156
157
expect ( screen . queryByRole ( 'gridcell' , { selected : true } ) ) . not . toBeInTheDocument ( ) ;
157
158
expect ( screen . queryByRole ( 'button' , { name : / s e l e c t e d / i } ) ) . not . toBeInTheDocument ( ) ;
158
159
} ) ;
159
160
160
161
it ( 'should have no date selected in controlled mode when the `selected` prop is set to `null`' , ( ) => {
162
+ // Note: the `defaultSelected` prop is ignored when the `selected` prop is set.
161
163
render ( < DateCalendar defaultSelected = { tomorrow } selected = { null } /> ) ;
162
164
163
165
expect ( screen . queryByRole ( 'gridcell' , { selected : true } ) ) . not . toBeInTheDocument ( ) ;
164
166
expect ( screen . queryByRole ( 'button' , { name : / s e l e c t e d / i } ) ) . not . toBeInTheDocument ( ) ;
165
167
} ) ;
166
168
169
+ it ( 'should select a date in uncontrolled mode via the `defaultSelected` prop even if the date is disabled`' , ( ) => {
170
+ render ( < DateCalendar defaultSelected = { tomorrow } disabled = { tomorrow } /> ) ;
171
+
172
+ expect ( getDateCell ( tomorrow , { selected : true } ) ) . toBeVisible ( ) ;
173
+
174
+ const tomorrowButton = getDateButton ( tomorrow ) ;
175
+ expect ( tomorrowButton ) . toBeVisible ( ) ;
176
+ expect ( tomorrowButton ) . toHaveAccessibleName ( / s e l e c t e d / i ) ;
177
+ expect ( tomorrowButton ) . toBeDisabled ( ) ;
178
+ } ) ;
179
+
180
+ it ( 'should select a date in controlled mode via the `selected` prop even if the date is disabled`' , ( ) => {
181
+ render ( < DateCalendar selected = { tomorrow } disabled = { tomorrow } /> ) ;
182
+
183
+ expect ( getDateCell ( tomorrow , { selected : true } ) ) . toBeVisible ( ) ;
184
+
185
+ const tomorrowButton = getDateButton ( tomorrow ) ;
186
+ expect ( tomorrowButton ) . toBeVisible ( ) ;
187
+ expect ( tomorrowButton ) . toHaveAccessibleName ( / s e l e c t e d / i ) ;
188
+ expect ( tomorrowButton ) . toBeDisabled ( ) ;
189
+ } ) ;
190
+
167
191
describe . each ( [
168
192
[ 'Uncontrolled' , UncontrolledDateCalendar ] ,
169
193
[ 'Controlled' , ControlledDateCalendar ] ,
0 commit comments