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 { ComponentHarness, HarnessPredicate, parallel } from '@angular/cdk/testing';
|
---|
10 | import { MatChipHarness } from './chip-harness';
|
---|
11 | import { MatChipInputHarness } from './chip-input-harness';
|
---|
12 | /** Base class for chip list harnesses. */
|
---|
13 | export class _MatChipListHarnessBase extends ComponentHarness {
|
---|
14 | /** Gets whether the chip list is disabled. */
|
---|
15 | isDisabled() {
|
---|
16 | return __awaiter(this, void 0, void 0, function* () {
|
---|
17 | return (yield (yield this.host()).getAttribute('aria-disabled')) === 'true';
|
---|
18 | });
|
---|
19 | }
|
---|
20 | /** Gets whether the chip list is required. */
|
---|
21 | isRequired() {
|
---|
22 | return __awaiter(this, void 0, void 0, function* () {
|
---|
23 | return (yield (yield this.host()).getAttribute('aria-required')) === 'true';
|
---|
24 | });
|
---|
25 | }
|
---|
26 | /** Gets whether the chip list is invalid. */
|
---|
27 | isInvalid() {
|
---|
28 | return __awaiter(this, void 0, void 0, function* () {
|
---|
29 | return (yield (yield this.host()).getAttribute('aria-invalid')) === 'true';
|
---|
30 | });
|
---|
31 | }
|
---|
32 | /** Gets whether the chip list is in multi selection mode. */
|
---|
33 | isMultiple() {
|
---|
34 | return __awaiter(this, void 0, void 0, function* () {
|
---|
35 | return (yield (yield this.host()).getAttribute('aria-multiselectable')) === 'true';
|
---|
36 | });
|
---|
37 | }
|
---|
38 | /** Gets whether the orientation of the chip list. */
|
---|
39 | getOrientation() {
|
---|
40 | return __awaiter(this, void 0, void 0, function* () {
|
---|
41 | const orientation = yield (yield this.host()).getAttribute('aria-orientation');
|
---|
42 | return orientation === 'vertical' ? 'vertical' : 'horizontal';
|
---|
43 | });
|
---|
44 | }
|
---|
45 | }
|
---|
46 | /** Harness for interacting with a standard chip list in tests. */
|
---|
47 | export class MatChipListHarness extends _MatChipListHarnessBase {
|
---|
48 | /**
|
---|
49 | * Gets a `HarnessPredicate` that can be used to search for a `MatChipListHarness` that meets
|
---|
50 | * certain criteria.
|
---|
51 | * @param options Options for filtering which chip list instances are considered a match.
|
---|
52 | * @return a `HarnessPredicate` configured with the given options.
|
---|
53 | */
|
---|
54 | static with(options = {}) {
|
---|
55 | return new HarnessPredicate(MatChipListHarness, options);
|
---|
56 | }
|
---|
57 | /**
|
---|
58 | * Gets the list of chips inside the chip list.
|
---|
59 | * @param filter Optionally filters which chips are included.
|
---|
60 | */
|
---|
61 | getChips(filter = {}) {
|
---|
62 | return __awaiter(this, void 0, void 0, function* () {
|
---|
63 | return this.locatorForAll(MatChipHarness.with(filter))();
|
---|
64 | });
|
---|
65 | }
|
---|
66 | /**
|
---|
67 | * Selects a chip inside the chip list.
|
---|
68 | * @param filter An optional filter to apply to the child chips.
|
---|
69 | * All the chips matching the filter will be selected.
|
---|
70 | * @deprecated Use `MatChipListboxHarness.selectChips` instead.
|
---|
71 | * @breaking-change 12.0.0
|
---|
72 | */
|
---|
73 | selectChips(filter = {}) {
|
---|
74 | return __awaiter(this, void 0, void 0, function* () {
|
---|
75 | const chips = yield this.getChips(filter);
|
---|
76 | if (!chips.length) {
|
---|
77 | throw Error(`Cannot find chip matching filter ${JSON.stringify(filter)}`);
|
---|
78 | }
|
---|
79 | yield parallel(() => chips.map(chip => chip.select()));
|
---|
80 | });
|
---|
81 | }
|
---|
82 | /**
|
---|
83 | * Gets the `MatChipInput` inside the chip list.
|
---|
84 | * @param filter Optionally filters which chip input is included.
|
---|
85 | */
|
---|
86 | getInput(filter = {}) {
|
---|
87 | return __awaiter(this, void 0, void 0, function* () {
|
---|
88 | // The input isn't required to be a descendant of the chip list so we have to look it up by id.
|
---|
89 | const inputId = yield (yield this.host()).getAttribute('data-mat-chip-input');
|
---|
90 | if (!inputId) {
|
---|
91 | throw Error(`Chip list is not associated with an input`);
|
---|
92 | }
|
---|
93 | return this.documentRootLocatorFactory().locatorFor(MatChipInputHarness.with(Object.assign(Object.assign({}, filter), { selector: `#${inputId}` })))();
|
---|
94 | });
|
---|
95 | }
|
---|
96 | }
|
---|
97 | /** The selector for the host element of a `MatChipList` instance. */
|
---|
98 | MatChipListHarness.hostSelector = '.mat-chip-list';
|
---|
99 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1saXN0LWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvY2hpcHMvdGVzdGluZy9jaGlwLWxpc3QtaGFybmVzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7O0FBRUgsT0FBTyxFQUFDLGdCQUFnQixFQUFFLGdCQUFnQixFQUFFLFFBQVEsRUFBQyxNQUFNLHNCQUFzQixDQUFDO0FBQ2xGLE9BQU8sRUFBQyxjQUFjLEVBQUMsTUFBTSxnQkFBZ0IsQ0FBQztBQUM5QyxPQUFPLEVBQUMsbUJBQW1CLEVBQUMsTUFBTSxzQkFBc0IsQ0FBQztBQU96RCwwQ0FBMEM7QUFDMUMsTUFBTSxPQUFnQix1QkFBd0IsU0FBUSxnQkFBZ0I7SUFDcEUsOENBQThDO0lBQ3hDLFVBQVU7O1lBQ2QsT0FBTyxDQUFBLE1BQU0sQ0FBQyxNQUFNLElBQUksQ0FBQyxJQUFJLEVBQUUsQ0FBQyxDQUFDLFlBQVksQ0FBQyxlQUFlLENBQUMsTUFBSyxNQUFNLENBQUM7UUFDNUUsQ0FBQztLQUFBO0lBRUQsOENBQThDO0lBQ3hDLFVBQVU7O1lBQ2QsT0FBTyxDQUFBLE1BQU0sQ0FBQyxNQUFNLElBQUksQ0FBQyxJQUFJLEVBQUUsQ0FBQyxDQUFDLFlBQVksQ0FBQyxlQ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