/** * @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, parallel, } from '@angular/cdk/testing'; import { MatTabHarness } from './tab-harness'; /** Harness for interacting with an MDC-based mat-tab-group in tests. */ export class MatTabGroupHarness extends ComponentHarness { /** The selector for the host element of a `MatTabGroup` instance. */ static { this.hostSelector = '.mat-mdc-tab-group'; } /** * Gets a `HarnessPredicate` that can be used to search for a tab group with specific attributes. * @param options Options for filtering which tab group instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options).addOption('selectedTabLabel', options.selectedTabLabel, async (harness, label) => { const selectedTab = await harness.getSelectedTab(); return HarnessPredicate.stringMatches(await selectedTab.getLabel(), label); }); } /** * Gets the list of tabs in the tab group. * @param filter Optionally filters which tabs are included. */ async getTabs(filter = {}) { return this.locatorForAll(MatTabHarness.with(filter))(); } /** Gets the selected tab of the tab group. */ async getSelectedTab() { const tabs = await this.getTabs(); const isSelected = await parallel(() => tabs.map(t => t.isSelected())); for (let i = 0; i < tabs.length; i++) { if (isSelected[i]) { return tabs[i]; } } throw new Error('No selected tab could be found.'); } /** * Selects a tab in this tab group. * @param filter An optional filter to apply to the child tabs. The first tab matching the filter * will be selected. */ async selectTab(filter = {}) { const tabs = await this.getTabs(filter); if (!tabs.length) { throw Error(`Cannot find mat-tab matching filter ${JSON.stringify(filter)}`); } await tabs[0].select(); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFiLWdyb3VwLWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvdGFicy90ZXN0aW5nL3RhYi1ncm91cC1oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQ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