source: trip-planner-front/node_modules/@angular/material/fesm2015/list/testing.js@ 6a80231

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

initial commit

  • Property mode set to 100644
File size: 20.8 KB
RevLine 
[6a3a178]1import { __awaiter } from 'tslib';
2import { HarnessPredicate, ComponentHarness, ContentContainerComponentHarness, parallel } from '@angular/cdk/testing';
3import { MatDividerHarness } from '@angular/material/divider/testing';
4
5/**
6 * @license
7 * Copyright Google LLC All Rights Reserved.
8 *
9 * Use of this source code is governed by an MIT-style license that can be
10 * found in the LICENSE file at https://angular.io/license
11 */
12const iconSelector = '.mat-list-icon';
13const avatarSelector = '.mat-list-avatar';
14/**
15 * Gets a `HarnessPredicate` that applies the given `BaseListItemHarnessFilters` to the given
16 * list item harness.
17 * @template H The type of list item harness to create a predicate for.
18 * @param harnessType A constructor for a list item harness.
19 * @param options An instance of `BaseListItemHarnessFilters` to apply.
20 * @return A `HarnessPredicate` for the given harness type with the given options applied.
21 */
22function getListItemPredicate(harnessType, options) {
23 return new HarnessPredicate(harnessType, options)
24 .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
25}
26/** Harness for interacting with a list subheader. */
27class MatSubheaderHarness extends ComponentHarness {
28 static with(options = {}) {
29 return new HarnessPredicate(MatSubheaderHarness, options)
30 .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
31 }
32 /** Gets the full text content of the list item (including text from any font icons). */
33 getText() {
34 return __awaiter(this, void 0, void 0, function* () {
35 return (yield this.host()).text();
36 });
37 }
38}
39MatSubheaderHarness.hostSelector = '.mat-subheader';
40/**
41 * Shared behavior among the harnesses for the various `MatListItem` flavors.
42 * @docs-private
43 */
44class MatListItemHarnessBase extends ContentContainerComponentHarness {
45 constructor() {
46 super(...arguments);
47 this._lines = this.locatorForAll('.mat-line');
48 this._avatar = this.locatorForOptional(avatarSelector);
49 this._icon = this.locatorForOptional(iconSelector);
50 }
51 /** Gets the full text content of the list item. */
52 getText() {
53 return __awaiter(this, void 0, void 0, function* () {
54 return (yield this.host()).text({ exclude: `${iconSelector}, ${avatarSelector}` });
55 });
56 }
57 /** Gets the lines of text (`mat-line` elements) in this nav list item. */
58 getLinesText() {
59 return __awaiter(this, void 0, void 0, function* () {
60 const lines = yield this._lines();
61 return parallel(() => lines.map(l => l.text()));
62 });
63 }
64 /** Whether this list item has an avatar. */
65 hasAvatar() {
66 return __awaiter(this, void 0, void 0, function* () {
67 return !!(yield this._avatar());
68 });
69 }
70 /** Whether this list item has an icon. */
71 hasIcon() {
72 return __awaiter(this, void 0, void 0, function* () {
73 return !!(yield this._icon());
74 });
75 }
76 /**
77 * Gets a `HarnessLoader` used to get harnesses within the list item's content.
78 * @deprecated Use `getChildLoader(MatListItemSection.CONTENT)` or `getHarness` instead.
79 * @breaking-change 12.0.0
80 */
81 getHarnessLoaderForContent() {
82 return __awaiter(this, void 0, void 0, function* () {
83 return this.getChildLoader(".mat-list-item-content" /* CONTENT */);
84 });
85 }
86}
87
88/**
89 * @license
90 * Copyright Google LLC All Rights Reserved.
91 *
92 * Use of this source code is governed by an MIT-style license that can be
93 * found in the LICENSE file at https://angular.io/license
94 */
95/**
96 * Shared behavior among the harnesses for the various `MatList` flavors.
97 * @template T A constructor type for a list item harness type used by this list harness.
98 * @template C The list item harness type that `T` constructs.
99 * @template F The filter type used filter list item harness of type `C`.
100 * @docs-private
101 */
102class MatListHarnessBase extends ComponentHarness {
103 /**
104 * Gets a list of harnesses representing the items in this list.
105 * @param filters Optional filters used to narrow which harnesses are included
106 * @return The list of items matching the given filters.
107 */
108 getItems(filters) {
109 return __awaiter(this, void 0, void 0, function* () {
110 return this.locatorForAll(this._itemHarness.with(filters))();
111 });
112 }
113 /**
114 * Gets a list of `ListSection` representing the list items grouped by subheaders. If the list has
115 * no subheaders it is represented as a single `ListSection` with an undefined `heading` property.
116 * @param filters Optional filters used to narrow which list item harnesses are included
117 * @return The list of items matching the given filters, grouped into sections by subheader.
118 */
119 getItemsGroupedBySubheader(filters) {
120 return __awaiter(this, void 0, void 0, function* () {
121 const listSections = [];
122 let currentSection = { items: [] };
123 const itemsAndSubheaders = yield this.getItemsWithSubheadersAndDividers({ item: filters, divider: false });
124 for (const itemOrSubheader of itemsAndSubheaders) {
125 if (itemOrSubheader instanceof MatSubheaderHarness) {
126 if (currentSection.heading !== undefined || currentSection.items.length) {
127 listSections.push(currentSection);
128 }
129 currentSection = { heading: itemOrSubheader.getText(), items: [] };
130 }
131 else {
132 currentSection.items.push(itemOrSubheader);
133 }
134 }
135 if (currentSection.heading !== undefined || currentSection.items.length ||
136 !listSections.length) {
137 listSections.push(currentSection);
138 }
139 // Concurrently wait for all sections to resolve their heading if present.
140 return parallel(() => listSections.map((s) => __awaiter(this, void 0, void 0, function* () { return ({ items: s.items, heading: yield s.heading }); })));
141 });
142 }
143 /**
144 * Gets a list of sub-lists representing the list items grouped by dividers. If the list has no
145 * dividers it is represented as a list with a single sub-list.
146 * @param filters Optional filters used to narrow which list item harnesses are included
147 * @return The list of items matching the given filters, grouped into sub-lists by divider.
148 */
149 getItemsGroupedByDividers(filters) {
150 return __awaiter(this, void 0, void 0, function* () {
151 const listSections = [[]];
152 const itemsAndDividers = yield this.getItemsWithSubheadersAndDividers({ item: filters, subheader: false });
153 for (const itemOrDivider of itemsAndDividers) {
154 if (itemOrDivider instanceof MatDividerHarness) {
155 listSections.push([]);
156 }
157 else {
158 listSections[listSections.length - 1].push(itemOrDivider);
159 }
160 }
161 return listSections;
162 });
163 }
164 getItemsWithSubheadersAndDividers(filters = {}) {
165 return __awaiter(this, void 0, void 0, function* () {
166 const query = [];
167 if (filters.item !== false) {
168 query.push(this._itemHarness.with(filters.item || {}));
169 }
170 if (filters.subheader !== false) {
171 query.push(MatSubheaderHarness.with(filters.subheader));
172 }
173 if (filters.divider !== false) {
174 query.push(MatDividerHarness.with(filters.divider));
175 }
176 return this.locatorForAll(...query)();
177 });
178 }
179}
180
181/**
182 * @license
183 * Copyright Google LLC All Rights Reserved.
184 *
185 * Use of this source code is governed by an MIT-style license that can be
186 * found in the LICENSE file at https://angular.io/license
187 */
188/** Harness for interacting with a standard mat-action-list in tests. */
189class MatActionListHarness extends MatListHarnessBase {
190 constructor() {
191 super(...arguments);
192 this._itemHarness = MatActionListItemHarness;
193 }
194 /**
195 * Gets a `HarnessPredicate` that can be used to search for a `MatActionListHarness` that meets
196 * certain criteria.
197 * @param options Options for filtering which action list instances are considered a match.
198 * @return a `HarnessPredicate` configured with the given options.
199 */
200 static with(options = {}) {
201 return new HarnessPredicate(MatActionListHarness, options);
202 }
203}
204/** The selector for the host element of a `MatActionList` instance. */
205MatActionListHarness.hostSelector = 'mat-action-list.mat-list';
206/** Harness for interacting with an action list item. */
207class MatActionListItemHarness extends MatListItemHarnessBase {
208 /**
209 * Gets a `HarnessPredicate` that can be used to search for a `MatActionListItemHarness` that
210 * meets certain criteria.
211 * @param options Options for filtering which action list item instances are considered a match.
212 * @return a `HarnessPredicate` configured with the given options.
213 */
214 static with(options = {}) {
215 return getListItemPredicate(MatActionListItemHarness, options);
216 }
217 /** Clicks on the action list item. */
218 click() {
219 return __awaiter(this, void 0, void 0, function* () {
220 return (yield this.host()).click();
221 });
222 }
223 /** Focuses the action list item. */
224 focus() {
225 return __awaiter(this, void 0, void 0, function* () {
226 return (yield this.host()).focus();
227 });
228 }
229 /** Blurs the action list item. */
230 blur() {
231 return __awaiter(this, void 0, void 0, function* () {
232 return (yield this.host()).blur();
233 });
234 }
235 /** Whether the action list item is focused. */
236 isFocused() {
237 return __awaiter(this, void 0, void 0, function* () {
238 return (yield this.host()).isFocused();
239 });
240 }
241}
242/** The selector for the host element of a `MatListItem` instance. */
243MatActionListItemHarness.hostSelector = `${MatActionListHarness.hostSelector} .mat-list-item`;
244
245/**
246 * @license
247 * Copyright Google LLC All Rights Reserved.
248 *
249 * Use of this source code is governed by an MIT-style license that can be
250 * found in the LICENSE file at https://angular.io/license
251 */
252/** Harness for interacting with a standard mat-list in tests. */
253class MatListHarness extends MatListHarnessBase {
254 constructor() {
255 super(...arguments);
256 this._itemHarness = MatListItemHarness;
257 }
258 /**
259 * Gets a `HarnessPredicate` that can be used to search for a `MatListHarness` that meets certain
260 * criteria.
261 * @param options Options for filtering which list instances are considered a match.
262 * @return a `HarnessPredicate` configured with the given options.
263 */
264 static with(options = {}) {
265 return new HarnessPredicate(MatListHarness, options);
266 }
267}
268/** The selector for the host element of a `MatList` instance. */
269MatListHarness.hostSelector = '.mat-list:not(mat-action-list)';
270/** Harness for interacting with a list item. */
271class MatListItemHarness extends MatListItemHarnessBase {
272 /**
273 * Gets a `HarnessPredicate` that can be used to search for a `MatListItemHarness` that meets
274 * certain criteria.
275 * @param options Options for filtering which list item instances are considered a match.
276 * @return a `HarnessPredicate` configured with the given options.
277 */
278 static with(options = {}) {
279 return getListItemPredicate(MatListItemHarness, options);
280 }
281}
282/** The selector for the host element of a `MatListItem` instance. */
283MatListItemHarness.hostSelector = `${MatListHarness.hostSelector} .mat-list-item`;
284
285/**
286 * @license
287 * Copyright Google LLC All Rights Reserved.
288 *
289 * Use of this source code is governed by an MIT-style license that can be
290 * found in the LICENSE file at https://angular.io/license
291 */
292
293/**
294 * @license
295 * Copyright Google LLC All Rights Reserved.
296 *
297 * Use of this source code is governed by an MIT-style license that can be
298 * found in the LICENSE file at https://angular.io/license
299 */
300/** Harness for interacting with a standard mat-nav-list in tests. */
301class MatNavListHarness extends MatListHarnessBase {
302 constructor() {
303 super(...arguments);
304 this._itemHarness = MatNavListItemHarness;
305 }
306 /**
307 * Gets a `HarnessPredicate` that can be used to search for a `MatNavListHarness` that meets
308 * certain criteria.
309 * @param options Options for filtering which nav list instances are considered a match.
310 * @return a `HarnessPredicate` configured with the given options.
311 */
312 static with(options = {}) {
313 return new HarnessPredicate(MatNavListHarness, options);
314 }
315}
316/** The selector for the host element of a `MatNavList` instance. */
317MatNavListHarness.hostSelector = '.mat-nav-list';
318/** Harness for interacting with a nav list item. */
319class MatNavListItemHarness extends MatListItemHarnessBase {
320 /**
321 * Gets a `HarnessPredicate` that can be used to search for a `MatNavListItemHarness` that
322 * meets certain criteria.
323 * @param options Options for filtering which nav list item instances are considered a match.
324 * @return a `HarnessPredicate` configured with the given options.
325 */
326 static with(options = {}) {
327 return getListItemPredicate(MatNavListItemHarness, options)
328 .addOption('href', options.href, (harness, href) => __awaiter(this, void 0, void 0, function* () { return HarnessPredicate.stringMatches(harness.getHref(), href); }));
329 }
330 /** Gets the href for this nav list item. */
331 getHref() {
332 return __awaiter(this, void 0, void 0, function* () {
333 return (yield this.host()).getAttribute('href');
334 });
335 }
336 /** Clicks on the nav list item. */
337 click() {
338 return __awaiter(this, void 0, void 0, function* () {
339 return (yield this.host()).click();
340 });
341 }
342 /** Focuses the nav list item. */
343 focus() {
344 return __awaiter(this, void 0, void 0, function* () {
345 return (yield this.host()).focus();
346 });
347 }
348 /** Blurs the nav list item. */
349 blur() {
350 return __awaiter(this, void 0, void 0, function* () {
351 return (yield this.host()).blur();
352 });
353 }
354 /** Whether the nav list item is focused. */
355 isFocused() {
356 return __awaiter(this, void 0, void 0, function* () {
357 return (yield this.host()).isFocused();
358 });
359 }
360}
361/** The selector for the host element of a `MatListItem` instance. */
362MatNavListItemHarness.hostSelector = `${MatNavListHarness.hostSelector} .mat-list-item`;
363
364/**
365 * @license
366 * Copyright Google LLC All Rights Reserved.
367 *
368 * Use of this source code is governed by an MIT-style license that can be
369 * found in the LICENSE file at https://angular.io/license
370 */
371/** Harness for interacting with a standard mat-selection-list in tests. */
372class MatSelectionListHarness extends MatListHarnessBase {
373 constructor() {
374 super(...arguments);
375 this._itemHarness = MatListOptionHarness;
376 }
377 /**
378 * Gets a `HarnessPredicate` that can be used to search for a `MatSelectionListHarness` that meets
379 * certain criteria.
380 * @param options Options for filtering which selection list instances are considered a match.
381 * @return a `HarnessPredicate` configured with the given options.
382 */
383 static with(options = {}) {
384 return new HarnessPredicate(MatSelectionListHarness, options);
385 }
386 /** Whether the selection list is disabled. */
387 isDisabled() {
388 return __awaiter(this, void 0, void 0, function* () {
389 return (yield (yield this.host()).getAttribute('aria-disabled')) === 'true';
390 });
391 }
392 /**
393 * Selects all items matching any of the given filters.
394 * @param filters Filters that specify which items should be selected.
395 */
396 selectItems(...filters) {
397 return __awaiter(this, void 0, void 0, function* () {
398 const items = yield this._getItems(filters);
399 yield parallel(() => items.map(item => item.select()));
400 });
401 }
402 /**
403 * Deselects all items matching any of the given filters.
404 * @param filters Filters that specify which items should be deselected.
405 */
406 deselectItems(...filters) {
407 return __awaiter(this, void 0, void 0, function* () {
408 const items = yield this._getItems(filters);
409 yield parallel(() => items.map(item => item.deselect()));
410 });
411 }
412 /** Gets all items matching the given list of filters. */
413 _getItems(filters) {
414 return __awaiter(this, void 0, void 0, function* () {
415 if (!filters.length) {
416 return this.getItems();
417 }
418 const matches = yield parallel(() => {
419 return filters.map(filter => this.locatorForAll(MatListOptionHarness.with(filter))());
420 });
421 return matches.reduce((result, current) => [...result, ...current], []);
422 });
423 }
424}
425/** The selector for the host element of a `MatSelectionList` instance. */
426MatSelectionListHarness.hostSelector = '.mat-selection-list';
427/** Harness for interacting with a list option. */
428class MatListOptionHarness extends MatListItemHarnessBase {
429 constructor() {
430 super(...arguments);
431 this._itemContent = this.locatorFor('.mat-list-item-content');
432 }
433 /**
434 * Gets a `HarnessPredicate` that can be used to search for a `MatListOptionHarness` that
435 * meets certain criteria.
436 * @param options Options for filtering which list option instances are considered a match.
437 * @return a `HarnessPredicate` configured with the given options.
438 */
439 static with(options = {}) {
440 return getListItemPredicate(MatListOptionHarness, options)
441 .addOption('is selected', options.selected, (harness, selected) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isSelected()) === selected; }));
442 }
443 /** Gets the position of the checkbox relative to the list option content. */
444 getCheckboxPosition() {
445 return __awaiter(this, void 0, void 0, function* () {
446 return (yield (yield this._itemContent()).hasClass('mat-list-item-content-reverse')) ?
447 'after' : 'before';
448 });
449 }
450 /** Whether the list option is selected. */
451 isSelected() {
452 return __awaiter(this, void 0, void 0, function* () {
453 return (yield (yield this.host()).getAttribute('aria-selected')) === 'true';
454 });
455 }
456 /** Whether the list option is disabled. */
457 isDisabled() {
458 return __awaiter(this, void 0, void 0, function* () {
459 return (yield (yield this.host()).getAttribute('aria-disabled')) === 'true';
460 });
461 }
462 /** Focuses the list option. */
463 focus() {
464 return __awaiter(this, void 0, void 0, function* () {
465 return (yield this.host()).focus();
466 });
467 }
468 /** Blurs the list option. */
469 blur() {
470 return __awaiter(this, void 0, void 0, function* () {
471 return (yield this.host()).blur();
472 });
473 }
474 /** Whether the list option is focused. */
475 isFocused() {
476 return __awaiter(this, void 0, void 0, function* () {
477 return (yield this.host()).isFocused();
478 });
479 }
480 /** Toggles the checked state of the checkbox. */
481 toggle() {
482 return __awaiter(this, void 0, void 0, function* () {
483 return (yield this.host()).click();
484 });
485 }
486 /**
487 * Puts the list option in a checked state by toggling it if it is currently unchecked, or doing
488 * nothing if it is already checked.
489 */
490 select() {
491 return __awaiter(this, void 0, void 0, function* () {
492 if (!(yield this.isSelected())) {
493 return this.toggle();
494 }
495 });
496 }
497 /**
498 * Puts the list option in an unchecked state by toggling it if it is currently checked, or doing
499 * nothing if it is already unchecked.
500 */
501 deselect() {
502 return __awaiter(this, void 0, void 0, function* () {
503 if (yield this.isSelected()) {
504 return this.toggle();
505 }
506 });
507 }
508}
509/** The selector for the host element of a `MatListOption` instance. */
510MatListOptionHarness.hostSelector = '.mat-list-option';
511
512/**
513 * @license
514 * Copyright Google LLC All Rights Reserved.
515 *
516 * Use of this source code is governed by an MIT-style license that can be
517 * found in the LICENSE file at https://angular.io/license
518 */
519
520/**
521 * @license
522 * Copyright Google LLC All Rights Reserved.
523 *
524 * Use of this source code is governed by an MIT-style license that can be
525 * found in the LICENSE file at https://angular.io/license
526 */
527
528export { MatActionListHarness, MatActionListItemHarness, MatListHarness, MatListItemHarness, MatListOptionHarness, MatNavListHarness, MatNavListItemHarness, MatSelectionListHarness };
529//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.