1 | import { __awaiter } from 'tslib';
|
---|
2 | import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
|
---|
3 | import { coerceBooleanProperty } from '@angular/cdk/coercion';
|
---|
4 |
|
---|
5 | /**
|
---|
6 | * @license
|
---|
7 | * Copyright Google LLC All Rights Reserved.
|
---|
8 | *
|
---|
9 | * Use of this source code is governed by an MIT-style license that can be
|
---|
10 | * found in the LICENSE file at https://angular.io/license
|
---|
11 | */
|
---|
12 | /** Harness for interacting with a standard mat-button-toggle in tests. */
|
---|
13 | class MatButtonToggleHarness extends ComponentHarness {
|
---|
14 | constructor() {
|
---|
15 | super(...arguments);
|
---|
16 | this._label = this.locatorFor('.mat-button-toggle-label-content');
|
---|
17 | this._button = this.locatorFor('.mat-button-toggle-button');
|
---|
18 | }
|
---|
19 | /**
|
---|
20 | * Gets a `HarnessPredicate` that can be used to search for a `MatButtonToggleHarness` that meets
|
---|
21 | * certain criteria.
|
---|
22 | * @param options Options for filtering which button toggle instances are considered a match.
|
---|
23 | * @return a `HarnessPredicate` configured with the given options.
|
---|
24 | */
|
---|
25 | static with(options = {}) {
|
---|
26 | return new HarnessPredicate(MatButtonToggleHarness, options)
|
---|
27 | .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text))
|
---|
28 | .addOption('name', options.name, (harness, name) => HarnessPredicate.stringMatches(harness.getName(), name))
|
---|
29 | .addOption('checked', options.checked, (harness, checked) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isChecked()) === checked; }));
|
---|
30 | }
|
---|
31 | /** Gets a boolean promise indicating if the button toggle is checked. */
|
---|
32 | isChecked() {
|
---|
33 | return __awaiter(this, void 0, void 0, function* () {
|
---|
34 | const checked = (yield this._button()).getAttribute('aria-pressed');
|
---|
35 | return coerceBooleanProperty(yield checked);
|
---|
36 | });
|
---|
37 | }
|
---|
38 | /** Gets a boolean promise indicating if the button toggle is disabled. */
|
---|
39 | isDisabled() {
|
---|
40 | return __awaiter(this, void 0, void 0, function* () {
|
---|
41 | const disabled = (yield this._button()).getAttribute('disabled');
|
---|
42 | return coerceBooleanProperty(yield disabled);
|
---|
43 | });
|
---|
44 | }
|
---|
45 | /** Gets a promise for the button toggle's name. */
|
---|
46 | getName() {
|
---|
47 | return __awaiter(this, void 0, void 0, function* () {
|
---|
48 | return (yield this._button()).getAttribute('name');
|
---|
49 | });
|
---|
50 | }
|
---|
51 | /** Gets a promise for the button toggle's aria-label. */
|
---|
52 | getAriaLabel() {
|
---|
53 | return __awaiter(this, void 0, void 0, function* () {
|
---|
54 | return (yield this._button()).getAttribute('aria-label');
|
---|
55 | });
|
---|
56 | }
|
---|
57 | /** Gets a promise for the button toggles's aria-labelledby. */
|
---|
58 | getAriaLabelledby() {
|
---|
59 | return __awaiter(this, void 0, void 0, function* () {
|
---|
60 | return (yield this._button()).getAttribute('aria-labelledby');
|
---|
61 | });
|
---|
62 | }
|
---|
63 | /** Gets a promise for the button toggle's text. */
|
---|
64 | getText() {
|
---|
65 | return __awaiter(this, void 0, void 0, function* () {
|
---|
66 | return (yield this._label()).text();
|
---|
67 | });
|
---|
68 | }
|
---|
69 | /** Gets the appearance that the button toggle is using. */
|
---|
70 | getAppearance() {
|
---|
71 | return __awaiter(this, void 0, void 0, function* () {
|
---|
72 | const host = yield this.host();
|
---|
73 | const className = 'mat-button-toggle-appearance-standard';
|
---|
74 | return (yield host.hasClass(className)) ? 'standard' : 'legacy';
|
---|
75 | });
|
---|
76 | }
|
---|
77 | /** Focuses the toggle. */
|
---|
78 | focus() {
|
---|
79 | return __awaiter(this, void 0, void 0, function* () {
|
---|
80 | return (yield this._button()).focus();
|
---|
81 | });
|
---|
82 | }
|
---|
83 | /** Blurs the toggle. */
|
---|
84 | blur() {
|
---|
85 | return __awaiter(this, void 0, void 0, function* () {
|
---|
86 | return (yield this._button()).blur();
|
---|
87 | });
|
---|
88 | }
|
---|
89 | /** Whether the toggle is focused. */
|
---|
90 | isFocused() {
|
---|
91 | return __awaiter(this, void 0, void 0, function* () {
|
---|
92 | return (yield this._button()).isFocused();
|
---|
93 | });
|
---|
94 | }
|
---|
95 | /** Toggle the checked state of the buttons toggle. */
|
---|
96 | toggle() {
|
---|
97 | return __awaiter(this, void 0, void 0, function* () {
|
---|
98 | return (yield this._button()).click();
|
---|
99 | });
|
---|
100 | }
|
---|
101 | /**
|
---|
102 | * Puts the button toggle in a checked state by toggling it if it's
|
---|
103 | * currently unchecked, or doing nothing if it is already checked.
|
---|
104 | */
|
---|
105 | check() {
|
---|
106 | return __awaiter(this, void 0, void 0, function* () {
|
---|
107 | if (!(yield this.isChecked())) {
|
---|
108 | yield this.toggle();
|
---|
109 | }
|
---|
110 | });
|
---|
111 | }
|
---|
112 | /**
|
---|
113 | * Puts the button toggle in an unchecked state by toggling it if it's
|
---|
114 | * currently checked, or doing nothing if it's already unchecked.
|
---|
115 | */
|
---|
116 | uncheck() {
|
---|
117 | return __awaiter(this, void 0, void 0, function* () {
|
---|
118 | if (yield this.isChecked()) {
|
---|
119 | yield this.toggle();
|
---|
120 | }
|
---|
121 | });
|
---|
122 | }
|
---|
123 | }
|
---|
124 | /** The selector for the host element of a `MatButton` instance. */
|
---|
125 | MatButtonToggleHarness.hostSelector = '.mat-button-toggle';
|
---|
126 |
|
---|
127 | /**
|
---|
128 | * @license
|
---|
129 | * Copyright Google LLC All Rights Reserved.
|
---|
130 | *
|
---|
131 | * Use of this source code is governed by an MIT-style license that can be
|
---|
132 | * found in the LICENSE file at https://angular.io/license
|
---|
133 | */
|
---|
134 |
|
---|
135 | /**
|
---|
136 | * @license
|
---|
137 | * Copyright Google LLC All Rights Reserved.
|
---|
138 | *
|
---|
139 | * Use of this source code is governed by an MIT-style license that can be
|
---|
140 | * found in the LICENSE file at https://angular.io/license
|
---|
141 | */
|
---|
142 | /** Harness for interacting with a standard mat-button-toggle in tests. */
|
---|
143 | class MatButtonToggleGroupHarness extends ComponentHarness {
|
---|
144 | /**
|
---|
145 | * Gets a `HarnessPredicate` that can be used to search for a `MatButtonToggleGroupHarness`
|
---|
146 | * that meets certain criteria.
|
---|
147 | * @param options Options for filtering which button toggle instances are considered a match.
|
---|
148 | * @return a `HarnessPredicate` configured with the given options.
|
---|
149 | */
|
---|
150 | static with(options = {}) {
|
---|
151 | return new HarnessPredicate(MatButtonToggleGroupHarness, options);
|
---|
152 | }
|
---|
153 | /**
|
---|
154 | * Gets the button toggles that are inside the group.
|
---|
155 | * @param filter Optionally filters which toggles are included.
|
---|
156 | */
|
---|
157 | getToggles(filter = {}) {
|
---|
158 | return __awaiter(this, void 0, void 0, function* () {
|
---|
159 | return this.locatorForAll(MatButtonToggleHarness.with(filter))();
|
---|
160 | });
|
---|
161 | }
|
---|
162 | /** Gets whether the button toggle group is disabled. */
|
---|
163 | isDisabled() {
|
---|
164 | return __awaiter(this, void 0, void 0, function* () {
|
---|
165 | return (yield (yield this.host()).getAttribute('aria-disabled')) === 'true';
|
---|
166 | });
|
---|
167 | }
|
---|
168 | /** Gets whether the button toggle group is laid out vertically. */
|
---|
169 | isVertical() {
|
---|
170 | return __awaiter(this, void 0, void 0, function* () {
|
---|
171 | return (yield this.host()).hasClass('mat-button-toggle-vertical');
|
---|
172 | });
|
---|
173 | }
|
---|
174 | /** Gets the appearance that the group is using. */
|
---|
175 | getAppearance() {
|
---|
176 | return __awaiter(this, void 0, void 0, function* () {
|
---|
177 | const host = yield this.host();
|
---|
178 | const className = 'mat-button-toggle-group-appearance-standard';
|
---|
179 | return (yield host.hasClass(className)) ? 'standard' : 'legacy';
|
---|
180 | });
|
---|
181 | }
|
---|
182 | }
|
---|
183 | /** The selector for the host element of a `MatButton` instance. */
|
---|
184 | MatButtonToggleGroupHarness.hostSelector = '.mat-button-toggle-group';
|
---|
185 |
|
---|
186 | /**
|
---|
187 | * @license
|
---|
188 | * Copyright Google LLC All Rights Reserved.
|
---|
189 | *
|
---|
190 | * Use of this source code is governed by an MIT-style license that can be
|
---|
191 | * found in the LICENSE file at https://angular.io/license
|
---|
192 | */
|
---|
193 |
|
---|
194 | /**
|
---|
195 | * @license
|
---|
196 | * Copyright Google LLC All Rights Reserved.
|
---|
197 | *
|
---|
198 | * Use of this source code is governed by an MIT-style license that can be
|
---|
199 | * found in the LICENSE file at https://angular.io/license
|
---|
200 | */
|
---|
201 |
|
---|
202 | /**
|
---|
203 | * @license
|
---|
204 | * Copyright Google LLC All Rights Reserved.
|
---|
205 | *
|
---|
206 | * Use of this source code is governed by an MIT-style license that can be
|
---|
207 | * found in the LICENSE file at https://angular.io/license
|
---|
208 | */
|
---|
209 |
|
---|
210 | export { MatButtonToggleGroupHarness, MatButtonToggleHarness };
|
---|
211 | //# sourceMappingURL=testing.js.map
|
---|