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 { HarnessPredicate, parallel } from '@angular/cdk/testing';
|
---|
10 | import { MatChipOptionHarness } from './chip-option-harness';
|
---|
11 | import { _MatChipListHarnessBase } from './chip-list-harness';
|
---|
12 | /** Harness for interacting with a standard selectable chip list in tests. */
|
---|
13 | export class MatChipListboxHarness extends _MatChipListHarnessBase {
|
---|
14 | /**
|
---|
15 | * Gets a `HarnessPredicate` that can be used to search for a `MatChipListHarness` that meets
|
---|
16 | * certain criteria.
|
---|
17 | * @param options Options for filtering which chip list instances are considered a match.
|
---|
18 | * @return a `HarnessPredicate` configured with the given options.
|
---|
19 | */
|
---|
20 | static with(options = {}) {
|
---|
21 | return new HarnessPredicate(MatChipListboxHarness, options);
|
---|
22 | }
|
---|
23 | /**
|
---|
24 | * Gets the list of chips inside the chip list.
|
---|
25 | * @param filter Optionally filters which chips are included.
|
---|
26 | */
|
---|
27 | getChips(filter = {}) {
|
---|
28 | return __awaiter(this, void 0, void 0, function* () {
|
---|
29 | return this.locatorForAll(MatChipOptionHarness.with(filter))();
|
---|
30 | });
|
---|
31 | }
|
---|
32 | /**
|
---|
33 | * Selects a chip inside the chip list.
|
---|
34 | * @param filter An optional filter to apply to the child chips.
|
---|
35 | * All the chips matching the filter will be selected.
|
---|
36 | */
|
---|
37 | selectChips(filter = {}) {
|
---|
38 | return __awaiter(this, void 0, void 0, function* () {
|
---|
39 | const chips = yield this.getChips(filter);
|
---|
40 | if (!chips.length) {
|
---|
41 | throw Error(`Cannot find chip matching filter ${JSON.stringify(filter)}`);
|
---|
42 | }
|
---|
43 | yield parallel(() => chips.map(chip => chip.select()));
|
---|
44 | });
|
---|
45 | }
|
---|
46 | }
|
---|
47 | /** The selector for the host element of a `M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