@@ -11,7 +11,6 @@ import {
11
11
dispatchFakeEvent,
12
12
dispatchKeyboardEvent,
13
13
dispatchMouseEvent,
14
- dispatchTouchEvent,
15
14
patchElementFocus,
16
15
} from '../../cdk/testing/private';
17
16
import {
@@ -233,63 +232,6 @@ describe('MatTooltip', () => {
233
232
expect(tooltipDirective._getOverlayPosition().fallback.overlayX).toBe('end');
234
233
}));
235
234
236
- it('should position center-bottom by default', fakeAsync(() => {
237
- TestBed.resetTestingModule()
238
- .configureTestingModule({
239
- imports: [MatLegacyTooltipModule, OverlayModule],
240
- declarations: [WideTooltipDemo]
241
- })
242
- .compileComponents();
243
-
244
- const wideFixture = TestBed.createComponent(WideTooltipDemo);
245
- wideFixture.detectChanges();
246
- tooltipDirective = wideFixture.debugElement
247
- .query(By.css('button'))!
248
- .injector.get<MatLegacyTooltip>(MatLegacyTooltip);
249
- const button: HTMLButtonElement = wideFixture.nativeElement.querySelector('button');
250
- const triggerRect = button.getBoundingClientRect();
251
-
252
- dispatchMouseEvent(button, 'mouseenter', triggerRect.right - 100, triggerRect.top + 100);
253
- wideFixture.detectChanges();
254
- tick();
255
- expect(tooltipDirective._isTooltipVisible()).toBe(true);
256
-
257
- expect(tooltipDirective._overlayRef!.overlayElement.offsetLeft).toBeGreaterThan(triggerRect.left + 200);
258
- expect(tooltipDirective._overlayRef!.overlayElement.offsetLeft).toBeLessThan(triggerRect.left + 300);
259
- expect(tooltipDirective._overlayRef!.overlayElement.offsetTop).toBe(triggerRect.bottom);
260
- }));
261
-
262
- it('should be able to override the default positionAtOrigin', fakeAsync(() => {
263
- TestBed.resetTestingModule()
264
- .configureTestingModule({
265
- imports: [MatLegacyTooltipModule, OverlayModule],
266
- declarations: [WideTooltipDemo],
267
- providers: [
268
- {
269
- provide: MAT_TOOLTIP_DEFAULT_OPTIONS,
270
- useValue: {positionAtOrigin: true},
271
- },
272
- ],
273
- })
274
- .compileComponents();
275
-
276
- const wideFixture = TestBed.createComponent(WideTooltipDemo);
277
- wideFixture.detectChanges();
278
- tooltipDirective = wideFixture.debugElement
279
- .query(By.css('button'))!
280
- .injector.get<MatLegacyTooltip>(MatLegacyTooltip);
281
- const button: HTMLButtonElement = wideFixture.nativeElement.querySelector('button');
282
- const triggerRect = button.getBoundingClientRect();
283
-
284
- dispatchMouseEvent(button, 'mouseenter', triggerRect.left + 50, triggerRect.bottom - 10);
285
- wideFixture.detectChanges();
286
- tick();
287
- expect(tooltipDirective._isTooltipVisible()).toBe(true);
288
-
289
- expect(tooltipDirective._overlayRef!.overlayElement.offsetLeft).toBe(triggerRect.left + 28);
290
- expect(tooltipDirective._overlayRef!.overlayElement.offsetTop).toBe(triggerRect.bottom - 10);
291
- }));
292
-
293
235
it('should be able to disable tooltip interactivity', fakeAsync(() => {
294
236
TestBed.resetTestingModule()
295
237
.configureTestingModule({
@@ -1227,10 +1169,7 @@ describe('MatTooltip', () => {
1227
1169
fixture.detectChanges();
1228
1170
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
1229
1171
1230
- const triggerRect = button.getBoundingClientRect();
1231
- const offsetX = triggerRect.right - 10;
1232
- const offsetY = triggerRect.top + 10;
1233
- dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
1172
+ dispatchFakeEvent(button, 'touchstart');
1234
1173
fixture.detectChanges();
1235
1174
tick(250); // Halfway through the delay.
1236
1175
@@ -1249,10 +1188,7 @@ describe('MatTooltip', () => {
1249
1188
fixture.detectChanges();
1250
1189
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
1251
1190
1252
- const triggerRect = button.getBoundingClientRect();
1253
- const offsetX = triggerRect.right - 10;
1254
- const offsetY = triggerRect.top + 10;
1255
- dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
1191
+ dispatchFakeEvent(button, 'touchstart');
1256
1192
fixture.detectChanges();
1257
1193
tick(500); // Finish the delay.
1258
1194
fixture.detectChanges();
@@ -1265,10 +1201,7 @@ describe('MatTooltip', () => {
1265
1201
const fixture = TestBed.createComponent(BasicTooltipDemo);
1266
1202
fixture.detectChanges();
1267
1203
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
1268
- const triggerRect = button.getBoundingClientRect();
1269
- const offsetX = triggerRect.right - 10;
1270
- const offsetY = triggerRect.top + 10;
1271
- const event = dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
1204
+ const event = dispatchFakeEvent(button, 'touchstart');
1272
1205
fixture.detectChanges();
1273
1206
1274
1207
expect(event.defaultPrevented).toBe(false);
@@ -1279,10 +1212,7 @@ describe('MatTooltip', () => {
1279
1212
fixture.detectChanges();
1280
1213
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
1281
1214
1282
- const triggerRect = button.getBoundingClientRect();
1283
- const offsetX = triggerRect.right - 10;
1284
- const offsetY = triggerRect.top + 10;
1285
- dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
1215
+ dispatchFakeEvent(button, 'touchstart');
1286
1216
fixture.detectChanges();
1287
1217
tick(500); // Finish the open delay.
1288
1218
fixture.detectChanges();
@@ -1306,10 +1236,7 @@ describe('MatTooltip', () => {
1306
1236
fixture.detectChanges();
1307
1237
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
1308
1238
1309
- const triggerRect = button.getBoundingClientRect();
1310
- const offsetX = triggerRect.right - 10;
1311
- const offsetY = triggerRect.top + 10;
1312
- dispatchTouchEvent(button, 'touchstart', offsetX, offsetY, offsetX, offsetY);
1239
+ dispatchFakeEvent(button, 'touchstart');
1313
1240
fixture.detectChanges();
1314
1241
tick(500); // Finish the open delay.
1315
1242
fixture.detectChanges();
@@ -1474,16 +1401,16 @@ describe('MatTooltip', () => {
1474
1401
const fixture = TestBed.createComponent(BasicTooltipDemo);
1475
1402
fixture.detectChanges();
1476
1403
const button: HTMLButtonElement = fixture.nativeElement.querySelector('button');
1477
- const triggerRect = button.getBoundingClientRect();
1478
1404
1479
- dispatchMouseEvent (button, 'mouseenter', triggerRect.right - 10, triggerRect.top + 10 );
1405
+ dispatchFakeEvent (button, 'mouseenter');
1480
1406
fixture.detectChanges();
1481
1407
tick(500); // Finish the open delay.
1482
1408
fixture.detectChanges();
1483
1409
finishCurrentTooltipAnimation(overlayContainerElement, true);
1484
1410
assertTooltipInstance(fixture.componentInstance.tooltip, true);
1485
1411
1486
1412
// Simulate the pointer over the trigger.
1413
+ const triggerRect = button.getBoundingClientRect();
1487
1414
const wheelEvent = createFakeEvent('wheel');
1488
1415
Object.defineProperties(wheelEvent, {
1489
1416
clientX: {get: () => triggerRect.left + 1},
@@ -1629,17 +1556,6 @@ class TooltipDemoWithoutPositionBinding {
1629
1556
@ViewChild('button') button: ElementRef<HTMLButtonElement>;
1630
1557
}
1631
1558
1632
- @Component({
1633
- selector: 'app',
1634
- styles: [`button { width: 500px; height: 500px; }`],
1635
- template: `<button #button [matTooltip]="message">Button</button>`,
1636
- })
1637
- class WideTooltipDemo {
1638
- message = 'Test';
1639
- @ViewChild(MatLegacyTooltip) tooltip: MatLegacyTooltip;
1640
- @ViewChild('button') button: ElementRef<HTMLButtonElement>;
1641
- }
1642
-
1643
1559
/** Asserts whether a tooltip directive has a tooltip instance. */
1644
1560
function assertTooltipInstance(tooltip: MatLegacyTooltip, shouldExist: boolean): void {
1645
1561
// Note that we have to cast this to a boolean, because Jasmine will go into an infinite loop
0 commit comments