@@ -84,12 +84,12 @@ describe('Modal', () => {
84
84
expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ;
85
85
86
86
userEvent . click ( screen . getByRole ( 'button' , { name : 'Hello' } ) ) ;
87
- expect ( window . alert ) . toHaveBeenCalled ( ) ;
87
+ expect ( window . alert ) . toHaveBeenCalledWith ( "Hey look it's listening" ) ;
88
88
expect ( container . querySelector ( '.modalBackdrop' ) ) . toBeInTheDocument ( ) ;
89
89
expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
90
90
91
91
userEvent . click ( screen . getByRole ( 'button' , { name : 'close' } ) ) ;
92
- expect ( window . alert ) . toHaveBeenCalled ( ) ;
92
+ expect ( window . alert ) . toHaveBeenCalledWith ( "Hey look it's listening" ) ;
93
93
expect (
94
94
container . querySelector ( '.modalBackdrop' ) ,
95
95
) . not . toBeInTheDocument ( ) ;
@@ -141,12 +141,12 @@ describe('Modal', () => {
141
141
expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ;
142
142
143
143
userEvent . click ( screen . getAllByRole ( 'button' , { name : 'Hello' } ) [ 1 ] ) ;
144
- expect ( window . alert ) . toHaveBeenCalled ( ) ;
144
+ expect ( window . alert ) . toHaveBeenCalledWith ( "Hey look it's listening" ) ;
145
145
expect ( container . querySelector ( '.modalBackdrop' ) ) . toBeInTheDocument ( ) ;
146
146
expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
147
147
148
148
userEvent . click ( screen . getByRole ( 'button' , { name : 'close' } ) ) ;
149
- expect ( window . alert ) . toHaveBeenCalled ( ) ;
149
+ expect ( window . alert ) . toHaveBeenCalledWith ( "Hey look it's listening" ) ;
150
150
expect (
151
151
container . querySelector ( '.modalBackdrop' ) ,
152
152
) . not . toBeInTheDocument ( ) ;
@@ -172,7 +172,7 @@ describe('Modal', () => {
172
172
expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ;
173
173
174
174
userEvent . click ( screen . getByRole ( 'button' , { name : 'Hello' } ) ) ;
175
- expect ( window . alert ) . toHaveBeenCalled ( ) ;
175
+ expect ( window . alert ) . toHaveBeenCalledWith ( "Hey look it's listening" ) ;
176
176
expect ( container . querySelector ( '.modalBackdrop' ) ) . toBeInTheDocument ( ) ;
177
177
expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
178
178
@@ -205,7 +205,7 @@ describe('Modal', () => {
205
205
expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ;
206
206
207
207
userEvent . click ( screen . getByRole ( 'button' , { name : 'Hello' } ) ) ;
208
- expect ( window . alert ) . toHaveBeenCalled ( ) ;
208
+ expect ( window . alert ) . toHaveBeenCalledWith ( "Hey look it's listening" ) ;
209
209
expect ( container . querySelector ( '.modalBackdrop' ) ) . toBeInTheDocument ( ) ;
210
210
expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
211
211
@@ -239,7 +239,7 @@ describe('Modal', () => {
239
239
expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ;
240
240
241
241
userEvent . click ( screen . getByRole ( 'button' , { name : 'Hello' } ) ) ;
242
- expect ( window . alert ) . toHaveBeenCalled ( ) ;
242
+ expect ( window . alert ) . toHaveBeenCalledWith ( "Hey look it's listening" ) ;
243
243
expect ( container . querySelector ( '.modalBackdrop' ) ) . toBeInTheDocument ( ) ;
244
244
expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
245
245
@@ -294,7 +294,7 @@ describe('Modal', () => {
294
294
expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ;
295
295
296
296
userEvent . click ( screen . getByRole ( 'button' , { name : 'Hello' } ) ) ;
297
- expect ( window . alert ) . toHaveBeenCalled ( ) ;
297
+ expect ( window . alert ) . toHaveBeenCalledWith ( "Hey look it's listening" ) ;
298
298
expect ( container . querySelector ( '.modalBackdrop' ) ) . toBeInTheDocument ( ) ;
299
299
expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
300
300
} ) ;
@@ -348,7 +348,7 @@ describe('Modal', () => {
348
348
expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ;
349
349
350
350
userEvent . click ( screen . getAllByRole ( 'button' , { name : 'Hello' } ) [ 1 ] ) ;
351
- expect ( window . alert ) . toHaveBeenCalled ( ) ;
351
+ expect ( window . alert ) . toHaveBeenCalledWith ( "Hey look it's listening" ) ;
352
352
expect ( container . querySelector ( '.modalBackdrop' ) ) . toBeInTheDocument ( ) ;
353
353
expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
354
354
} ) ;
@@ -454,5 +454,32 @@ describe('Modal', () => {
454
454
expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
455
455
} ) ;
456
456
} ) ;
457
+
458
+ describe ( 'opens when enter key is pressed' , ( ) => {
459
+ const component = (
460
+ < Modal
461
+ element = "Hello"
462
+ body = { bodyText }
463
+ title = { title }
464
+ openListener = { openListener }
465
+ onKeyPress = { handleKeyPress }
466
+ />
467
+ ) ;
468
+ it ( 'toggles correctly' , ( ) => {
469
+ const { container } = render ( component ) ;
470
+ expect (
471
+ container . querySelector ( '.modalBackdrop' ) ,
472
+ ) . not . toBeInTheDocument ( ) ;
473
+ expect ( screen . queryByRole ( 'dialog' ) ) . toBeNull ( ) ;
474
+
475
+ fireEvent . keyDown ( container . querySelector ( '.modalElement' ) , {
476
+ key : 'Enter' ,
477
+ } ) ;
478
+ expect (
479
+ container . querySelector ( '.modalBackdrop' ) ,
480
+ ) . toBeInTheDocument ( ) ;
481
+ expect ( screen . getByRole ( 'dialog' ) ) . toBeInTheDocument ( ) ;
482
+ } ) ;
483
+ } ) ;
457
484
} ) ;
458
485
} ) ;
0 commit comments