UNPKG

@angular/material

Version:
1 lines 5.03 kB
{"version":3,"file":"tooltip-testing.mjs","sources":["../../../../../darwin_arm64-fastbuild-ST-fdfa778d11ba/bin/src/material/tooltip/testing/tooltip-harness.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.dev/license\n */\n\nimport {\n ComponentHarness,\n ComponentHarnessConstructor,\n HarnessPredicate,\n} from '@angular/cdk/testing';\nimport {TooltipHarnessFilters} from './tooltip-harness-filters';\n\n/** Harness for interacting with a mat-tooltip in tests. */\nexport class MatTooltipHarness extends ComponentHarness {\n static hostSelector = '.mat-mdc-tooltip-trigger';\n\n private _optionalPanel = this.documentRootLocatorFactory().locatorForOptional('.mat-mdc-tooltip');\n private _hiddenClass = 'mat-mdc-tooltip-hide';\n private _disabledClass = 'mat-mdc-tooltip-disabled';\n private _showAnimationName = 'mat-mdc-tooltip-show';\n private _hideAnimationName = 'mat-mdc-tooltip-hide';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a tooltip trigger with specific\n * attributes.\n * @param options Options for narrowing the search.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with<T extends MatTooltipHarness>(\n this: ComponentHarnessConstructor<T>,\n options: TooltipHarnessFilters = {},\n ): HarnessPredicate<T> {\n return new HarnessPredicate(this, options);\n }\n\n /** Shows the tooltip. */\n async show(): Promise<void> {\n const host = await this.host();\n\n // We need to dispatch both `touchstart` and a hover event, because the tooltip binds\n // different events depending on the device. The `changedTouches` is there in case the\n // element has ripples.\n await host.dispatchEvent('touchstart', {changedTouches: []});\n await host.hover();\n const panel = await this._optionalPanel();\n await panel?.dispatchEvent('animationend', {animationName: this._showAnimationName});\n }\n\n /** Hides the tooltip. */\n async hide(): Promise<void> {\n const host = await this.host();\n\n // We need to dispatch both `touchstart` and a hover event, because\n // the tooltip binds different events depending on the device.\n await host.dispatchEvent('touchend');\n await host.mouseAway();\n const panel = await this._optionalPanel();\n await panel?.dispatchEvent('animationend', {animationName: this._hideAnimationName});\n }\n\n /** Gets whether the tooltip is open. */\n async isOpen(): Promise<boolean> {\n const panel = await this._optionalPanel();\n return !!panel && !(await panel.hasClass(this._hiddenClass));\n }\n\n /** Gets whether the tooltip is disabled */\n async isDisabled(): Promise<boolean> {\n const host = await this.host();\n return host.hasClass(this._disabledClass);\n }\n\n /** Gets a promise for the tooltip panel's text. */\n async getTooltipText(): Promise<string> {\n const panel = await this._optionalPanel();\n return panel ? panel.text() : '';\n }\n}\n"],"names":["MatTooltipHarness","ComponentHarness","hostSelector","_optionalPanel","documentRootLocatorFactory","locatorForOptional","_hiddenClass","_disabledClass","_showAnimationName","_hideAnimationName","with","options","HarnessPredicate","show","host","dispatchEvent","changedTouches","hover","panel","animationName","hide","mouseAway","isOpen","hasClass","isDisabled","getTooltipText","text"],"mappings":";;AAgBM,MAAOA,iBAAkB,SAAQC,gBAAgB,CAAA;EACrD,OAAOC,YAAY,GAAG,0BAA0B;EAExCC,cAAc,GAAG,IAAI,CAACC,0BAA0B,EAAE,CAACC,kBAAkB,CAAC,kBAAkB,CAAC;AACzFC,EAAAA,YAAY,GAAG,sBAAsB;AACrCC,EAAAA,cAAc,GAAG,0BAA0B;AAC3CC,EAAAA,kBAAkB,GAAG,sBAAsB;AAC3CC,EAAAA,kBAAkB,GAAG,sBAAsB;AAQnD,EAAA,OAAOC,IAAIA,CAETC,OAAA,GAAiC,EAAE,EAAA;AAEnC,IAAA,OAAO,IAAIC,gBAAgB,CAAC,IAAI,EAAED,OAAO,CAAC;AAC5C;EAGA,MAAME,IAAIA,GAAA;AACR,IAAA,MAAMC,IAAI,GAAG,MAAM,IAAI,CAACA,IAAI,EAAE;AAK9B,IAAA,MAAMA,IAAI,CAACC,aAAa,CAAC,YAAY,EAAE;AAACC,MAAAA,cAAc,EAAE;AAAG,KAAA,CAAC;AAC5D,IAAA,MAAMF,IAAI,CAACG,KAAK,EAAE;AAClB,IAAA,MAAMC,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