/** * @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 { ContentContainerComponentHarness, HarnessPredicate, } from '@angular/cdk/testing'; /** Harness for interacting with an MDC_based Angular Material tab in tests. */ export class MatTabHarness extends ContentContainerComponentHarness { /** The selector for the host element of a `MatTab` instance. */ static { this.hostSelector = '.mat-mdc-tab'; } /** * Gets a `HarnessPredicate` that can be used to search for a tab with specific attributes. * @param options Options for filtering which tab instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options) .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabel(), label)) .addOption('selected', options.selected, async (harness, selected) => (await harness.isSelected()) == selected); } /** Gets the label of the tab. */ async getLabel() { return (await this.host()).text(); } /** Gets the aria-label of the tab. */ async getAriaLabel() { return (await this.host()).getAttribute('aria-label'); } /** Gets the value of the "aria-labelledby" attribute. */ async getAriaLabelledby() { return (await this.host()).getAttribute('aria-labelledby'); } /** Whether the tab is selected. */ async isSelected() { const hostEl = await this.host(); return (await hostEl.getAttribute('aria-selected')) === 'true'; } /** Whether the tab is disabled. */ async isDisabled() { const hostEl = await this.host(); return (await hostEl.getAttribute('aria-disabled')) === 'true'; } /** Selects the given tab by clicking on the label. Tab cannot be selected if disabled. */ async select() { await (await this.host()).click('center'); } /** Gets the text content of the tab. */ async getTextContent() { const contentId = await this._getContentId(); const contentEl = await this.documentRootLocatorFactory().locatorFor(`#${contentId}`)(); return contentEl.text(); } async getRootHarnessLoader() { const contentId = await this._getContentId(); return this.documentRootLocatorFactory().harnessLoaderFor(`#${contentId}`); } /** Gets the element id for the content of the current tab. */ async _getContentId() { const hostEl = await this.host(); // Tabs never have an empty "aria-controls" attribute. return (await hostEl.getAttribute('aria-controls')); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFiLWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIi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