/** * @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 a standard Angular Material tab-label in tests. * @deprecated Use `MatTabHarness` from `@angular/material/tabs/testing` instead. See https://material.angular.io/guide/mdc-migration for information about migrating. * @breaking-change 17.0.0 */ export class MatLegacyTabHarness extends ContentContainerComponentHarness { /** The selector for the host element of a `MatTab` instance. */ static { this.hostSelector = '.mat-tab-label'; } /** * Gets a `HarnessPredicate` that can be used to search for a `MatTabHarness` that meets * certain criteria. * @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(MatLegacyTabHarness, 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(); } /** 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('a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