source: trip-planner-front/node_modules/@angular/material/esm2015/tabs/testing/tab-group-harness.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 8.0 KB
Line 
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 */
8import { __awaiter } from "tslib";
9import { ComponentHarness, HarnessPredicate, parallel } from '@angular/cdk/testing';
10import { MatTabHarness } from './tab-harness';
11/** Harness for interacting with a standard mat-tab-group in tests. */
12export class MatTabGroupHarness extends ComponentHarness {
13 /**
14 * Gets a `HarnessPredicate` that can be used to search for a `MatTabGroupHarness` that meets
15 * certain criteria.
16 * @param options Options for filtering which tab group instances are considered a match.
17 * @return a `HarnessPredicate` configured with the given options.
18 */
19 static with(options = {}) {
20 return new HarnessPredicate(MatTabGroupHarness, options)
21 .addOption('selectedTabLabel', options.selectedTabLabel, (harness, label) => __awaiter(this, void 0, void 0, function* () {
22 const selectedTab = yield harness.getSelectedTab();
23 return HarnessPredicate.stringMatches(yield selectedTab.getLabel(), label);
24 }));
25 }
26 /**
27 * Gets the list of tabs in the tab group.
28 * @param filter Optionally filters which tabs are included.
29 */
30 getTabs(filter = {}) {
31 return __awaiter(this, void 0, void 0, function* () {
32 return this.locatorForAll(MatTabHarness.with(filter))();
33 });
34 }
35 /** Gets the selected tab of the tab group. */
36 getSelectedTab() {
37 return __awaiter(this, void 0, void 0, function* () {
38 const tabs = yield this.getTabs();
39 const isSelected = yield parallel(() => tabs.map(t => t.isSelected()));
40 for (let i = 0; i < tabs.length; i++) {
41 if (isSelected[i]) {
42 return tabs[i];
43 }
44 }
45 throw new Error('No selected tab could be found.');
46 });
47 }
48 /**
49 * Selects a tab in this tab group.
50 * @param filter An optional filter to apply to the child tabs. The first tab matching the filter
51 * will be selected.
52 */
53 selectTab(filter = {}) {
54 return __awaiter(this, void 0, void 0, function* () {
55 const tabs = yield this.getTabs(filter);
56 if (!tabs.length) {
57 throw Error(`Cannot find mat-tab matching filter ${JSON.stringify(filter)}`);
58 }
59 yield tabs[0].select();
60 });
61 }
62}
63/** The selector for the host element of a `MatTabGroup` instance. */
64MatTabGroupHarness.hostSelector = '.mat-tab-group';
65//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFiLWdyb3VwLWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvdGFicy90ZXN0aW5nL3RhYi1ncm91cC1oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRzs7QUFFSCxPQUFPLEVBQUMsZ0JBQWdCLEVBQUUsZ0JBQWdCLEVBQUUsUUFBUSxFQUFDLE1BQU0sc0JBQXNCLENBQUM7QUFFbEYsT0FBTyxFQUFDLGFBQWEsRUFBQyxNQUFNLGVBQWUsQ0FBQztBQUU1QyxzRUFBc0U7QUFDdEUsTUFBTSxPQUFPLGtCQUFtQixTQUFRLGdCQUFnQjtJQUl0RDs7Ozs7T0FLRztJQUNILE1BQU0sQ0FBQyxJQUFJLENBQUMsVUFBa0MsRUFBRTtRQUM5QyxPQUFPLElBQUksZ0JBQWdCLENBQUMsa0JBQWtCLEVBQUUsT0FBTyxDQUFDO2FBQ25ELFNBQVMsQ0FBQyxrQkFBa0IsRUFBRSxPQUFPLENBQUMsZ0JBQWdCLEVBQUUsQ0FBTyxPQUFPLEVBQUUsS0FBSyxFQUFFLEVBQUU7WUFDaEYsTUFBTSxXQUFXLEdBQUcsTUFBTSxPQUFPLENBQUMsY0FBYyxFQUFFLENBQUM7WUFDbkQsT0FBTyxnQkFBZ0IsQ0FBQyxhQUFhLENBQUMsTUFBTSxXQUFXLENBQUMsUUFBUSxFQUFFLEVBQUUsS0FBSyxDQUFDLENBQUM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