MCPcopy
hub / github.com/angular/components / MatTooltipHarness

Class MatTooltipHarness

src/material/tooltip/testing/tooltip-harness.ts:17–81  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16/** Harness for interacting with a mat-tooltip in tests. */
17export class MatTooltipHarness extends ComponentHarness {
18 static hostSelector = '.mat-mdc-tooltip-trigger';
19
20 private _optionalPanel = this.documentRootLocatorFactory().locatorForOptional('.mat-mdc-tooltip');
21 private _hiddenClass = 'mat-mdc-tooltip-hide';
22 private _disabledClass = 'mat-mdc-tooltip-disabled';
23 private _showAnimationName = 'mat-mdc-tooltip-show';
24 private _hideAnimationName = 'mat-mdc-tooltip-hide';
25
26 /**
27 * Gets a `HarnessPredicate` that can be used to search for a tooltip trigger with specific
28 * attributes.
29 * @param options Options for narrowing the search.
30 * @return a `HarnessPredicate` configured with the given options.
31 */
32 static with<T extends MatTooltipHarness>(
33 this: ComponentHarnessConstructor<T>,
34 options: TooltipHarnessFilters = {},
35 ): HarnessPredicate<T> {
36 return new HarnessPredicate(this, options);
37 }
38
39 /** Shows the tooltip. */
40 async show(): Promise<void> {
41 const host = await this.host();
42
43 // We need to dispatch both `touchstart` and a hover event, because the tooltip binds
44 // different events depending on the device. The `changedTouches` is there in case the
45 // element has ripples.
46 await host.dispatchEvent('touchstart', {changedTouches: []});
47 await host.hover();
48 const panel = await this._optionalPanel();
49 await panel?.dispatchEvent('animationend', {animationName: this._showAnimationName});
50 }
51
52 /** Hides the tooltip. */
53 async hide(): Promise<void> {
54 const host = await this.host();
55
56 // We need to dispatch both `touchstart` and a hover event, because
57 // the tooltip binds different events depending on the device.
58 await host.dispatchEvent('touchend');
59 await host.mouseAway();
60 const panel = await this._optionalPanel();
61 await panel?.dispatchEvent('animationend', {animationName: this._hideAnimationName});
62 }
63
64 /** Gets whether the tooltip is open. */
65 async isOpen(): Promise<boolean> {
66 const panel = await this._optionalPanel();
67 return !!panel && !(await panel.hasClass(this._hiddenClass));
68 }
69
70 /** Gets whether the tooltip is disabled */
71 async isDisabled(): Promise<boolean> {
72 const host = await this.host();
73 return host.hasClass(this._disabledClass);
74 }

Callers

nothing calls this directly

Calls 2

locatorForOptionalMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…