@angular/material
Version:
Angular Material
62 lines • 9.11 kB
JavaScript
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { ComponentHarness, HarnessPredicate, } from '@angular/cdk/testing';
export class _MatTooltipHarnessBase extends ComponentHarness {
/** Shows the tooltip. */
async show() {
const host = await this.host();
// We need to dispatch both `touchstart` and a hover event, because the tooltip binds
// different events depending on the device. The `changedTouches` is there in case the
// element has ripples.
await host.dispatchEvent('touchstart', { changedTouches: [] });
await host.hover();
const panel = await this._optionalPanel();
await panel?.dispatchEvent('animationend', { animationName: this._showAnimationName });
}
/** Hides the tooltip. */
async hide() {
const host = await this.host();
// We need to dispatch both `touchstart` and a hover event, because
// the tooltip binds different events depending on the device.
await host.dispatchEvent('touchend');
await host.mouseAway();
const panel = await this._optionalPanel();
await panel?.dispatchEvent('animationend', { animationName: this._hideAnimationName });
}
/** Gets whether the tooltip is open. */
async isOpen() {
const panel = await this._optionalPanel();
return !!panel && !(await panel.hasClass(this._hiddenClass));
}
/** Gets a promise for the tooltip panel's text. */
async getTooltipText() {
const panel = await this._optionalPanel();
return panel ? panel.text() : '';
}
}
/** Harness for interacting with a standard mat-tooltip in tests. */
export class MatTooltipHarness extends _MatTooltipHarnessBase {
constructor() {
super(...arguments);
this._optionalPanel = this.documentRootLocatorFactory().locatorForOptional('.mat-mdc-tooltip');
this._hiddenClass = 'mat-mdc-tooltip-hide';
this._showAnimationName = 'mat-mdc-tooltip-show';
this._hideAnimationName = 'mat-mdc-tooltip-hide';
}
/**
* Gets a `HarnessPredicate` that can be used to search for a tooltip trigger with specific
* attributes.
* @param options Options for narrowing the search.
* @return a `HarnessPredicate` configured with the given options.
*/
static with(options = {}) {
return new HarnessPredicate(this, options);
}
}
MatTooltipHarness.hostSelector = '.mat-mdc-tooltip-trigger';
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidG9vbHRpcC1oYXJ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