Skip to content

Commit

Permalink
Use getByRole
Browse files Browse the repository at this point in the history
  • Loading branch information
noisysocks committed May 4, 2022
1 parent 63cb7ce commit d5f0fac
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions packages/components/src/date-time/test/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe( 'DatePicker', () => {
render( <DatePicker currentDate="2022-05-02T11:00:00" /> );

expect(
screen.getByLabelText( 'Monday, May 2, 2022' ).classList
screen.getByRole( 'button', { name: 'Monday, May 2, 2022' } )
.classList
).toContain( 'CalendarDay__selected' );

// Expect React deprecation warning due to outdated 'react-dates' package.
Expand All @@ -28,9 +29,9 @@ describe( 'DatePicker', () => {
render( <DatePicker /> );

const todayDescription = moment().format( 'dddd, MMM D, YYYY' );
expect( screen.getByLabelText( todayDescription ).classList ).toContain(
'CalendarDay__selected'
);
expect(
screen.getByRole( 'button', { name: todayDescription } ).classList
).toContain( 'CalendarDay__selected' );
} );

it( 'should call onChange when a day is selected', async () => {
Expand All @@ -45,7 +46,9 @@ describe( 'DatePicker', () => {
/>
);

await user.click( screen.getByLabelText( 'Friday, May 20, 2022' ) );
await user.click(
screen.getByRole( 'button', { name: 'Friday, May 20, 2022' } )
);

expect( onChange ).toHaveBeenCalledWith( '2022-05-20T11:00:00' );
} );
Expand All @@ -65,14 +68,18 @@ describe( 'DatePicker', () => {
);

await user.click(
screen.getByLabelText( 'Move forward to switch to the next month.' )
screen.getByRole( 'button', {
name: 'Move forward to switch to the next month.',
} )
);

expect( onMonthPreviewed ).toHaveBeenCalledWith(
expect.stringMatching( /^2022-06/ )
);

await user.click( screen.getByLabelText( 'Monday, June 20, 2022' ) );
await user.click(
screen.getByRole( 'button', { name: 'Monday, June 20, 2022' } )
);

expect( onChange ).toHaveBeenCalledWith( '2022-06-20T11:00:00' );
} );
Expand Down Expand Up @@ -111,7 +118,9 @@ describe( 'DatePicker', () => {
/>
);

await user.click( screen.getByLabelText( 'Friday, May 20, 2022' ) );
await user.click(
screen.getByRole( 'button', { name: 'Friday, May 20, 2022' } )
);

expect( onChange ).not.toHaveBeenCalledWith( '2022-05-20T11:00:00' );
} );
Expand Down

0 comments on commit d5f0fac

Please sign in to comment.