@@ -454,6 +454,20 @@ testSuite({
454
454
dom . getActiveElement ( document ) == popup . getElement ( ) ) ;
455
455
} ,
456
456
457
+ testPopupGetsFocus_withOptionalParent ( ) {
458
+ const parentEl = dom . createElement ( TagName . DIV ) ;
459
+ document . body . appendChild ( parentEl ) ;
460
+ popup = new ModalPopup ( ) ;
461
+ popup . setCenterInsideParentElement ( true ) ;
462
+ popup . render ( parentEl ) ;
463
+
464
+ popup . setVisible ( true ) ;
465
+
466
+ assertTrue (
467
+ 'Dialog must receive initial focus' ,
468
+ dom . getActiveElement ( document ) == popup . getElement ( ) ) ;
469
+ } ,
470
+
457
471
testDecoratedPopupGetsFocus ( ) {
458
472
const dialogElem = dom . createElement ( TagName . DIV ) ;
459
473
document . body . appendChild ( dialogElem ) ;
@@ -465,4 +479,100 @@ testSuite({
465
479
dom . getActiveElement ( document ) == popup . getElement ( ) ) ;
466
480
dom . removeNode ( dialogElem ) ;
467
481
} ,
482
+
483
+ testBackgroundSize_withoutOptionalParent_inheritBodySize ( ) {
484
+ popup = new ModalPopup ( ) ;
485
+ popup . render ( ) ;
486
+ // Because the test does not add css, the size of body element changes
487
+ // after showing the background.
488
+ const documentHeight = document . documentElement . scrollHeight ;
489
+ const documentWidth = document . documentElement . scrollWidth ;
490
+
491
+ popup . setVisible ( true ) ;
492
+
493
+ const backgroundSize = style . getSize ( popup . getBackgroundElement ( ) ) ;
494
+ assertTrue ( backgroundSize . width === documentWidth ) ;
495
+ assertTrue ( backgroundSize . height === documentHeight ) ;
496
+ } ,
497
+
498
+ testBackgroundSize_withOptionalParent_backgroundInheritParentSize ( ) {
499
+ const parentEl = dom . createElement ( TagName . DIV ) ;
500
+ document . body . appendChild ( parentEl ) ;
501
+ style . setSize ( parentEl , 99 , 88 ) ;
502
+ // Reinforce the test by changing the parent element size and assert the
503
+ // modal popup receives the right parent dimensions.
504
+ parentEl . style . transform = 'scale(0.5)' ;
505
+ parentEl . style . zoom = '50%' ;
506
+ parentEl . style . border = '20px solid' ;
507
+ popup = new ModalPopup ( ) ;
508
+ popup . setCenterInsideParentElement ( true ) ;
509
+ popup . render ( parentEl ) ;
510
+
511
+ popup . setVisible ( true ) ;
512
+
513
+ const backgroundSize = style . getSize ( popup . getBackgroundElement ( ) ) ;
514
+ assertTrue ( backgroundSize . width === 99 ) ;
515
+ assertTrue ( backgroundSize . height === 88 ) ;
516
+ dom . removeNode ( parentEl ) ;
517
+ } ,
518
+
519
+ testPopupPosition_withoutOptionalParent_relativeToBody ( ) {
520
+ popup = new ModalPopup ( ) ;
521
+ popup . render ( ) ;
522
+ style . setSize ( popup . getElement ( ) , 20 , 20 ) ;
523
+
524
+ popup . setVisible ( true ) ;
525
+
526
+ const viewportSize = dom . getViewportSize ( ) ;
527
+ const modalEl = popup . getElement ( ) ;
528
+ const modalSize = style . getSize ( modalEl ) ;
529
+ const top = style . getComputedStyle ( modalEl , 'top' ) ;
530
+ const expectedTop = viewportSize . height / 2 - modalSize . height / 2 ;
531
+ assertTrue ( top === expectedTop + 'px' ) ;
532
+ const left = style . getComputedStyle ( modalEl , 'left' ) ;
533
+ const expectedLeft = viewportSize . width / 2 - modalSize . width / 2 ;
534
+ assertTrue ( left === expectedLeft + 'px' ) ;
535
+ } ,
536
+
537
+ testPopupPosition_withOptionalParent_relativeToBody ( ) {
538
+ const parentEl = dom . createElement ( TagName . DIV ) ;
539
+ document . body . appendChild ( parentEl ) ;
540
+ popup = new ModalPopup ( ) ;
541
+ popup . setCenterInsideParentElement ( true ) ;
542
+ popup . render ( parentEl ) ;
543
+ style . setSize ( popup . getElement ( ) , 20 , 20 ) ;
544
+ style . setSize ( parentEl , 99 , 88 ) ;
545
+ // Reinforce the test by changing the parent element size and assert the
546
+ // modal popup receives the right parent dimensions.
547
+ parentEl . style . transform = 'scale(0.5)' ;
548
+ parentEl . style . zoom = '50%' ;
549
+ const borderThickness = 20 ;
550
+ parentEl . style . border = `${ borderThickness } px solid` ;
551
+
552
+ popup . setVisible ( true ) ;
553
+
554
+ const modalEl = popup . getElement ( ) ;
555
+ const modalSize = style . getSize ( modalEl ) ;
556
+ const parentSize = style . getSize ( parentEl ) ;
557
+ const parentInnerHeight =
558
+ parentSize . height - borderThickness - borderThickness ;
559
+ const expectedTop = parentInnerHeight / 2 - modalSize . height / 2 ;
560
+ const top = style . getComputedStyle ( modalEl , 'top' ) ;
561
+ assertTrue ( top === expectedTop + 'px' ) ;
562
+ const left = style . getComputedStyle ( modalEl , 'left' ) ;
563
+ const parentInnerWidth =
564
+ parentSize . width - borderThickness - borderThickness ;
565
+ const expectedLeft = parentInnerWidth / 2 - modalSize . width / 2 ;
566
+ assertTrue ( left === expectedLeft + 'px' ) ;
567
+ dom . removeNode ( parentEl ) ;
568
+ } ,
569
+
570
+ testSetCenterInsideParentElementAfterRender_throws ( ) {
571
+ const parentEl = dom . createElement ( TagName . DIV ) ;
572
+ document . body . appendChild ( parentEl ) ;
573
+ popup = new ModalPopup ( ) ;
574
+ popup . render ( ) ;
575
+
576
+ assertThrows ( ( ) => popup . setCenterInsideParentElement ( true ) ) ;
577
+ }
468
578
} ) ;
0 commit comments