11import { fakeAsync , TestBed , tick , flush , waitForAsync } from '@angular/core/testing' ;
22import { By } from '@angular/platform-browser' ;
33import { NoopAnimationsModule } from '@angular/platform-browser/animations' ;
4- import { IgxTooltipSingleTargetComponent , IgxTooltipMultipleTargetsComponent , IgxTooltipPlainStringComponent } from '../../test-utils/tooltip-components.spec' ;
4+ import { IgxTooltipSingleTargetComponent , IgxTooltipMultipleTargetsComponent , IgxTooltipPlainStringComponent , IgxTooltipWithToggleActionComponent } from '../../test-utils/tooltip-components.spec' ;
55import { UIInteractions } from '../../test-utils/ui-interactions.spec' ;
66import { configureTestSuite } from '../../test-utils/configure-suite' ;
77import { HorizontalAlignment , VerticalAlignment , AutoPositionStrategy } from '../../services/public_api' ;
@@ -24,7 +24,8 @@ describe('IgxTooltip', () => {
2424 NoopAnimationsModule ,
2525 IgxTooltipSingleTargetComponent ,
2626 IgxTooltipMultipleTargetsComponent ,
27- IgxTooltipPlainStringComponent
27+ IgxTooltipPlainStringComponent ,
28+ IgxTooltipWithToggleActionComponent
2829 ]
2930 } ) . compileComponents ( ) ;
3031 UIInteractions . clearOverlay ( ) ;
@@ -554,6 +555,36 @@ describe('IgxTooltip', () => {
554555 verifyTooltipPosition ( tooltipNativeElement , buttonOne , false ) ;
555556 } ) ) ;
556557 } ) ;
558+
559+ describe ( 'Tooltip integration' , ( ) => {
560+ beforeEach ( waitForAsync ( ( ) => {
561+ fix = TestBed . createComponent ( IgxTooltipWithToggleActionComponent ) ;
562+ fix . detectChanges ( ) ;
563+ tooltipNativeElement = fix . debugElement . query ( By . directive ( IgxTooltipDirective ) ) . nativeElement ;
564+ tooltipTarget = fix . componentInstance . tooltipTarget as IgxTooltipTargetDirective ;
565+ button = fix . debugElement . query ( By . directive ( IgxTooltipTargetDirective ) ) ;
566+ } ) ) ;
567+
568+ it ( 'Correctly sets tooltip target when defined before igxToggleAction directive on same host - issue #14196' , fakeAsync ( ( ) => {
569+ expect ( tooltipTarget . target . element ) . toBe ( tooltipNativeElement ) ;
570+ expect ( fix . componentInstance . toggleDir . collapsed ) . toBe ( true ) ;
571+
572+ hoverElement ( button ) ;
573+ flush ( ) ;
574+
575+ verifyTooltipVisibility ( tooltipNativeElement , tooltipTarget , true ) ;
576+
577+ UIInteractions . simulateClickEvent ( button . nativeElement ) ;
578+ fix . detectChanges ( ) ;
579+
580+ verifyTooltipVisibility ( tooltipNativeElement , tooltipTarget , false ) ;
581+
582+ UIInteractions . simulateClickEvent ( button . nativeElement ) ;
583+ fix . detectChanges ( ) ;
584+
585+ expect ( fix . componentInstance . toggleDir . collapsed ) . toBe ( false ) ;
586+ } ) ) ;
587+ } ) ;
557588} ) ;
558589
559590const hoverElement = ( element ) => element . nativeElement . dispatchEvent ( new MouseEvent ( 'mouseenter' ) ) ;
0 commit comments