source: trip-planner-front/node_modules/@angular/material/fesm2015/tabs/testing.js@ e29cc2e

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

initial commit

  • Property mode set to 100644
File size: 10.7 KB
Line 
1import { __awaiter } from 'tslib';
2import { ContentContainerComponentHarness, HarnessPredicate, ComponentHarness, parallel } from '@angular/cdk/testing';
3
4/**
5 * @license
6 * Copyright Google LLC All Rights Reserved.
7 *
8 * Use of this source code is governed by an MIT-style license that can be
9 * found in the LICENSE file at https://angular.io/license
10 */
11/** Harness for interacting with a standard Angular Material tab-label in tests. */
12class MatTabHarness extends ContentContainerComponentHarness {
13 /**
14 * Gets a `HarnessPredicate` that can be used to search for a `MatTabHarness` that meets
15 * certain criteria.
16 * @param options Options for filtering which tab instances are considered a match.
17 * @return a `HarnessPredicate` configured with the given options.
18 */
19 static with(options = {}) {
20 return new HarnessPredicate(MatTabHarness, options)
21 .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabel(), label));
22 }
23 /** Gets the label of the tab. */
24 getLabel() {
25 return __awaiter(this, void 0, void 0, function* () {
26 return (yield this.host()).text();
27 });
28 }
29 /** Gets the aria-label of the tab. */
30 getAriaLabel() {
31 return __awaiter(this, void 0, void 0, function* () {
32 return (yield this.host()).getAttribute('aria-label');
33 });
34 }
35 /** Gets the value of the "aria-labelledby" attribute. */
36 getAriaLabelledby() {
37 return __awaiter(this, void 0, void 0, function* () {
38 return (yield this.host()).getAttribute('aria-labelledby');
39 });
40 }
41 /** Whether the tab is selected. */
42 isSelected() {
43 return __awaiter(this, void 0, void 0, function* () {
44 const hostEl = yield this.host();
45 return (yield hostEl.getAttribute('aria-selected')) === 'true';
46 });
47 }
48 /** Whether the tab is disabled. */
49 isDisabled() {
50 return __awaiter(this, void 0, void 0, function* () {
51 const hostEl = yield this.host();
52 return (yield hostEl.getAttribute('aria-disabled')) === 'true';
53 });
54 }
55 /** Selects the given tab by clicking on the label. Tab cannot be selected if disabled. */
56 select() {
57 return __awaiter(this, void 0, void 0, function* () {
58 yield (yield this.host()).click();
59 });
60 }
61 /** Gets the text content of the tab. */
62 getTextContent() {
63 return __awaiter(this, void 0, void 0, function* () {
64 const contentId = yield this._getContentId();
65 const contentEl = yield this.documentRootLocatorFactory().locatorFor(`#${contentId}`)();
66 return contentEl.text();
67 });
68 }
69 /**
70 * Gets a `HarnessLoader` that can be used to load harnesses for components within the tab's
71 * content area.
72 * @deprecated Use `getHarness` or `getChildLoader` instead.
73 * @breaking-change 12.0.0
74 */
75 getHarnessLoaderForContent() {
76 return __awaiter(this, void 0, void 0, function* () {
77 return this.getRootHarnessLoader();
78 });
79 }
80 getRootHarnessLoader() {
81 return __awaiter(this, void 0, void 0, function* () {
82 const contentId = yield this._getContentId();
83 return this.documentRootLocatorFactory().harnessLoaderFor(`#${contentId}`);
84 });
85 }
86 /** Gets the element id for the content of the current tab. */
87 _getContentId() {
88 return __awaiter(this, void 0, void 0, function* () {
89 const hostEl = yield this.host();
90 // Tabs never have an empty "aria-controls" attribute.
91 return (yield hostEl.getAttribute('aria-controls'));
92 });
93 }
94}
95/** The selector for the host element of a `MatTab` instance. */
96MatTabHarness.hostSelector = '.mat-tab-label';
97
98/**
99 * @license
100 * Copyright Google LLC All Rights Reserved.
101 *
102 * Use of this source code is governed by an MIT-style license that can be
103 * found in the LICENSE file at https://angular.io/license
104 */
105/** Harness for interacting with a standard mat-tab-group in tests. */
106class MatTabGroupHarness extends ComponentHarness {
107 /**
108 * Gets a `HarnessPredicate` that can be used to search for a `MatTabGroupHarness` that meets
109 * certain criteria.
110 * @param options Options for filtering which tab group instances are considered a match.
111 * @return a `HarnessPredicate` configured with the given options.
112 */
113 static with(options = {}) {
114 return new HarnessPredicate(MatTabGroupHarness, options)
115 .addOption('selectedTabLabel', options.selectedTabLabel, (harness, label) => __awaiter(this, void 0, void 0, function* () {
116 const selectedTab = yield harness.getSelectedTab();
117 return HarnessPredicate.stringMatches(yield selectedTab.getLabel(), label);
118 }));
119 }
120 /**
121 * Gets the list of tabs in the tab group.
122 * @param filter Optionally filters which tabs are included.
123 */
124 getTabs(filter = {}) {
125 return __awaiter(this, void 0, void 0, function* () {
126 return this.locatorForAll(MatTabHarness.with(filter))();
127 });
128 }
129 /** Gets the selected tab of the tab group. */
130 getSelectedTab() {
131 return __awaiter(this, void 0, void 0, function* () {
132 const tabs = yield this.getTabs();
133 const isSelected = yield parallel(() => tabs.map(t => t.isSelected()));
134 for (let i = 0; i < tabs.length; i++) {
135 if (isSelected[i]) {
136 return tabs[i];
137 }
138 }
139 throw new Error('No selected tab could be found.');
140 });
141 }
142 /**
143 * Selects a tab in this tab group.
144 * @param filter An optional filter to apply to the child tabs. The first tab matching the filter
145 * will be selected.
146 */
147 selectTab(filter = {}) {
148 return __awaiter(this, void 0, void 0, function* () {
149 const tabs = yield this.getTabs(filter);
150 if (!tabs.length) {
151 throw Error(`Cannot find mat-tab matching filter ${JSON.stringify(filter)}`);
152 }
153 yield tabs[0].select();
154 });
155 }
156}
157/** The selector for the host element of a `MatTabGroup` instance. */
158MatTabGroupHarness.hostSelector = '.mat-tab-group';
159
160/**
161 * @license
162 * Copyright Google LLC All Rights Reserved.
163 *
164 * Use of this source code is governed by an MIT-style license that can be
165 * found in the LICENSE file at https://angular.io/license
166 */
167/** Harness for interacting with a standard Angular Material tab link in tests. */
168class MatTabLinkHarness extends ComponentHarness {
169 /**
170 * Gets a `HarnessPredicate` that can be used to search for a `MatTabLinkHarness` that meets
171 * certain criteria.
172 * @param options Options for filtering which tab link instances are considered a match.
173 * @return a `HarnessPredicate` configured with the given options.
174 */
175 static with(options = {}) {
176 return new HarnessPredicate(MatTabLinkHarness, options)
177 .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabel(), label));
178 }
179 /** Gets the label of the link. */
180 getLabel() {
181 return __awaiter(this, void 0, void 0, function* () {
182 return (yield this.host()).text();
183 });
184 }
185 /** Whether the link is active. */
186 isActive() {
187 return __awaiter(this, void 0, void 0, function* () {
188 const host = yield this.host();
189 return host.hasClass('mat-tab-label-active');
190 });
191 }
192 /** Whether the link is disabled. */
193 isDisabled() {
194 return __awaiter(this, void 0, void 0, function* () {
195 const host = yield this.host();
196 return host.hasClass('mat-tab-disabled');
197 });
198 }
199 /** Clicks on the link. */
200 click() {
201 return __awaiter(this, void 0, void 0, function* () {
202 yield (yield this.host()).click();
203 });
204 }
205}
206/** The selector for the host element of a `MatTabLink` instance. */
207MatTabLinkHarness.hostSelector = '.mat-tab-link';
208
209/**
210 * @license
211 * Copyright Google LLC All Rights Reserved.
212 *
213 * Use of this source code is governed by an MIT-style license that can be
214 * found in the LICENSE file at https://angular.io/license
215 */
216/** Harness for interacting with a standard mat-tab-nav-bar in tests. */
217class MatTabNavBarHarness extends ComponentHarness {
218 /**
219 * Gets a `HarnessPredicate` that can be used to search for a `MatTabNavBar` that meets
220 * certain criteria.
221 * @param options Options for filtering which tab nav bar instances are considered a match.
222 * @return a `HarnessPredicate` configured with the given options.
223 */
224 static with(options = {}) {
225 return new HarnessPredicate(MatTabNavBarHarness, options);
226 }
227 /**
228 * Gets the list of links in the nav bar.
229 * @param filter Optionally filters which links are included.
230 */
231 getLinks(filter = {}) {
232 return __awaiter(this, void 0, void 0, function* () {
233 return this.locatorForAll(MatTabLinkHarness.with(filter))();
234 });
235 }
236 /** Gets the active link in the nav bar. */
237 getActiveLink() {
238 return __awaiter(this, void 0, void 0, function* () {
239 const links = yield this.getLinks();
240 const isActive = yield parallel(() => links.map(t => t.isActive()));
241 for (let i = 0; i < links.length; i++) {
242 if (isActive[i]) {
243 return links[i];
244 }
245 }
246 throw new Error('No active link could be found.');
247 });
248 }
249 /**
250 * Clicks a link inside the nav bar.
251 * @param filter An optional filter to apply to the child link. The first link matching the filter
252 * will be clicked.
253 */
254 clickLink(filter = {}) {
255 return __awaiter(this, void 0, void 0, function* () {
256 const tabs = yield this.getLinks(filter);
257 if (!tabs.length) {
258 throw Error(`Cannot find mat-tab-link matching filter ${JSON.stringify(filter)}`);
259 }
260 yield tabs[0].click();
261 });
262 }
263}
264/** The selector for the host element of a `MatTabNavBar` instance. */
265MatTabNavBarHarness.hostSelector = '.mat-tab-nav-bar';
266
267/**
268 * @license
269 * Copyright Google LLC All Rights Reserved.
270 *
271 * Use of this source code is governed by an MIT-style license that can be
272 * found in the LICENSE file at https://angular.io/license
273 */
274
275/**
276 * @license
277 * Copyright Google LLC All Rights Reserved.
278 *
279 * Use of this source code is governed by an MIT-style license that can be
280 * found in the LICENSE file at https://angular.io/license
281 */
282
283export { MatTabGroupHarness, MatTabHarness, MatTabLinkHarness, MatTabNavBarHarness };
284//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.