File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed
packages/react/src/components/ModalWrapper Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff 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 >
You can’t perform that action at this time.
0 commit comments