Skip to content

Commit 69c37a8

Browse files
committed
Add selected disabled dates tests
1 parent feebbc7 commit 69c37a8

File tree

1 file changed

+26
-2
lines changed
  • packages/components/src/calendar/test

1 file changed

+26
-2
lines changed

packages/components/src/calendar/test/index.tsx

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ describe( 'DateCalendar', () => {
141141
} );
142142

143143
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.
144145
render( <DateCalendar defaultSelected={ tomorrow } selected={ today } /> );
145146

146147
expect( getDateCell( today, { selected: true } ) ).toBeVisible();
@@ -150,20 +151,43 @@ describe( 'DateCalendar', () => {
150151
expect( todayButton ).toHaveAccessibleName( /selected/i );
151152
} );
152153

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 /> );
155156

156157
expect( screen.queryByRole( 'gridcell', { selected: true } ) ).not.toBeInTheDocument();
157158
expect( screen.queryByRole( 'button', { name: /selected/i } ) ).not.toBeInTheDocument();
158159
} );
159160

160161
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.
161163
render( <DateCalendar defaultSelected={ tomorrow } selected={ null } /> );
162164

163165
expect( screen.queryByRole( 'gridcell', { selected: true } ) ).not.toBeInTheDocument();
164166
expect( screen.queryByRole( 'button', { name: /selected/i } ) ).not.toBeInTheDocument();
165167
} );
166168

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( /selected/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( /selected/i );
188+
expect( tomorrowButton ).toBeDisabled();
189+
} );
190+
167191
describe.each( [
168192
[ 'Uncontrolled', UncontrolledDateCalendar ],
169193
[ 'Controlled', ControlledDateCalendar ],

0 commit comments

Comments
 (0)