Skip to content

Commit cdf16cd

Browse files
test(modal-wrapper): increase coverage (#18156)
Co-authored-by: Gururaj J <89023023+Gururajj77@users.noreply.github.com>
1 parent bd4f604 commit cdf16cd

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

packages/react/src/components/ModalWrapper/ModalWrapper-test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,24 @@ describe('ModalWrapper', () => {
102102
expect(screen.getByTestId('modal-2')).not.toHaveClass('is-visible');
103103
});
104104

105+
it('should call onKeyDown with escape', async () => {
106+
const onKeyDown = jest.fn();
107+
render(
108+
<ModalWrapper
109+
buttonTriggerText="Launch modal"
110+
modalHeading="Modal heading"
111+
modalLabel="Label"
112+
data-testid="modal-2"
113+
onKeyDown={onKeyDown}>
114+
<p>Modal content here</p>
115+
</ModalWrapper>
116+
);
117+
118+
await userEvent.tab();
119+
await userEvent.keyboard('{Escape}');
120+
expect(onKeyDown).toHaveBeenCalledTimes(1);
121+
});
122+
105123
it('should set open state to false when close button is clicked', async () => {
106124
render(
107125
<ModalWrapper
@@ -149,6 +167,7 @@ describe('ModalWrapper', () => {
149167
modalHeading="Modal heading"
150168
modalLabel="Label"
151169
handleSubmit={handleSubmit}
170+
shouldCloseAfterSubmit
152171
open
153172
data-testid="modal-5">
154173
<p>Modal content here</p>

0 commit comments

Comments
 (0)