@@ -437,5 +437,86 @@ describe('vaadin-master-detail-layout', () => {
437
437
expect ( layout . hasAttribute ( 'overlay' ) ) . to . be . false ;
438
438
} ) ;
439
439
} ) ;
440
+
441
+ describe ( 'containment' , ( ) => {
442
+ before ( ( ) => {
443
+ // Apply padding to body to test viewport containment.
444
+ document . body . style . padding = '20px' ;
445
+ } ) ;
446
+
447
+ after ( ( ) => {
448
+ document . body . style . padding = '' ;
449
+ } ) ;
450
+
451
+ describe ( 'horizontal orientation' , ( ) => {
452
+ beforeEach ( async ( ) => {
453
+ // Use the threshold at which the overlay mode is on by default.
454
+ await setViewport ( { width : 350 , height } ) ;
455
+ await nextResize ( layout ) ;
456
+
457
+ expect ( layout . hasAttribute ( 'overlay' ) ) . to . be . true ;
458
+ } ) ;
459
+
460
+ it ( 'should contain overlay to layout by default' , ( ) => {
461
+ const layoutBounds = layout . getBoundingClientRect ( ) ;
462
+ const detailBounds = detail . getBoundingClientRect ( ) ;
463
+
464
+ expect ( getComputedStyle ( detail ) . position ) . to . equal ( 'absolute' ) ;
465
+ expect ( detailBounds . top ) . to . equal ( layoutBounds . top ) ;
466
+ expect ( detailBounds . bottom ) . to . equal ( layoutBounds . bottom ) ;
467
+ expect ( detailBounds . right ) . to . equal ( layoutBounds . right ) ;
468
+ } ) ;
469
+
470
+ it ( 'should contain overlay to viewport when configured' , async ( ) => {
471
+ layout . containment = 'viewport' ;
472
+ await nextRender ( ) ;
473
+
474
+ const detailBounds = detail . getBoundingClientRect ( ) ;
475
+ const windowBounds = document . documentElement . getBoundingClientRect ( ) ;
476
+
477
+ expect ( getComputedStyle ( detail ) . position ) . to . equal ( 'fixed' ) ;
478
+ expect ( detailBounds . top ) . to . equal ( windowBounds . top ) ;
479
+ expect ( detailBounds . bottom ) . to . equal ( windowBounds . bottom ) ;
480
+ expect ( detailBounds . right ) . to . equal ( windowBounds . right ) ;
481
+ } ) ;
482
+ } ) ;
483
+
484
+ describe ( 'vertical orientation' , ( ) => {
485
+ beforeEach ( async ( ) => {
486
+ layout . orientation = 'vertical' ;
487
+ layout . style . maxHeight = '500px' ;
488
+ layout . parentElement . style . height = '100%' ;
489
+
490
+ // Use the threshold at which the overlay mode is on by default.
491
+ await setViewport ( { width : 500 , height : 400 } ) ;
492
+ await nextResize ( layout ) ;
493
+
494
+ expect ( layout . hasAttribute ( 'overlay' ) ) . to . be . true ;
495
+ } ) ;
496
+
497
+ it ( 'should contain overlay to layout by default' , ( ) => {
498
+ const layoutBounds = layout . getBoundingClientRect ( ) ;
499
+ const detailBounds = detail . getBoundingClientRect ( ) ;
500
+
501
+ expect ( getComputedStyle ( detail ) . position ) . to . equal ( 'absolute' ) ;
502
+ expect ( detailBounds . left ) . to . equal ( layoutBounds . left ) ;
503
+ expect ( detailBounds . right ) . to . equal ( layoutBounds . right ) ;
504
+ expect ( detailBounds . bottom ) . to . equal ( layoutBounds . bottom ) ;
505
+ } ) ;
506
+
507
+ it ( 'should contain overlay to viewport when configured' , async ( ) => {
508
+ layout . containment = 'viewport' ;
509
+ await nextRender ( ) ;
510
+
511
+ const detailBounds = detail . getBoundingClientRect ( ) ;
512
+ const windowBounds = document . documentElement . getBoundingClientRect ( ) ;
513
+
514
+ expect ( getComputedStyle ( detail ) . position ) . to . equal ( 'fixed' ) ;
515
+ expect ( detailBounds . left ) . to . equal ( windowBounds . left ) ;
516
+ expect ( detailBounds . right ) . to . equal ( windowBounds . right ) ;
517
+ expect ( detailBounds . bottom ) . to . equal ( windowBounds . bottom ) ;
518
+ } ) ;
519
+ } ) ;
520
+ } ) ;
440
521
} ) ;
441
522
} ) ;
0 commit comments