source: trip-planner-front/node_modules/@angular/material/fesm2015/autocomplete/testing.js@ e29cc2e

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

initial commit

  • Property mode set to 100644
File size: 5.7 KB
Line 
1import { __awaiter } from 'tslib';
2import { coerceBooleanProperty } from '@angular/cdk/coercion';
3import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
4import { MatOptionHarness, MatOptgroupHarness } from '@angular/material/core/testing';
5
6/**
7 * @license
8 * Copyright Google LLC All Rights Reserved.
9 *
10 * Use of this source code is governed by an MIT-style license that can be
11 * found in the LICENSE file at https://angular.io/license
12 */
13class _MatAutocompleteHarnessBase extends ComponentHarness {
14 constructor() {
15 super(...arguments);
16 this._documentRootLocator = this.documentRootLocatorFactory();
17 }
18 /** Gets the value of the autocomplete input. */
19 getValue() {
20 return __awaiter(this, void 0, void 0, function* () {
21 return (yield this.host()).getProperty('value');
22 });
23 }
24 /** Whether the autocomplete input is disabled. */
25 isDisabled() {
26 return __awaiter(this, void 0, void 0, function* () {
27 const disabled = (yield this.host()).getAttribute('disabled');
28 return coerceBooleanProperty(yield disabled);
29 });
30 }
31 /** Focuses the autocomplete input. */
32 focus() {
33 return __awaiter(this, void 0, void 0, function* () {
34 return (yield this.host()).focus();
35 });
36 }
37 /** Blurs the autocomplete input. */
38 blur() {
39 return __awaiter(this, void 0, void 0, function* () {
40 return (yield this.host()).blur();
41 });
42 }
43 /** Whether the autocomplete input is focused. */
44 isFocused() {
45 return __awaiter(this, void 0, void 0, function* () {
46 return (yield this.host()).isFocused();
47 });
48 }
49 /** Enters text into the autocomplete. */
50 enterText(value) {
51 return __awaiter(this, void 0, void 0, function* () {
52 return (yield this.host()).sendKeys(value);
53 });
54 }
55 /** Gets the options inside the autocomplete panel. */
56 getOptions(filters) {
57 return __awaiter(this, void 0, void 0, function* () {
58 return this._documentRootLocator.locatorForAll(this._optionClass.with(Object.assign(Object.assign({}, (filters || {})), { ancestor: yield this._getPanelSelector() })))();
59 });
60 }
61 /** Gets the option groups inside the autocomplete panel. */
62 getOptionGroups(filters) {
63 return __awaiter(this, void 0, void 0, function* () {
64 return this._documentRootLocator.locatorForAll(this._optionGroupClass.with(Object.assign(Object.assign({}, (filters || {})), { ancestor: yield this._getPanelSelector() })))();
65 });
66 }
67 /** Selects the first option matching the given filters. */
68 selectOption(filters) {
69 return __awaiter(this, void 0, void 0, function* () {
70 yield this.focus(); // Focus the input to make sure the autocomplete panel is shown.
71 const options = yield this.getOptions(filters);
72 if (!options.length) {
73 throw Error(`Could not find a mat-option matching ${JSON.stringify(filters)}`);
74 }
75 yield options[0].click();
76 });
77 }
78 /** Whether the autocomplete is open. */
79 isOpen() {
80 return __awaiter(this, void 0, void 0, function* () {
81 const panel = yield this._getPanel();
82 return !!panel && (yield panel.hasClass(`${this._prefix}-autocomplete-visible`));
83 });
84 }
85 /** Gets the panel associated with this autocomplete trigger. */
86 _getPanel() {
87 return __awaiter(this, void 0, void 0, function* () {
88 // Technically this is static, but it needs to be in a
89 // function, because the autocomplete's panel ID can changed.
90 return this._documentRootLocator.locatorForOptional(yield this._getPanelSelector())();
91 });
92 }
93 /** Gets the selector that can be used to find the autocomplete trigger's panel. */
94 _getPanelSelector() {
95 return __awaiter(this, void 0, void 0, function* () {
96 return `#${(yield (yield this.host()).getAttribute('aria-owns'))}`;
97 });
98 }
99}
100/** Harness for interacting with a standard mat-autocomplete in tests. */
101class MatAutocompleteHarness extends _MatAutocompleteHarnessBase {
102 constructor() {
103 super(...arguments);
104 this._prefix = 'mat';
105 this._optionClass = MatOptionHarness;
106 this._optionGroupClass = MatOptgroupHarness;
107 }
108 /**
109 * Gets a `HarnessPredicate` that can be used to search for a `MatAutocompleteHarness` that meets
110 * certain criteria.
111 * @param options Options for filtering which autocomplete instances are considered a match.
112 * @return a `HarnessPredicate` configured with the given options.
113 */
114 static with(options = {}) {
115 return new HarnessPredicate(MatAutocompleteHarness, options)
116 .addOption('value', options.value, (harness, value) => HarnessPredicate.stringMatches(harness.getValue(), value));
117 }
118}
119/** The selector for the host element of a `MatAutocomplete` instance. */
120MatAutocompleteHarness.hostSelector = '.mat-autocomplete-trigger';
121
122/**
123 * @license
124 * Copyright Google LLC All Rights Reserved.
125 *
126 * Use of this source code is governed by an MIT-style license that can be
127 * found in the LICENSE file at https://angular.io/license
128 */
129
130/**
131 * @license
132 * Copyright Google LLC All Rights Reserved.
133 *
134 * Use of this source code is governed by an MIT-style license that can be
135 * found in the LICENSE file at https://angular.io/license
136 */
137
138/**
139 * @license
140 * Copyright Google LLC All Rights Reserved.
141 *
142 * Use of this source code is governed by an MIT-style license that can be
143 * found in the LICENSE file at https://angular.io/license
144 */
145
146export { MatAutocompleteHarness, _MatAutocompleteHarnessBase };
147//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.