[6a3a178] | 1 | /**
|
---|
| 2 | * @license
|
---|
| 3 | * Copyright Google LLC All Rights Reserved.
|
---|
| 4 | *
|
---|
| 5 | * Use of this source code is governed by an MIT-style license that can be
|
---|
| 6 | * found in the LICENSE file at https://angular.io/license
|
---|
| 7 | */
|
---|
| 8 | import { __awaiter } from "tslib";
|
---|
| 9 | import { ComponentHarness, HarnessPredicate, parallel } from '@angular/cdk/testing';
|
---|
| 10 | import { MatTabLinkHarness } from './tab-link-harness';
|
---|
| 11 | /** Harness for interacting with a standard mat-tab-nav-bar in tests. */
|
---|
| 12 | export class MatTabNavBarHarness extends ComponentHarness {
|
---|
| 13 | /**
|
---|
| 14 | * Gets a `HarnessPredicate` that can be used to search for a `MatTabNavBar` that meets
|
---|
| 15 | * certain criteria.
|
---|
| 16 | * @param options Options for filtering which tab nav bar instances are considered a match.
|
---|
| 17 | * @return a `HarnessPredicate` configured with the given options.
|
---|
| 18 | */
|
---|
| 19 | static with(options = {}) {
|
---|
| 20 | return new HarnessPredicate(MatTabNavBarHarness, options);
|
---|
| 21 | }
|
---|
| 22 | /**
|
---|
| 23 | * Gets the list of links in the nav bar.
|
---|
| 24 | * @param filter Optionally filters which links are included.
|
---|
| 25 | */
|
---|
| 26 | getLinks(filter = {}) {
|
---|
| 27 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 28 | return this.locatorForAll(MatTabLinkHarness.with(filter))();
|
---|
| 29 | });
|
---|
| 30 | }
|
---|
| 31 | /** Gets the active link in the nav bar. */
|
---|
| 32 | getActiveLink() {
|
---|
| 33 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 34 | const links = yield this.getLinks();
|
---|
| 35 | const isActive = yield parallel(() => links.map(t => t.isActive()));
|
---|
| 36 | for (let i = 0; i < links.length; i++) {
|
---|
| 37 | if (isActive[i]) {
|
---|
| 38 | return links[i];
|
---|
| 39 | }
|
---|
| 40 | }
|
---|
| 41 | throw new Error('No active link could be found.');
|
---|
| 42 | });
|
---|
| 43 | }
|
---|
| 44 | /**
|
---|
| 45 | * Clicks a link inside the nav bar.
|
---|
| 46 | * @param filter An optional filter to apply to the child link. The first link matching the filter
|
---|
| 47 | * will be clicked.
|
---|
| 48 | */
|
---|
| 49 | clickLink(filter = {}) {
|
---|
| 50 | return __awaiter(this, void 0, void 0, function* () {
|
---|
| 51 | const tabs = yield this.getLinks(filter);
|
---|
| 52 | if (!tabs.length) {
|
---|
| 53 | throw Error(`Cannot find mat-tab-link matching filter ${JSON.stringify(filter)}`);
|
---|
| 54 | }
|
---|
| 55 | yield tabs[0].click();
|
---|
| 56 | });
|
---|
| 57 | }
|
---|
| 58 | }
|
---|
| 59 | /** The selector for the host element of a `MatTabNavBar` instance. */
|
---|
| 60 | MatTabNavBarHarness.hostSelector = '.mat-tab-nav-bar';
|
---|
| 61 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFiLW5hdi1iYXItaGFybmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC90YWJzL3Rlc3RpbmcvdGFiLW5hdi1iYXItaGFybmVzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7O0FBRUgsT0FBTyxFQUFDLGdCQUFnQixFQUFFLGdCQUFnQixFQUFFLFFBQVEsRUFBQyxNQUFNLHNCQUFzQixDQUFDO0FBRWxGLE9BQU8sRUFBQyxpQkFBaUIsRUFBQyxNQUFNLG9CQUFvQixDQUFDO0FBRXJELHdFQUF3RTtBQUN4RSxNQUFNLE9BQU8sbUJBQW9CLFNBQVEsZ0JBQWdCO0lBSXZEOzs7OztPQUtHO0lBQ0gsTUFBTSxDQUFDLElBQUksQ0FBQyxVQUFtQyxFQUFFO1FBQy9DLE9BQU8sSUFBSSxnQkFBZ0IsQ0FBQyxtQkFBbUIsRUFBRSxPQUFPLENBQUMsQ0FBQ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