Skip to content

Commit 674bcf0

Browse files
committed
test(Tooltip): Adding a test for destroying the target.
1 parent 33d7052 commit 674bcf0

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

projects/igniteui-angular/src/lib/directives/tooltip/tooltip.directive.spec.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,19 @@ describe('IgxTooltip', () => {
271271
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, false);
272272
}));
273273

274+
it('IgxTooltip is hidden when its target is destroyed', fakeAsync(() => {
275+
hoverElement(button);
276+
flush();
277+
278+
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, true);
279+
debugger
280+
fix.componentInstance.showButton = false;
281+
fix.detectChanges();
282+
flush();
283+
284+
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, false);
285+
}));
286+
274287
describe('Tooltip events', () => {
275288
// configureTestSuite();
276289
it('should emit the proper events when hovering/unhovering target', fakeAsync(() => {
@@ -596,7 +609,7 @@ const touchElement = (element) => element.nativeElement.dispatchEvent(new TouchE
596609
const verifyTooltipVisibility = (tooltipNativeElement, tooltipTarget, shouldBeVisible: boolean) => {
597610
expect(tooltipNativeElement.classList.contains(TOOLTIP_CLASS)).toBe(shouldBeVisible);
598611
expect(tooltipNativeElement.classList.contains(HIDDEN_TOOLTIP_CLASS)).not.toBe(shouldBeVisible);
599-
expect(tooltipTarget.tooltipHidden).not.toBe(shouldBeVisible);
612+
expect(tooltipTarget?.tooltipHidden).not.toBe(shouldBeVisible);
600613
};
601614

602615
const verifyTooltipPosition = (tooltipNativeElement, actualTarget, shouldBeAligned: boolean) => {

projects/igniteui-angular/src/lib/test-utils/tooltip-components.spec.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ import { IgxToggleActionDirective, IgxToggleDirective } from '../directives/togg
66
@Component({
77
template: `
88
<div class="dummyDiv">dummy div for touch tests</div>
9-
<button [igxTooltipTarget]="tooltipRef" [tooltip]="'Infragistics Inc. HQ'"
10-
(tooltipShow)="showing($event)" (tooltipHide)="hiding($event)"
11-
style="margin: 200px">
12-
Hover me
13-
</button>
9+
10+
@if (showButton) {
11+
<button [igxTooltipTarget]="tooltipRef" [tooltip]="'Infragistics Inc. HQ'"
12+
(tooltipShow)="showing($event)" (tooltipHide)="hiding($event)"
13+
style="margin: 200px">
14+
Hover me
15+
</button>
16+
}
1417
<div igxTooltip #tooltipRef="tooltip">
1518
Hello, I am a tooltip!
1619
</div>
@@ -23,6 +26,7 @@ export class IgxTooltipSingleTargetComponent {
2326
@ViewChild(IgxTooltipTargetDirective, { static: true }) public tooltipTarget: IgxTooltipTargetDirective;
2427
public cancelShowing = false;
2528
public cancelHiding = false;
29+
public showButton = true;
2630

2731
public showing(args: ITooltipShowEventArgs) {
2832
if (this.cancelShowing) {
@@ -39,9 +43,9 @@ export class IgxTooltipSingleTargetComponent {
3943

4044
@Component({
4145
template: `
42-
<button class="buttonOne" #targetOne="tooltipTarget" [igxTooltipTarget]="tooltipRef" style="margin: 100px">
43-
Target One
44-
</button>
46+
<button class="buttonOne" #targetOne="tooltipTarget" [igxTooltipTarget]="tooltipRef" style="margin: 100px">
47+
Target One
48+
</button>
4549
4650
<button class="buttonTwo" #targetTwo="tooltipTarget" [igxTooltipTarget]="tooltipRef" style="margin: 100px">
4751
Target Two

0 commit comments

Comments
 (0)