|
1 | | -import { DebugElement } from '@angular/core'; |
| 1 | +import { DebugElement, ErrorHandler, provideZonelessChangeDetection } from '@angular/core'; |
2 | 2 | import { fakeAsync, TestBed, tick, flush, waitForAsync, ComponentFixture } from '@angular/core/testing'; |
3 | 3 | import { By } from '@angular/platform-browser'; |
4 | 4 | import { NoopAnimationsModule } from '@angular/platform-browser/animations'; |
5 | 5 | import { IgxTooltipSingleTargetComponent, IgxTooltipMultipleTargetsComponent, IgxTooltipPlainStringComponent, IgxTooltipWithToggleActionComponent, IgxTooltipWithCloseButtonComponent, IgxTooltipWithNestedContentComponent, IgxTooltipNestedTooltipsComponent } from '../../../../test-utils/tooltip-components.spec'; |
6 | | -import { UIInteractions } from '../../../../test-utils/ui-interactions.spec'; |
| 6 | +import { UIInteractions, wait } from '../../../../test-utils/ui-interactions.spec'; |
7 | 7 | import { HorizontalAlignment, VerticalAlignment, AutoPositionStrategy } from '../../../../core/src/services/public_api'; |
8 | 8 | import { IgxTooltipDirective } from './tooltip.directive'; |
9 | 9 | import { IgxTooltipTargetDirective } from './tooltip-target.directive'; |
@@ -1101,6 +1101,61 @@ describe('IgxTooltip', () => { |
1101 | 1101 | expect(closeBtn).toBeTruthy(); |
1102 | 1102 | expect(tooltipNativeElement.getAttribute('role')).toBe('status'); |
1103 | 1103 | })); |
| 1104 | + |
| 1105 | + describe('Zoneless', () => { |
| 1106 | + beforeEach(async () => { |
| 1107 | + TestBed.resetTestingModule(); |
| 1108 | + await TestBed.configureTestingModule({ |
| 1109 | + imports: [ |
| 1110 | + NoopAnimationsModule, |
| 1111 | + IgxTooltipWithCloseButtonComponent |
| 1112 | + ], |
| 1113 | + providers: [provideZonelessChangeDetection()] |
| 1114 | + }).compileComponents(); |
| 1115 | + }); |
| 1116 | + |
| 1117 | + beforeEach(() => { |
| 1118 | + fix = TestBed.createComponent(IgxTooltipWithCloseButtonComponent); |
| 1119 | + fix.detectChanges(); |
| 1120 | + tooltipNativeElement = fix.debugElement.query(By.directive(IgxTooltipDirective)).nativeElement; |
| 1121 | + tooltipTarget = fix.componentInstance.tooltipTarget as IgxTooltipTargetDirective; |
| 1122 | + button = fix.debugElement.query(By.directive(IgxTooltipTargetDirective)); |
| 1123 | + }); |
| 1124 | + |
| 1125 | + it('should not throw ExpressionChangedAfterItHasBeenChecked when showing sticky tooltip with close button', async () => { |
| 1126 | + const errorHandler = TestBed.inject(ErrorHandler); |
| 1127 | + const handleErrorSpy = spyOn(errorHandler, 'handleError'); |
| 1128 | + |
| 1129 | + hoverElement(button); |
| 1130 | + await wait(SHOW_DELAY + 50); |
| 1131 | + fix.detectChanges(); |
| 1132 | + |
| 1133 | + expect(handleErrorSpy).not.toHaveBeenCalled(); |
| 1134 | + verifyTooltipVisibility(tooltipNativeElement, tooltipTarget, true); |
| 1135 | + expect(tooltipNativeElement.getAttribute('role')).toBe('status'); |
| 1136 | + }); |
| 1137 | + |
| 1138 | + it('should correctly remove the close button and update the role when sticky is set to false', async () => { |
| 1139 | + tooltipTarget.sticky = true; |
| 1140 | + fix.detectChanges(); |
| 1141 | + hoverElement(button); |
| 1142 | + await wait(SHOW_DELAY + 50); |
| 1143 | + fix.detectChanges(); |
| 1144 | + |
| 1145 | + const closeBtn = tooltipNativeElement.querySelector('igx-tooltip-close-button'); |
| 1146 | + expect(closeBtn).not.toBeNull(); |
| 1147 | + expect(fix.componentInstance.tooltip.role).toBe('status'); |
| 1148 | + |
| 1149 | + tooltipTarget.sticky = false; |
| 1150 | + fix.detectChanges(); |
| 1151 | + hoverElement(button); |
| 1152 | + await wait(SHOW_DELAY + 50); |
| 1153 | + fix.detectChanges(); |
| 1154 | + |
| 1155 | + expect(fix.componentInstance.tooltip.role).toBe('tooltip'); |
| 1156 | + expect(tooltipNativeElement.querySelector('igx-tooltip-close-button')).toBeNull(); |
| 1157 | + }); |
| 1158 | + }); |
1104 | 1159 | }); |
1105 | 1160 |
|
1106 | 1161 | describe('IgxTooltip placement and offset', () => { |
@@ -1188,7 +1243,7 @@ const alignmentTolerance = 2; |
1188 | 1243 | export const verifyTooltipPosition = ( |
1189 | 1244 | tooltipNativeElement: HTMLElement, |
1190 | 1245 | actualTarget: { nativeElement: HTMLElement }, |
1191 | | - shouldAlign:boolean = true, |
| 1246 | + shouldAlign: boolean = true, |
1192 | 1247 | placement: Placement = Placement.Bottom, |
1193 | 1248 | offset: number = 6 |
1194 | 1249 | ) => { |
|
0 commit comments