11import { TestBed , ComponentFixture } from "@angular/core/testing" ;
2- import { Component , Input } from "@angular/core" ;
2+ import { Component , DebugElement , Input } from "@angular/core" ;
33import { By } from "@angular/platform-browser" ;
44
55import { PopoverContainer , PopoverContent } from "./" ;
@@ -12,7 +12,8 @@ import { PopoverContainer, PopoverContent } from "./";
1212 [dropShadow]="dropShadow"
1313 [align]="align"
1414 [caret]="caret"
15- [highContrast]="highContrast">
15+ [highContrast]="highContrast"
16+ [autoAlign]="autoAlign">
1617 <p>Popover trigger</p>
1718 <cds-popover-content>
1819 <div>
@@ -28,27 +29,31 @@ class TestPopoverComponent {
2829 @Input ( ) align = "bottom" ;
2930 @Input ( ) caret = true ;
3031 @Input ( ) highContrast = false ;
32+ @Input ( ) autoAlign = true ;
3133}
3234
3335describe ( "Popover" , ( ) => {
3436 let fixture : ComponentFixture < TestPopoverComponent > ;
3537 let component : TestPopoverComponent ;
38+ let popoverContainerElement : DebugElement ;
39+ let popoverDirectiveEl : PopoverContainer ;
3640
3741 beforeEach ( ( ) => {
3842 TestBed . configureTestingModule ( {
3943 declarations : [ TestPopoverComponent , PopoverContainer , PopoverContent ]
4044 } ) ;
4145 fixture = TestBed . createComponent ( TestPopoverComponent ) ;
4246 component = fixture . componentInstance ;
47+ popoverContainerElement = fixture . debugElement . query ( By . directive ( PopoverContainer ) ) ;
48+ popoverDirectiveEl = popoverContainerElement . injector . get ( PopoverContainer ) ;
4349 fixture . detectChanges ( ) ;
4450 } ) ;
4551
4652
4753 it ( "should create a popover container & content" , ( ) => {
4854 expect ( component ) . toBeTruthy ( ) ;
49- const directiveEl = fixture . debugElement . query ( By . directive ( PopoverContainer ) ) ;
50- expect ( directiveEl ) . not . toBeNull ( ) ;
51- expect ( directiveEl . nativeElement . className . includes ( "cds--popover-container" ) ) . toBeTruthy ( ) ;
55+ expect ( popoverContainerElement ) . not . toBeNull ( ) ;
56+ expect ( popoverContainerElement . nativeElement . className . includes ( "cds--popover-container" ) ) . toBeTruthy ( ) ;
5257
5358 const componentEl = fixture . debugElement . query ( By . css ( "cds-popover-content" ) ) ;
5459 expect ( componentEl ) . not . toBeNull ( ) ;
@@ -79,4 +84,17 @@ describe("Popover", () => {
7984 expect ( directiveEl . className . includes ( "cds--popover--drop-shadow" ) ) . toBeFalsy ( ) ;
8085 expect ( directiveEl . className . includes ( "cds--popover--high-contrast" ) ) . toBeTruthy ( ) ;
8186 } ) ;
87+
88+ it ( "should set auto alignment class to wrapper and caret" , ( ) => {
89+ expect ( popoverContainerElement . nativeElement . classList . contains ( "cds--popover--auto-align" ) ) . toBeTruthy ( ) ;
90+ expect ( popoverContainerElement . nativeElement . querySelector ( ".cds--popover-caret.cds--popover--auto-align" ) ) . toBeDefined ( ) ;
91+ } ) ;
92+
93+ it ( "should clean up auto placement on close when auto alignment is enabled" , ( ) => {
94+ spyOn ( popoverDirectiveEl , "cleanUp" ) ;
95+ component . isOpen = true ;
96+ fixture . detectChanges ( ) ;
97+ component . isOpen = false ;
98+ expect ( popoverDirectiveEl . cleanUp ) . toHaveBeenCalled ( ) ;
99+ } ) ;
82100} ) ;
0 commit comments