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 { ContentContainerComponentHarness, HarnessPredicate, TestKey } from '@angular/cdk/testing';
|
---|
10 | import { MatChipAvatarHarness } from './chip-avatar-harness';
|
---|
11 | import { MatChipRemoveHarness } from './chip-remove-harness';
|
---|
12 | /** Harness for interacting with a standard selectable Angular Material chip in tests. */
|
---|
13 | export class MatChipHarness extends ContentContainerComponentHarness {
|
---|
14 | /**
|
---|
15 | * Gets a `HarnessPredicate` that can be used to search for a `MatChipHarness` that meets
|
---|
16 | * certain criteria.
|
---|
17 | * @param options Options for filtering which chip instances are considered a match.
|
---|
18 | * @return a `HarnessPredicate` configured with the given options.
|
---|
19 | */
|
---|
20 | static with(options = {}) {
|
---|
21 | return new HarnessPredicate(MatChipHarness, options)
|
---|
22 | .addOption('text', options.text, (harness, label) => HarnessPredicate.stringMatches(harness.getText(), label))
|
---|
23 | .addOption('selected', options.selected, (harness, selected) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isSelected()) === selected; }));
|
---|
24 | }
|
---|
25 | /** Gets the text of the chip. */
|
---|
26 | getText() {
|
---|
27 | return __awaiter(this, void 0, void 0, function* () {
|
---|
28 | return (yield this.host()).text({
|
---|
29 | exclude: '.mat-chip-avatar, .mat-chip-trailing-icon, .mat-icon'
|
---|
30 | });
|
---|
31 | });
|
---|
32 | }
|
---|
33 | /**
|
---|
34 | * Whether the chip is selected.
|
---|
35 | * @deprecated Use `MatChipOptionHarness.isSelected` instead.
|
---|
36 | * @breaking-change 12.0.0
|
---|
37 | */
|
---|
38 | isSelected() {
|
---|
39 | return __awaiter(this, void 0, void 0, function* () {
|
---|
40 | return (yield this.host()).hasClass('mat-chip-selected');
|
---|
41 | });
|
---|
42 | }
|
---|
43 | /** Whether the chip is disabled. */
|
---|
44 | isDisabled() {
|
---|
45 | return __awaiter(this, void 0, void 0, function* () {
|
---|
46 | return (yield this.host()).hasClass('mat-chip-disabled');
|
---|
47 | });
|
---|
48 | }
|
---|
49 | /**
|
---|
50 | * Selects the given chip. Only applies if it's selectable.
|
---|
51 | * @deprecated Use `MatChipOptionHarness.select` instead.
|
---|
52 | * @breaking-change 12.0.0
|
---|
53 | */
|
---|
54 | select() {
|
---|
55 | return __awaiter(this, void 0, void 0, function* () {
|
---|
56 | if (!(yield this.isSelected())) {
|
---|
57 | yield this.toggle();
|
---|
58 | }
|
---|
59 | });
|
---|
60 | }
|
---|
61 | /**
|
---|
62 | * Deselects the given chip. Only applies if it's selectable.
|
---|
63 | * @deprecated Use `MatChipOptionHarness.deselect` instead.
|
---|
64 | * @breaking-change 12.0.0
|
---|
65 | */
|
---|
66 | deselect() {
|
---|
67 | return __awaiter(this, void 0, void 0, function* () {
|
---|
68 | if (yield this.isSelected()) {
|
---|
69 | yield this.toggle();
|
---|
70 | }
|
---|
71 | });
|
---|
72 | }
|
---|
73 | /**
|
---|
74 | * Toggles the selected state of the given chip. Only applies if it's selectable.
|
---|
75 | * @deprecated Use `MatChipOptionHarness.toggle` instead.
|
---|
76 | * @breaking-change 12.0.0
|
---|
77 | */
|
---|
78 | toggle() {
|
---|
79 | return __awaiter(this, void 0, void 0, function* () {
|
---|
80 | return (yield this.host()).sendKeys(' ');
|
---|
81 | });
|
---|
82 | }
|
---|
83 | /** Removes the given chip. Only applies if it's removable. */
|
---|
84 | remove() {
|
---|
85 | return __awaiter(this, void 0, void 0, function* () {
|
---|
86 | yield (yield this.host()).sendKeys(TestKey.DELETE);
|
---|
87 | });
|
---|
88 | }
|
---|
89 | /**
|
---|
90 | * Gets the remove button inside of a chip.
|
---|
91 | * @param filter Optionally filters which remove buttons are included.
|
---|
92 | */
|
---|
93 | getRemoveButton(filter = {}) {
|
---|
94 | return __awaiter(this, void 0, void 0, function* () {
|
---|
95 | return this.locatorFor(MatChipRemoveHarness.with(filter))();
|
---|
96 | });
|
---|
97 | }
|
---|
98 | /**
|
---|
99 | * Gets the avatar inside a chip.
|
---|
100 | * @param filter Optionally filters which avatars are included.
|
---|
101 | */
|
---|
102 | getAvatar(filter = {}) {
|
---|
103 | return __awaiter(this, void 0, void 0, function* () {
|
---|
104 | return this.locatorForOptional(MatChipAvatarHarness.with(filter))();
|
---|
105 | });
|
---|
106 | }
|
---|
107 | }
|
---|
108 | /** The selector for the host element of a `MatChip` instance. */
|
---|
109 | MatChipHarness.hostSelector = '.mat-chip';
|
---|
110 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL2NoaXBzL3Rlc3RpbmcvY2hpcC1oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRzs7QUFFSCxPQUFPLEVBQUMsZ0NBQWdDLEVBQUUsZ0JBQWdCLEVBQUUsT0FBTyxFQUFDLE1BQU0sc0JBQXNCLENBQUM7QUFDakcsT0FBTyxFQUFDLG9CQUFvQixFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFNM0QsT0FBTyxFQUFDLG9CQUFvQixFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFFM0QseUZBQXlGO0FBQ3pGLE1BQU0sT0FBTyxjQUFlLFNBQVEsZ0NBQWdDO0lBSWxFOzs7OztPQUtHO0lBQ0gsTUFBTSxDQUFDLElBQUksQ0FBQyxVQUE4QixFQUFFO1FBQzFDLE9BQU8sSUFBSSxnQkFBZ0IsQ0FBQyxjQUFjLEVBQUUsT0FBTyxDQUFDO2FBQy9DLFNBQVMsQ0FBQyxNQUFNLEVBQUUsT0FBTyxDQUFDLElBQUksRUFDM0IsQ0FBQyxPQUFP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