source: trip-planner-front/node_modules/@angular/material/fesm2015/chips/testing.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 17.5 KB
Line 
1import { __awaiter } from 'tslib';
2import { ComponentHarness, HarnessPredicate, ContentContainerComponentHarness, TestKey, parallel } 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 standard Material chip avatar in tests. */
12class MatChipAvatarHarness extends ComponentHarness {
13 /**
14 * Gets a `HarnessPredicate` that can be used to search for a `MatChipAvatarHarness` that meets
15 * certain criteria.
16 * @param options Options for filtering which input instances are considered a match.
17 * @return a `HarnessPredicate` configured with the given options.
18 */
19 static with(options = {}) {
20 return new HarnessPredicate(MatChipAvatarHarness, options);
21 }
22}
23MatChipAvatarHarness.hostSelector = '.mat-chip-avatar';
24
25/**
26 * @license
27 * Copyright Google LLC All Rights Reserved.
28 *
29 * Use of this source code is governed by an MIT-style license that can be
30 * found in the LICENSE file at https://angular.io/license
31 */
32/** Harness for interacting with a standard Material chip remove button in tests. */
33class MatChipRemoveHarness extends ComponentHarness {
34 /**
35 * Gets a `HarnessPredicate` that can be used to search for a `MatChipRemoveHarness` that meets
36 * certain criteria.
37 * @param options Options for filtering which input instances are considered a match.
38 * @return a `HarnessPredicate` configured with the given options.
39 */
40 static with(options = {}) {
41 return new HarnessPredicate(MatChipRemoveHarness, options);
42 }
43 /** Clicks the remove button. */
44 click() {
45 return __awaiter(this, void 0, void 0, function* () {
46 return (yield this.host()).click();
47 });
48 }
49}
50MatChipRemoveHarness.hostSelector = '.mat-chip-remove';
51
52/**
53 * @license
54 * Copyright Google LLC All Rights Reserved.
55 *
56 * Use of this source code is governed by an MIT-style license that can be
57 * found in the LICENSE file at https://angular.io/license
58 */
59/** Harness for interacting with a standard selectable Angular Material chip in tests. */
60class MatChipHarness extends ContentContainerComponentHarness {
61 /**
62 * Gets a `HarnessPredicate` that can be used to search for a `MatChipHarness` that meets
63 * certain criteria.
64 * @param options Options for filtering which chip instances are considered a match.
65 * @return a `HarnessPredicate` configured with the given options.
66 */
67 static with(options = {}) {
68 return new HarnessPredicate(MatChipHarness, options)
69 .addOption('text', options.text, (harness, label) => HarnessPredicate.stringMatches(harness.getText(), label))
70 .addOption('selected', options.selected, (harness, selected) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isSelected()) === selected; }));
71 }
72 /** Gets the text of the chip. */
73 getText() {
74 return __awaiter(this, void 0, void 0, function* () {
75 return (yield this.host()).text({
76 exclude: '.mat-chip-avatar, .mat-chip-trailing-icon, .mat-icon'
77 });
78 });
79 }
80 /**
81 * Whether the chip is selected.
82 * @deprecated Use `MatChipOptionHarness.isSelected` instead.
83 * @breaking-change 12.0.0
84 */
85 isSelected() {
86 return __awaiter(this, void 0, void 0, function* () {
87 return (yield this.host()).hasClass('mat-chip-selected');
88 });
89 }
90 /** Whether the chip is disabled. */
91 isDisabled() {
92 return __awaiter(this, void 0, void 0, function* () {
93 return (yield this.host()).hasClass('mat-chip-disabled');
94 });
95 }
96 /**
97 * Selects the given chip. Only applies if it's selectable.
98 * @deprecated Use `MatChipOptionHarness.select` instead.
99 * @breaking-change 12.0.0
100 */
101 select() {
102 return __awaiter(this, void 0, void 0, function* () {
103 if (!(yield this.isSelected())) {
104 yield this.toggle();
105 }
106 });
107 }
108 /**
109 * Deselects the given chip. Only applies if it's selectable.
110 * @deprecated Use `MatChipOptionHarness.deselect` instead.
111 * @breaking-change 12.0.0
112 */
113 deselect() {
114 return __awaiter(this, void 0, void 0, function* () {
115 if (yield this.isSelected()) {
116 yield this.toggle();
117 }
118 });
119 }
120 /**
121 * Toggles the selected state of the given chip. Only applies if it's selectable.
122 * @deprecated Use `MatChipOptionHarness.toggle` instead.
123 * @breaking-change 12.0.0
124 */
125 toggle() {
126 return __awaiter(this, void 0, void 0, function* () {
127 return (yield this.host()).sendKeys(' ');
128 });
129 }
130 /** Removes the given chip. Only applies if it's removable. */
131 remove() {
132 return __awaiter(this, void 0, void 0, function* () {
133 yield (yield this.host()).sendKeys(TestKey.DELETE);
134 });
135 }
136 /**
137 * Gets the remove button inside of a chip.
138 * @param filter Optionally filters which remove buttons are included.
139 */
140 getRemoveButton(filter = {}) {
141 return __awaiter(this, void 0, void 0, function* () {
142 return this.locatorFor(MatChipRemoveHarness.with(filter))();
143 });
144 }
145 /**
146 * Gets the avatar inside a chip.
147 * @param filter Optionally filters which avatars are included.
148 */
149 getAvatar(filter = {}) {
150 return __awaiter(this, void 0, void 0, function* () {
151 return this.locatorForOptional(MatChipAvatarHarness.with(filter))();
152 });
153 }
154}
155/** The selector for the host element of a `MatChip` instance. */
156MatChipHarness.hostSelector = '.mat-chip';
157
158/**
159 * @license
160 * Copyright Google LLC All Rights Reserved.
161 *
162 * Use of this source code is governed by an MIT-style license that can be
163 * found in the LICENSE file at https://angular.io/license
164 */
165/** Harness for interacting with a standard Material chip inputs in tests. */
166class MatChipInputHarness extends ComponentHarness {
167 /**
168 * Gets a `HarnessPredicate` that can be used to search for a `MatChipInputHarness` that meets
169 * certain criteria.
170 * @param options Options for filtering which input instances are considered a match.
171 * @return a `HarnessPredicate` configured with the given options.
172 */
173 static with(options = {}) {
174 return new HarnessPredicate(MatChipInputHarness, options)
175 .addOption('value', options.value, (harness, value) => __awaiter(this, void 0, void 0, function* () {
176 return (yield harness.getValue()) === value;
177 }))
178 .addOption('placeholder', options.placeholder, (harness, placeholder) => __awaiter(this, void 0, void 0, function* () {
179 return (yield harness.getPlaceholder()) === placeholder;
180 }));
181 }
182 /** Whether the input is disabled. */
183 isDisabled() {
184 return __awaiter(this, void 0, void 0, function* () {
185 return (yield this.host()).getProperty('disabled');
186 });
187 }
188 /** Whether the input is required. */
189 isRequired() {
190 return __awaiter(this, void 0, void 0, function* () {
191 return (yield this.host()).getProperty('required');
192 });
193 }
194 /** Gets the value of the input. */
195 getValue() {
196 return __awaiter(this, void 0, void 0, function* () {
197 // The "value" property of the native input is never undefined.
198 return (yield (yield this.host()).getProperty('value'));
199 });
200 }
201 /** Gets the placeholder of the input. */
202 getPlaceholder() {
203 return __awaiter(this, void 0, void 0, function* () {
204 return (yield (yield this.host()).getProperty('placeholder'));
205 });
206 }
207 /**
208 * Focuses the input and returns a promise that indicates when the
209 * action is complete.
210 */
211 focus() {
212 return __awaiter(this, void 0, void 0, function* () {
213 return (yield this.host()).focus();
214 });
215 }
216 /**
217 * Blurs the input and returns a promise that indicates when the
218 * action is complete.
219 */
220 blur() {
221 return __awaiter(this, void 0, void 0, function* () {
222 return (yield this.host()).blur();
223 });
224 }
225 /** Whether the input is focused. */
226 isFocused() {
227 return __awaiter(this, void 0, void 0, function* () {
228 return (yield this.host()).isFocused();
229 });
230 }
231 /**
232 * Sets the value of the input. The value will be set by simulating
233 * keypresses that correspond to the given value.
234 */
235 setValue(newValue) {
236 return __awaiter(this, void 0, void 0, function* () {
237 const inputEl = yield this.host();
238 yield inputEl.clear();
239 // We don't want to send keys for the value if the value is an empty
240 // string in order to clear the value. Sending keys with an empty string
241 // still results in unnecessary focus events.
242 if (newValue) {
243 yield inputEl.sendKeys(newValue);
244 }
245 });
246 }
247 /** Sends a chip separator key to the input element. */
248 sendSeparatorKey(key) {
249 return __awaiter(this, void 0, void 0, function* () {
250 const inputEl = yield this.host();
251 return inputEl.sendKeys(key);
252 });
253 }
254}
255MatChipInputHarness.hostSelector = '.mat-chip-input';
256
257/**
258 * @license
259 * Copyright Google LLC All Rights Reserved.
260 *
261 * Use of this source code is governed by an MIT-style license that can be
262 * found in the LICENSE file at https://angular.io/license
263 */
264/** Base class for chip list harnesses. */
265class _MatChipListHarnessBase extends ComponentHarness {
266 /** Gets whether the chip list is disabled. */
267 isDisabled() {
268 return __awaiter(this, void 0, void 0, function* () {
269 return (yield (yield this.host()).getAttribute('aria-disabled')) === 'true';
270 });
271 }
272 /** Gets whether the chip list is required. */
273 isRequired() {
274 return __awaiter(this, void 0, void 0, function* () {
275 return (yield (yield this.host()).getAttribute('aria-required')) === 'true';
276 });
277 }
278 /** Gets whether the chip list is invalid. */
279 isInvalid() {
280 return __awaiter(this, void 0, void 0, function* () {
281 return (yield (yield this.host()).getAttribute('aria-invalid')) === 'true';
282 });
283 }
284 /** Gets whether the chip list is in multi selection mode. */
285 isMultiple() {
286 return __awaiter(this, void 0, void 0, function* () {
287 return (yield (yield this.host()).getAttribute('aria-multiselectable')) === 'true';
288 });
289 }
290 /** Gets whether the orientation of the chip list. */
291 getOrientation() {
292 return __awaiter(this, void 0, void 0, function* () {
293 const orientation = yield (yield this.host()).getAttribute('aria-orientation');
294 return orientation === 'vertical' ? 'vertical' : 'horizontal';
295 });
296 }
297}
298/** Harness for interacting with a standard chip list in tests. */
299class MatChipListHarness extends _MatChipListHarnessBase {
300 /**
301 * Gets a `HarnessPredicate` that can be used to search for a `MatChipListHarness` that meets
302 * certain criteria.
303 * @param options Options for filtering which chip list instances are considered a match.
304 * @return a `HarnessPredicate` configured with the given options.
305 */
306 static with(options = {}) {
307 return new HarnessPredicate(MatChipListHarness, options);
308 }
309 /**
310 * Gets the list of chips inside the chip list.
311 * @param filter Optionally filters which chips are included.
312 */
313 getChips(filter = {}) {
314 return __awaiter(this, void 0, void 0, function* () {
315 return this.locatorForAll(MatChipHarness.with(filter))();
316 });
317 }
318 /**
319 * Selects a chip inside the chip list.
320 * @param filter An optional filter to apply to the child chips.
321 * All the chips matching the filter will be selected.
322 * @deprecated Use `MatChipListboxHarness.selectChips` instead.
323 * @breaking-change 12.0.0
324 */
325 selectChips(filter = {}) {
326 return __awaiter(this, void 0, void 0, function* () {
327 const chips = yield this.getChips(filter);
328 if (!chips.length) {
329 throw Error(`Cannot find chip matching filter ${JSON.stringify(filter)}`);
330 }
331 yield parallel(() => chips.map(chip => chip.select()));
332 });
333 }
334 /**
335 * Gets the `MatChipInput` inside the chip list.
336 * @param filter Optionally filters which chip input is included.
337 */
338 getInput(filter = {}) {
339 return __awaiter(this, void 0, void 0, function* () {
340 // The input isn't required to be a descendant of the chip list so we have to look it up by id.
341 const inputId = yield (yield this.host()).getAttribute('data-mat-chip-input');
342 if (!inputId) {
343 throw Error(`Chip list is not associated with an input`);
344 }
345 return this.documentRootLocatorFactory().locatorFor(MatChipInputHarness.with(Object.assign(Object.assign({}, filter), { selector: `#${inputId}` })))();
346 });
347 }
348}
349/** The selector for the host element of a `MatChipList` instance. */
350MatChipListHarness.hostSelector = '.mat-chip-list';
351
352/**
353 * @license
354 * Copyright Google LLC All Rights Reserved.
355 *
356 * Use of this source code is governed by an MIT-style license that can be
357 * found in the LICENSE file at https://angular.io/license
358 */
359class MatChipOptionHarness extends MatChipHarness {
360 /**
361 * Gets a `HarnessPredicate` that can be used to search for a `MatChipOptionHarness`
362 * that meets certain criteria.
363 * @param options Options for filtering which chip instances are considered a match.
364 * @return a `HarnessPredicate` configured with the given options.
365 */
366 static with(options = {}) {
367 return new HarnessPredicate(MatChipOptionHarness, options)
368 .addOption('text', options.text, (harness, label) => HarnessPredicate.stringMatches(harness.getText(), label))
369 .addOption('selected', options.selected, (harness, selected) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isSelected()) === selected; }));
370 }
371 /** Whether the chip is selected. */
372 isSelected() {
373 return __awaiter(this, void 0, void 0, function* () {
374 return (yield this.host()).hasClass('mat-chip-selected');
375 });
376 }
377 /** Selects the given chip. Only applies if it's selectable. */
378 select() {
379 return __awaiter(this, void 0, void 0, function* () {
380 if (!(yield this.isSelected())) {
381 yield this.toggle();
382 }
383 });
384 }
385 /** Deselects the given chip. Only applies if it's selectable. */
386 deselect() {
387 return __awaiter(this, void 0, void 0, function* () {
388 if (yield this.isSelected()) {
389 yield this.toggle();
390 }
391 });
392 }
393 /** Toggles the selected state of the given chip. */
394 toggle() {
395 return __awaiter(this, void 0, void 0, function* () {
396 return (yield this.host()).sendKeys(' ');
397 });
398 }
399}
400/** The selector for the host element of a selectable chip instance. */
401MatChipOptionHarness.hostSelector = '.mat-chip';
402
403/**
404 * @license
405 * Copyright Google LLC All Rights Reserved.
406 *
407 * Use of this source code is governed by an MIT-style license that can be
408 * found in the LICENSE file at https://angular.io/license
409 */
410/** Harness for interacting with a standard selectable chip list in tests. */
411class MatChipListboxHarness extends _MatChipListHarnessBase {
412 /**
413 * Gets a `HarnessPredicate` that can be used to search for a `MatChipListHarness` that meets
414 * certain criteria.
415 * @param options Options for filtering which chip list instances are considered a match.
416 * @return a `HarnessPredicate` configured with the given options.
417 */
418 static with(options = {}) {
419 return new HarnessPredicate(MatChipListboxHarness, options);
420 }
421 /**
422 * Gets the list of chips inside the chip list.
423 * @param filter Optionally filters which chips are included.
424 */
425 getChips(filter = {}) {
426 return __awaiter(this, void 0, void 0, function* () {
427 return this.locatorForAll(MatChipOptionHarness.with(filter))();
428 });
429 }
430 /**
431 * Selects a chip inside the chip list.
432 * @param filter An optional filter to apply to the child chips.
433 * All the chips matching the filter will be selected.
434 */
435 selectChips(filter = {}) {
436 return __awaiter(this, void 0, void 0, function* () {
437 const chips = yield this.getChips(filter);
438 if (!chips.length) {
439 throw Error(`Cannot find chip matching filter ${JSON.stringify(filter)}`);
440 }
441 yield parallel(() => chips.map(chip => chip.select()));
442 });
443 }
444}
445/** The selector for the host element of a `MatChipList` instance. */
446MatChipListboxHarness.hostSelector = '.mat-chip-list';
447
448/**
449 * @license
450 * Copyright Google LLC All Rights Reserved.
451 *
452 * Use of this source code is governed by an MIT-style license that can be
453 * found in the LICENSE file at https://angular.io/license
454 */
455
456/**
457 * @license
458 * Copyright Google LLC All Rights Reserved.
459 *
460 * Use of this source code is governed by an MIT-style license that can be
461 * found in the LICENSE file at https://angular.io/license
462 */
463
464export { MatChipHarness, MatChipInputHarness, MatChipListHarness, MatChipListboxHarness, MatChipOptionHarness, MatChipRemoveHarness };
465//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.