Skip to content

Commit

Permalink
test(modal-wrapper): increase coverage (#18156)
Browse files Browse the repository at this point in the history
Co-authored-by: Gururaj J <89023023+Gururajj77@users.noreply.github.com>
  • Loading branch information
ariellalgilmore and Gururajj77 authored Dec 3, 2024
1 parent bd4f604 commit cdf16cd
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions packages/react/src/components/ModalWrapper/ModalWrapper-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,24 @@ describe('ModalWrapper', () => {
expect(screen.getByTestId('modal-2')).not.toHaveClass('is-visible');
});

it('should call onKeyDown with escape', async () => {
const onKeyDown = jest.fn();
render(
<ModalWrapper
buttonTriggerText="Launch modal"
modalHeading="Modal heading"
modalLabel="Label"
data-testid="modal-2"
onKeyDown={onKeyDown}>
<p>Modal content here</p>
</ModalWrapper>
);

await userEvent.tab();
await userEvent.keyboard('{Escape}');
expect(onKeyDown).toHaveBeenCalledTimes(1);
});

it('should set open state to false when close button is clicked', async () => {
render(
<ModalWrapper
Expand Down Expand Up @@ -149,6 +167,7 @@ describe('ModalWrapper', () => {
modalHeading="Modal heading"
modalLabel="Label"
handleSubmit={handleSubmit}
shouldCloseAfterSubmit
open
data-testid="modal-5">
<p>Modal content here</p>
Expand Down

0 comments on commit cdf16cd

Please sign in to comment.