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

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

initial commit

  • Property mode set to 100644
File size: 10.8 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 { ContentContainerComponentHarness, HarnessPredicate, } from '@angular/cdk/testing';
10/** Harness for interacting with a standard Angular Material tab-label in tests. */
11export class MatTabHarness extends ContentContainerComponentHarness {
12 /**
13 * Gets a `HarnessPredicate` that can be used to search for a `MatTabHarness` that meets
14 * certain criteria.
15 * @param options Options for filtering which tab instances are considered a match.
16 * @return a `HarnessPredicate` configured with the given options.
17 */
18 static with(options = {}) {
19 return new HarnessPredicate(MatTabHarness, options)
20 .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabel(), label));
21 }
22 /** Gets the label of the tab. */
23 getLabel() {
24 return __awaiter(this, void 0, void 0, function* () {
25 return (yield this.host()).text();
26 });
27 }
28 /** Gets the aria-label of the tab. */
29 getAriaLabel() {
30 return __awaiter(this, void 0, void 0, function* () {
31 return (yield this.host()).getAttribute('aria-label');
32 });
33 }
34 /** Gets the value of the "aria-labelledby" attribute. */
35 getAriaLabelledby() {
36 return __awaiter(this, void 0, void 0, function* () {
37 return (yield this.host()).getAttribute('aria-labelledby');
38 });
39 }
40 /** Whether the tab is selected. */
41 isSelected() {
42 return __awaiter(this, void 0, void 0, function* () {
43 const hostEl = yield this.host();
44 return (yield hostEl.getAttribute('aria-selected')) === 'true';
45 });
46 }
47 /** Whether the tab is disabled. */
48 isDisabled() {
49 return __awaiter(this, void 0, void 0, function* () {
50 const hostEl = yield this.host();
51 return (yield hostEl.getAttribute('aria-disabled')) === 'true';
52 });
53 }
54 /** Selects the given tab by clicking on the label. Tab cannot be selected if disabled. */
55 select() {
56 return __awaiter(this, void 0, void 0, function* () {
57 yield (yield this.host()).click();
58 });
59 }
60 /** Gets the text content of the tab. */
61 getTextContent() {
62 return __awaiter(this, void 0, void 0, function* () {
63 const contentId = yield this._getContentId();
64 const contentEl = yield this.documentRootLocatorFactory().locatorFor(`#${contentId}`)();
65 return contentEl.text();
66 });
67 }
68 /**
69 * Gets a `HarnessLoader` that can be used to load harnesses for components within the tab's
70 * content area.
71 * @deprecated Use `getHarness` or `getChildLoader` instead.
72 * @breaking-change 12.0.0
73 */
74 getHarnessLoaderForContent() {
75 return __awaiter(this, void 0, void 0, function* () {
76 return this.getRootHarnessLoader();
77 });
78 }
79 getRootHarnessLoader() {
80 return __awaiter(this, void 0, void 0, function* () {
81 const contentId = yield this._getContentId();
82 return this.documentRootLocatorFactory().harnessLoaderFor(`#${contentId}`);
83 });
84 }
85 /** Gets the element id for the content of the current tab. */
86 _getContentId() {
87 return __awaiter(this, void 0, void 0, function* () {
88 const hostEl = yield this.host();
89 // Tabs never have an empty "aria-controls" attribute.
90 return (yield hostEl.getAttribute('aria-controls'));
91 });
92 }
93}
94/** The selector for the host element of a `MatTab` instance. */
95MatTabHarness.hostSelector = '.mat-tab-label';
96//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGFiLWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvdGFicy90ZXN0aW5nL3RhYi1oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRzs7QUFFSCxPQUFPLEVBQ0wsZ0NBQWdDLEVBRWhDLGdCQUFnQixHQUNqQixNQUFNLHNCQUFzQixDQUFDO0FBRzlCLG1GQUFtRjtBQUNuRixNQUFNLE9BQU8sYUFBYyxTQUFRLGdDQUF3QztJQUl6RTs7Ozs7T0FLRztJQUNILE1BQU0sQ0FBQyxJQUFJLENBQUMsV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1lbnQgaWQgZm9yIHRoZSBjb250ZW50IG9mIHRoZSBjdXJyZW50IHRhYi4gKi9cbiAgcHJpdmF0ZSBhc3luYyBfZ2V0Q29udGVudElkKCk6IFByb21pc2U8c3RyaW5nPiB7XG4gICAgY29uc3QgaG9zdEVsID0gYXdhaXQgdGhpcy5ob3N0KCk7XG4gICAgLy8gVGFicyBuZXZlciBoYXZlIGFuIGVtcHR5IFwiYXJpYS1jb250cm9sc1wiIGF0dHJpYnV0ZS5cbiAgICByZXR1cm4gKGF3YWl0IGhvc3RFbC5nZXRBdHRyaWJ1dGUoJ2FyaWEtY29udHJvbHMnKSkhO1xuICB9XG59XG4iXX0=
Note: See TracBrowser for help on using the repository browser.