UNPKG

4.66 kBJavaScriptView Raw
1import { __awaiter } from 'tslib';
2import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
3
4/** Harness for interacting with a `mat-option` in tests. */
5class MatOptionHarness extends ComponentHarness {
6 constructor() {
7 super(...arguments);
8 /** Element containing the option's text. */
9 this._text = this.locatorFor('.mat-option-text');
10 }
11 /**
12 * Gets a `HarnessPredicate` that can be used to search for a `MatOptionsHarness` that meets
13 * certain criteria.
14 * @param options Options for filtering which option instances are considered a match.
15 * @return a `HarnessPredicate` configured with the given options.
16 */
17 static with(options = {}) {
18 return new HarnessPredicate(MatOptionHarness, options)
19 .addOption('text', options.text, (harness, title) => __awaiter(this, void 0, void 0, function* () { return HarnessPredicate.stringMatches(yield harness.getText(), title); }))
20 .addOption('isSelected', options.isSelected, (harness, isSelected) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isSelected()) === isSelected; }));
21 }
22 /** Clicks the option. */
23 click() {
24 return __awaiter(this, void 0, void 0, function* () {
25 return (yield this.host()).click();
26 });
27 }
28 /** Gets the option's label text. */
29 getText() {
30 return __awaiter(this, void 0, void 0, function* () {
31 return (yield this._text()).text();
32 });
33 }
34 /** Gets whether the option is disabled. */
35 isDisabled() {
36 return __awaiter(this, void 0, void 0, function* () {
37 return (yield this.host()).hasClass('mat-option-disabled');
38 });
39 }
40 /** Gets whether the option is selected. */
41 isSelected() {
42 return __awaiter(this, void 0, void 0, function* () {
43 return (yield this.host()).hasClass('mat-selected');
44 });
45 }
46 /** Gets whether the option is active. */
47 isActive() {
48 return __awaiter(this, void 0, void 0, function* () {
49 return (yield this.host()).hasClass('mat-active');
50 });
51 }
52 /** Gets whether the option is in multiple selection mode. */
53 isMultiple() {
54 return __awaiter(this, void 0, void 0, function* () {
55 return (yield this.host()).hasClass('mat-option-multiple');
56 });
57 }
58}
59/** Selector used to locate option instances. */
60MatOptionHarness.hostSelector = '.mat-option';
61
62/** Harness for interacting with a `mat-optgroup` in tests. */
63class MatOptgroupHarness extends ComponentHarness {
64 constructor() {
65 super(...arguments);
66 this._label = this.locatorFor('.mat-optgroup-label');
67 }
68 /**
69 * Gets a `HarnessPredicate` that can be used to search for a `MatOptgroupHarness` that meets
70 * certain criteria.
71 * @param options Options for filtering which option instances are considered a match.
72 * @return a `HarnessPredicate` configured with the given options.
73 */
74 static with(options = {}) {
75 return new HarnessPredicate(MatOptgroupHarness, options).addOption('labelText', options.labelText, (harness, title) => __awaiter(this, void 0, void 0, function* () { return HarnessPredicate.stringMatches(yield harness.getLabelText(), title); }));
76 }
77 /** Gets the option group's label text. */
78 getLabelText() {
79 return __awaiter(this, void 0, void 0, function* () {
80 return (yield this._label()).text();
81 });
82 }
83 /** Gets whether the option group is disabled. */
84 isDisabled() {
85 return __awaiter(this, void 0, void 0, function* () {
86 return (yield this.host()).hasClass('mat-optgroup-disabled');
87 });
88 }
89 /**
90 * Gets the options that are inside the group.
91 * @param filter Optionally filters which options are included.
92 */
93 getOptions(filter = {}) {
94 return __awaiter(this, void 0, void 0, function* () {
95 return this.locatorForAll(MatOptionHarness.with(filter))();
96 });
97 }
98}
99/** Selector used to locate option group instances. */
100MatOptgroupHarness.hostSelector = '.mat-optgroup';
101
102/**
103 * @license
104 * Copyright Google LLC All Rights Reserved.
105 *
106 * Use of this source code is governed by an MIT-style license that can be
107 * found in the LICENSE file at https://angular.io/license
108 */
109
110/**
111 * @license
112 * Copyright Google LLC All Rights Reserved.
113 *
114 * Use of this source code is governed by an MIT-style license that can be
115 * found in the LICENSE file at https://angular.io/license
116 */
117
118export { MatOptgroupHarness, MatOptionHarness };
119//# sourceMappingURL=testing.mjs.map