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