Skip to content

Commit 57cce59

Browse files
committed
test(tooltip): add tooltip tests
1 parent cca17e2 commit 57cce59

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

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

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { fakeAsync, TestBed, tick, flush, waitForAsync } from '@angular/core/tes
22
import { By } from '@angular/platform-browser';
33
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
44
import { IgxTooltipModule, IgxTooltipTargetDirective, IgxTooltipDirective } from './';
5-
import { IgxTooltipSingleTargetComponent, IgxTooltipMultipleTargetsComponent } from '../../test-utils/tooltip-components.spec';
5+
import { IgxTooltipSingleTargetComponent, IgxTooltipMultipleTargetsComponent, IgxTooltipPlainStringComponent } from '../../test-utils/tooltip-components.spec';
66
import { UIInteractions } from '../../test-utils/ui-interactions.spec';
77
import { configureTestSuite } from '../../test-utils/configure-suite';
88
import { HorizontalAlignment, VerticalAlignment, AutoPositionStrategy } from '../../services/public_api';
@@ -21,7 +21,8 @@ describe('IgxTooltip', () => {
2121
TestBed.configureTestingModule({
2222
declarations: [
2323
IgxTooltipSingleTargetComponent,
24-
IgxTooltipMultipleTargetsComponent
24+
IgxTooltipMultipleTargetsComponent,
25+
IgxTooltipPlainStringComponent
2526
],
2627
imports: [NoopAnimationsModule, IgxTooltipModule]
2728
}).compileComponents();
@@ -79,6 +80,14 @@ describe('IgxTooltip', () => {
7980
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, false);
8081
}));
8182

83+
it('show target tooltip when hovering its target and ignore [tooltip] input', fakeAsync(() => {
84+
hoverElement(button);
85+
flush();
86+
87+
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, true);
88+
expect(tooltipNativeElement.textContent.trim()).toEqual('Hello, I am a tooltip!');
89+
}));
90+
8291
it('verify tooltip default position', fakeAsync(() => {
8392
hoverElement(button);
8493
flush();
@@ -260,6 +269,33 @@ describe('IgxTooltip', () => {
260269
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, false);
261270
}));
262271

272+
describe('Plain string toopltip input', () => {
273+
// configureTestSuite();
274+
beforeEach(waitForAsync(() => {
275+
fix = TestBed.createComponent(IgxTooltipPlainStringComponent);
276+
fix.detectChanges();
277+
button = fix.debugElement.query(By.directive(IgxTooltipTargetDirective));
278+
tooltipTarget = fix.componentInstance.tooltipTarget;
279+
tooltipNativeElement = fix.debugElement.query(By.directive(IgxTooltipDirective)).nativeElement;
280+
}));
281+
282+
it('IgxTooltip is initially hidden', () => {
283+
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, false);
284+
});
285+
286+
it('IgxTooltip is shown/hidden when hovering/unhovering its target', fakeAsync(() => {
287+
hoverElement(button);
288+
flush();
289+
290+
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, true);
291+
292+
unhoverElement(button);
293+
flush();
294+
295+
verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, false);
296+
}));
297+
});
298+
263299
describe('Tooltip events', () => {
264300
// configureTestSuite();
265301
it('should emit the proper events when hovering/unhovering target', fakeAsync(() => {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
@Component({
88
template: `
99
<div class="dummyDiv">dummy div for touch tests</div>
10-
<button [igxTooltipTarget]="tooltipRef"
10+
<button [igxTooltipTarget]="tooltipRef" [tooltip]="'Infragistics Inc. HQ'"
1111
(tooltipShow)="showing($event)" (tooltipHide)="hiding($event)"
1212
style="margin: 200px">
1313
Hover me
@@ -56,3 +56,15 @@ export class IgxTooltipMultipleTargetsComponent {
5656
@ViewChild('targetTwo', { read: IgxTooltipTargetDirective, static: true }) public targetTwo: IgxTooltipTargetDirective;
5757
@ViewChild(IgxTooltipDirective, { static: true }) public tooltip: IgxTooltipDirective;
5858
}
59+
60+
61+
@Component({
62+
template: `
63+
<button igxTooltipTarget [tooltip]="'Infragistics Inc. HQ'">
64+
info
65+
</button>
66+
`
67+
})
68+
export class IgxTooltipPlainStringComponent {
69+
@ViewChild(IgxTooltipTargetDirective, { static: true }) public tooltipTarget: IgxTooltipTargetDirective;
70+
}

0 commit comments

Comments
 (0)