@@ -300,98 +300,104 @@ describe('Modal', () => {
300
300
301
301
describe ( 'onOpen' , ( ) => {
302
302
it ( 'is called on trigger click' , ( ) => {
303
- const spy = sandbox . spy ( )
304
- wrapperMount ( < Modal onOpen = { spy } trigger = { < div id = 'trigger' /> } /> )
303
+ const onOpen = sandbox . spy ( )
304
+ wrapperMount ( < Modal onOpen = { onOpen } trigger = { < div id = 'trigger' /> } /> )
305
305
306
306
wrapper . find ( '#trigger' ) . simulate ( 'click' )
307
- spy . should . have . been . calledOnce ( )
307
+ onOpen . should . have . been . calledOnce ( )
308
+ onOpen . should . have . been . calledWithMatch ( { } , { open : true } )
308
309
} )
309
310
310
311
it ( 'is not called on body click' , ( ) => {
311
- const spy = sandbox . spy ( )
312
- wrapperMount ( < Modal onOpen = { spy } /> )
312
+ const onOpen = sandbox . spy ( )
313
+ wrapperMount ( < Modal onOpen = { onOpen } /> )
313
314
314
315
domEvent . click ( document . body )
315
- spy . should . not . have . been . called ( )
316
+ onOpen . should . not . have . been . called ( )
316
317
} )
317
318
} )
318
319
319
320
describe ( 'onClose' , ( ) => {
320
- let spy
321
-
322
- beforeEach ( ( ) => {
323
- spy = sandbox . spy ( )
324
- } )
325
-
326
321
it ( 'is called on dimmer click' , ( ) => {
327
- wrapperMount ( < Modal onClose = { spy } defaultOpen /> )
322
+ const onClose = sandbox . spy ( )
323
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen /> )
328
324
329
325
domEvent . click ( '.ui.dimmer' )
330
- spy . should . have . been . calledOnce ( )
326
+ onClose . should . have . been . calledOnce ( )
327
+ onClose . should . have . been . calledWithMatch ( { } , { open : false } )
331
328
} )
332
329
333
330
it ( 'is called on click outside of the modal' , ( ) => {
334
- wrapperMount ( < Modal onClose = { spy } defaultOpen /> )
331
+ const onClose = sandbox . spy ( )
332
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen /> )
335
333
336
334
domEvent . click ( document . querySelector ( '.ui.modal' ) . parentNode )
337
- spy . should . have . been . calledOnce ( )
335
+ onClose . should . have . been . calledOnce ( )
338
336
} )
339
337
340
338
it ( 'is not called on mousedown inside and mouseup outside of the modal' , ( ) => {
341
- wrapperMount ( < Modal onClose = { spy } defaultOpen /> )
339
+ const onClose = sandbox . spy ( )
340
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen /> )
342
341
343
342
domEvent . mouseDown ( document . querySelector ( '.ui.modal' ) )
344
343
domEvent . click ( document . querySelector ( '.ui.modal' ) . parentNode )
345
- spy . should . not . have . been . called ( )
344
+ onClose . should . not . have . been . called ( )
346
345
} )
347
346
348
347
it ( 'is not called on click inside of the modal' , ( ) => {
349
- wrapperMount ( < Modal onClose = { spy } defaultOpen /> )
348
+ const onClose = sandbox . spy ( )
349
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen /> )
350
350
351
351
domEvent . click ( document . querySelector ( '.ui.modal' ) )
352
- spy . should . not . have . been . called ( )
352
+ onClose . should . not . have . been . called ( )
353
353
} )
354
354
355
355
it ( 'is not called on body click' , ( ) => {
356
- wrapperMount ( < Modal onClose = { spy } defaultOpen /> )
356
+ const onClose = sandbox . spy ( )
357
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen /> )
357
358
358
359
domEvent . click ( document . body )
359
- spy . should . not . have . been . calledOnce ( )
360
+ onClose . should . not . have . been . calledOnce ( )
360
361
} )
361
362
362
363
it ( 'is called when pressing escape' , ( ) => {
363
- wrapperMount ( < Modal onClose = { spy } defaultOpen /> )
364
+ const onClose = sandbox . spy ( )
365
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen /> )
364
366
365
367
domEvent . keyDown ( document , { key : 'Escape' } )
366
- spy . should . have . been . calledOnce ( )
368
+ onClose . should . have . been . calledOnce ( )
367
369
} )
368
370
369
371
it ( 'is not called when the open prop changes to false' , ( ) => {
370
- wrapperMount ( < Modal onClose = { spy } defaultOpen /> )
372
+ const onClose = sandbox . spy ( )
373
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen /> )
371
374
372
375
wrapper . setProps ( { open : false } )
373
- spy . should . not . have . been . called ( )
376
+ onClose . should . not . have . been . called ( )
374
377
} )
375
378
376
379
it ( 'is not called when open changes to false programmatically' , ( ) => {
377
- wrapperMount ( < Modal onClose = { spy } defaultOpen /> )
380
+ const onClose = sandbox . spy ( )
381
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen /> )
378
382
379
383
wrapper . setProps ( { open : false } )
380
- spy . should . not . have . been . called ( )
384
+ onClose . should . not . have . been . called ( )
381
385
} )
382
386
383
387
it ( 'is not called on dimmer click when closeOnDimmerClick is false' , ( ) => {
384
- wrapperMount ( < Modal onClose = { spy } defaultOpen closeOnDimmerClick = { false } /> )
388
+ const onClose = sandbox . spy ( )
389
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen closeOnDimmerClick = { false } /> )
385
390
386
391
domEvent . click ( '.ui.dimmer' )
387
- spy . should . not . have . been . called ( )
392
+ onClose . should . not . have . been . called ( )
388
393
} )
389
394
390
395
it ( 'is not called on body click when closeOnDocumentClick is false' , ( ) => {
391
- wrapperMount ( < Modal onClose = { spy } defaultOpen closeOnDocumentClick = { false } /> )
396
+ const onClose = sandbox . spy ( )
397
+ wrapperMount ( < Modal onClose = { onClose } defaultOpen closeOnDocumentClick = { false } /> )
392
398
393
399
domEvent . click ( document . body )
394
- spy . should . not . have . been . called ( )
400
+ onClose . should . not . have . been . called ( )
395
401
} )
396
402
} )
397
403
0 commit comments