@@ -11,7 +11,6 @@ import Portal from 'src/addons/Portal/Portal'
11
11
12
12
import {
13
13
assertNodeContains ,
14
- assertBodyClasses ,
15
14
assertBodyContains ,
16
15
assertWithTimeout ,
17
16
domEvent ,
@@ -30,16 +29,6 @@ let wrapper
30
29
const wrapperMount = ( ...args ) => ( wrapper = mount ( ...args ) )
31
30
const wrapperShallow = ( ...args ) => ( wrapper = shallow ( ...args ) )
32
31
33
- // cleanup in `useEffect()` is executed async, so we need to perform a proper cleanup first to avoid
34
- // collisions with other tests
35
- function waitForClassesCleanup ( done , customAssertions = ( ) => { } ) {
36
- wrapper . unmount ( )
37
- assertWithTimeout ( ( ) => {
38
- assertBodyClasses ( 'dimmed' , false )
39
- customAssertions ( )
40
- } , done )
41
- }
42
-
43
32
describe ( 'Modal' , ( ) => {
44
33
beforeEach ( ( ) => {
45
34
if ( wrapper && wrapper . unmount ) {
@@ -72,12 +61,16 @@ describe('Modal', () => {
72
61
propKey : 'header' ,
73
62
ShorthandComponent : ModalHeader ,
74
63
mapValueToProps : ( content ) => ( { content } ) ,
64
+ rendersPortal : true ,
65
+ requiredProps : { open : true } ,
75
66
} )
76
67
common . implementsShorthandProp ( Modal , {
77
68
autoGenerateKey : false ,
78
69
propKey : 'content' ,
79
70
ShorthandComponent : ModalContent ,
80
71
mapValueToProps : ( content ) => ( { content } ) ,
72
+ rendersPortal : true ,
73
+ requiredProps : { open : true } ,
81
74
} )
82
75
83
76
// Heads up!
@@ -246,67 +239,24 @@ describe('Modal', () => {
246
239
} )
247
240
248
241
describe ( 'dimmer' , ( ) => {
249
- it ( 'adds a "dimmer" className to the body ' , ( done ) => {
242
+ it ( 'renders ModalDimmer by default ' , ( ) => {
250
243
wrapperMount ( < Modal open /> )
251
-
252
- assertBodyContains ( '.ui.page.modals.dimmer.transition.visible.active' )
253
- waitForClassesCleanup ( done )
244
+ wrapper . should . have . descendants ( 'ModalDimmer' )
254
245
} )
255
246
256
- describe ( 'can be "true"' , ( ) => {
257
- it ( 'adds/removes body classes "dimmable dimmed" on mount/unmount' , ( done ) => {
258
- assertBodyClasses ( 'dimmable dimmed' , false )
259
-
260
- wrapperMount ( < Modal open dimmer /> )
261
- assertBodyClasses ( 'dimmable dimmed' )
262
-
263
- wrapper . setProps ( { open : false } )
264
- assertBodyClasses ( 'dimmable dimmed' , false )
265
-
266
- waitForClassesCleanup ( done )
267
- } )
247
+ it ( 'renders ModalDimmer when is "true"' , ( ) => {
248
+ wrapperMount ( < Modal open dimmer /> )
249
+ wrapper . should . have . descendants ( 'ModalDimmer' )
268
250
} )
269
251
270
- describe ( 'blurring' , ( ) => {
271
- it ( 'adds/removes body classes "dimmable dimmed blurring" on mount/unmount' , ( done ) => {
272
- assertBodyClasses ( 'dimmable dimmed blurring' , false )
273
-
274
- wrapperMount ( < Modal open dimmer = 'blurring' /> )
275
- assertBodyClasses ( 'dimmable dimmed blurring' )
276
-
277
- wrapper . setProps ( { open : false } )
278
- assertBodyClasses ( 'dimmable dimmed blurring' , false )
279
-
280
- waitForClassesCleanup ( done )
281
- } )
282
-
283
- it ( 'adds a dimmer to the body' , ( done ) => {
284
- wrapperMount ( < Modal open dimmer = 'blurring' /> )
285
-
286
- assertBodyContains ( '.ui.page.modals.dimmer.transition.visible.active' )
287
- waitForClassesCleanup ( done )
288
- } )
252
+ it ( 'passes "blurring" to ModalDimmer' , ( ) => {
253
+ wrapperMount ( < Modal open dimmer = 'blurring' /> )
254
+ wrapper . find ( 'ModalDimmer' ) . should . have . prop ( 'blurring' , true )
289
255
} )
290
256
291
- describe ( 'inverted' , ( ) => {
292
- it ( 'adds/removes body classes "dimmable dimmed" on mount/unmount' , ( done ) => {
293
- assertBodyClasses ( 'dimmable dimmed' , false )
294
-
295
- wrapperMount ( < Modal open dimmer /> )
296
- assertBodyClasses ( 'dimmable dimmed' )
297
-
298
- wrapper . setProps ( { open : false } )
299
- assertBodyClasses ( 'dimmable dimmed' , false )
300
-
301
- waitForClassesCleanup ( done )
302
- } )
303
-
304
- it ( 'adds an inverted dimmer to the body' , ( done ) => {
305
- wrapperMount ( < Modal open dimmer = 'inverted' /> )
306
-
307
- assertBodyContains ( '.ui.inverted.page.modals.dimmer.transition.visible.active' )
308
- waitForClassesCleanup ( done )
309
- } )
257
+ it ( 'passes "inverted" to ModalDimmer' , ( ) => {
258
+ wrapperMount ( < Modal open dimmer = 'inverted' /> )
259
+ wrapper . find ( 'ModalDimmer' ) . should . have . prop ( 'inverted' , true )
310
260
} )
311
261
312
262
describe ( 'object' , ( ) => {
@@ -550,41 +500,42 @@ describe('Modal', () => {
550
500
window . innerHeight = innerHeight
551
501
} )
552
502
553
- it ( 'does not add the scrolling class to the body by default' , ( done ) => {
503
+ it ( 'does not pass " scrolling" by default' , ( ) => {
554
504
wrapperMount ( < Modal open /> )
555
-
556
- assertBodyClasses ( 'scrolling' , false )
557
- waitForClassesCleanup ( done )
505
+ wrapper . find ( 'ModalDimmer' ) . should . have . prop ( 'scrolling' , false )
558
506
} )
559
507
560
- it ( 'does not add the scrolling class to the body when equal to the window height' , ( done ) => {
508
+ it ( 'does not pass " scrolling" when equal to the window height' , ( done ) => {
561
509
/* 101 is `padding * 2 + 1, see Modal/utils */
562
510
const height = window . innerHeight - 101
511
+
563
512
wrapperMount (
564
513
< Modal open style = { { height } } >
565
514
foo
566
515
</ Modal > ,
567
516
)
568
517
569
518
requestAnimationFrame ( ( ) => {
570
- assertBodyClasses ( 'scrolling' , false )
519
+ wrapper . update ( )
520
+ wrapper . find ( 'ModalDimmer' ) . should . have . prop ( 'scrolling' , false )
521
+
571
522
done ( )
572
523
} )
573
524
} )
574
525
575
- it ( 'adds the scrolling class to the body when taller than the window' , ( done ) => {
526
+ it ( 'passes " scrolling" when taller than the window' , ( done ) => {
576
527
window . innerHeight = 10
577
528
wrapperMount ( < Modal open > foo</ Modal > )
578
529
579
530
requestAnimationFrame ( ( ) => {
580
- assertBodyClasses ( 'scrolling' )
531
+ wrapper . update ( )
532
+ wrapper . find ( 'ModalDimmer' ) . should . have . prop ( 'scrolling' , true )
533
+
581
534
done ( )
582
535
} )
583
536
} )
584
537
585
- it ( 'adds/removes the scrolling class to the body when the window grows/shrinks' , ( done ) => {
586
- assertBodyClasses ( 'scrolling' , false )
587
-
538
+ it ( 'passes "scrolling" when the window grows/shrinks' , ( done ) => {
588
539
wrapperMount (
589
540
< Modal open >
590
541
< span />
@@ -594,51 +545,18 @@ describe('Modal', () => {
594
545
595
546
assertWithTimeout (
596
547
( ) => {
597
- assertBodyClasses ( 'scrolling' )
548
+ wrapper . update ( )
549
+ wrapper . find ( 'ModalDimmer' ) . should . have . prop ( 'scrolling' , true )
550
+
598
551
window . innerHeight = 10000
599
552
} ,
600
553
( ) =>
601
554
assertWithTimeout ( ( ) => {
602
- assertBodyClasses ( 'scrolling' , false )
555
+ wrapper . update ( )
556
+ wrapper . find ( 'ModalDimmer' ) . should . have . prop ( 'scrolling' , false )
603
557
} , done ) ,
604
558
)
605
559
} )
606
-
607
- it ( 'adds the scrolling class to the body after re-open' , ( done ) => {
608
- assertBodyClasses ( 'scrolling' , false )
609
-
610
- window . innerHeight = 10
611
- wrapperMount ( < Modal defaultOpen > foo</ Modal > )
612
-
613
- assertWithTimeout (
614
- ( ) => {
615
- assertBodyClasses ( 'scrolling' )
616
- domEvent . click ( '.ui.dimmer' )
617
- } ,
618
- ( ) =>
619
- assertWithTimeout (
620
- ( ) => {
621
- assertBodyClasses ( 'scrolling' , false )
622
- wrapper . setProps ( { open : true } )
623
- } ,
624
- ( ) =>
625
- assertWithTimeout ( ( ) => {
626
- assertBodyClasses ( 'scrolling' )
627
- } , done ) ,
628
- ) ,
629
- )
630
- } )
631
-
632
- it ( 'removes the scrolling class from the body on unmount' , ( done ) => {
633
- assertBodyClasses ( 'scrolling' , false )
634
-
635
- window . innerHeight = 10
636
- wrapperMount ( < Modal open > foo</ Modal > )
637
-
638
- waitForClassesCleanup ( done , ( ) => {
639
- assertBodyClasses ( 'scrolling' , false )
640
- } )
641
- } )
642
560
} )
643
561
644
562
describe ( 'server-side' , ( ) => {
0 commit comments