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 } from '@angular/cdk/testing';
|
---|
10 | import { MatChipHarness } from './chip-harness';
|
---|
11 | export class MatChipOptionHarness extends MatChipHarness {
|
---|
12 | /**
|
---|
13 | * Gets a `HarnessPredicate` that can be used to search for a `MatChipOptionHarness`
|
---|
14 | * that meets certain criteria.
|
---|
15 | * @param options Options for filtering which chip instances are considered a match.
|
---|
16 | * @return a `HarnessPredicate` configured with the given options.
|
---|
17 | */
|
---|
18 | static with(options = {}) {
|
---|
19 | return new HarnessPredicate(MatChipOptionHarness, options)
|
---|
20 | .addOption('text', options.text, (harness, label) => HarnessPredicate.stringMatches(harness.getText(), label))
|
---|
21 | .addOption('selected', options.selected, (harness, selected) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isSelected()) === selected; }));
|
---|
22 | }
|
---|
23 | /** Whether the chip is selected. */
|
---|
24 | isSelected() {
|
---|
25 | return __awaiter(this, void 0, void 0, function* () {
|
---|
26 | return (yield this.host()).hasClass('mat-chip-selected');
|
---|
27 | });
|
---|
28 | }
|
---|
29 | /** Selects the given chip. Only applies if it's selectable. */
|
---|
30 | select() {
|
---|
31 | return __awaiter(this, void 0, void 0, function* () {
|
---|
32 | if (!(yield this.isSelected())) {
|
---|
33 | yield this.toggle();
|
---|
34 | }
|
---|
35 | });
|
---|
36 | }
|
---|
37 | /** Deselects the given chip. Only applies if it's selectable. */
|
---|
38 | deselect() {
|
---|
39 | return __awaiter(this, void 0, void 0, function* () {
|
---|
40 | if (yield this.isSelected()) {
|
---|
41 | yield this.toggle();
|
---|
42 | }
|
---|
43 | });
|
---|
44 | }
|
---|
45 | /** Toggles the selected state of the given chip. */
|
---|
46 | toggle() {
|
---|
47 | return __awaiter(this, void 0, void 0, function* () {
|
---|
48 | return (yield this.host()).sendKeys(' ');
|
---|
49 | });
|
---|
50 | }
|
---|
51 | }
|
---|
52 | /** The selector for the host element of a selectable chip instance. */
|
---|
53 | MatChipOptionHarness.hostSelector = '.mat-chip';
|
---|
54 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1vcHRpb24taGFybmVzcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uLy4uLy4uLy4uLy4uLy4uL3NyYy9tYXRlcmlhbC9jaGlwcy90ZXN0aW5nL2NoaXAtb3B0aW9uLWhhcm5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HOztBQUVILE9BQU8sRUFBQyxnQkFBZ0IsRUFBQyxNQUFNLHNCQUFzQixDQUFDO0FBQ3RELE9BQU8sRUFBQyxjQUFjLEVBQUMsTUFBTSxnQkFBZ0IsQ0FBQztBQUc5QyxNQUFNLE9BQU8sb0JBQXFCLFNBQVEsY0FBYztJQUl0RDs7Ozs7T0FLRztJQUNILE1BQU0sQ0FBVSxJQUFJLENBQUMsVUFBb0MsRUFBRTtRQUV6RCxPQUFPLElBQUksZ0JBQWdCLENBQUMsb0JBQW9CLEVBQUUsT0FBTyxDQUFDO2FBQ3JELFNBQVMsQ0FBQyxNQUFNLEVBQUUsT0FBTyxDQUFDLElBQUksRUFDM0IsQ0FBQyxPQUFPLEVBQUUsS0FBSyxFQUFFLEVBQUUsQ0FBQyxnQkFBZ0IsQ0FBQyxhQUFhLENBQUMsT0FBTyxDQUFDLE9BQU8sRUFBRSxFQUFFLEtBQUssQ0FBQyxDQUFDO2FBQ2hGLFNBQVMsQ0FBQyxVQUFVLEVBQUUsT0FBTyxDQUFDLFFBQVEsRUFDbkMsQ0FBTyxPQUFPLEVBQUUsUUFBUSxFQUFFLEVBQUUsZ0RBQUMsT0FBQSxDQUFDLE1BQU0s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