source: trip-planner-front/node_modules/@angular/material/esm2015/input/testing/native-select-harness.js@ bdd6491

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

initial commit

  • Property mode set to 100644
File size: 12.0 KB
Line 
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { __awaiter } from "tslib";
9import { HarnessPredicate, parallel } from '@angular/cdk/testing';
10import { MatFormFieldControlHarness } from '@angular/material/form-field/testing/control';
11import { MatNativeOptionHarness } from './native-option-harness';
12/** Harness for interacting with a native `select` in tests. */
13export class MatNativeSelectHarness extends MatFormFieldControlHarness {
14 /**
15 * Gets a `HarnessPredicate` that can be used to search for a `MatNativeSelectHarness` that meets
16 * certain criteria.
17 * @param options Options for filtering which select instances are considered a match.
18 * @return a `HarnessPredicate` configured with the given options.
19 */
20 static with(options = {}) {
21 return new HarnessPredicate(MatNativeSelectHarness, options);
22 }
23 /** Gets a boolean promise indicating if the select is disabled. */
24 isDisabled() {
25 return __awaiter(this, void 0, void 0, function* () {
26 return (yield this.host()).getProperty('disabled');
27 });
28 }
29 /** Gets a boolean promise indicating if the select is required. */
30 isRequired() {
31 return __awaiter(this, void 0, void 0, function* () {
32 return (yield this.host()).getProperty('required');
33 });
34 }
35 /** Gets a boolean promise indicating if the select is in multi-selection mode. */
36 isMultiple() {
37 return __awaiter(this, void 0, void 0, function* () {
38 return (yield this.host()).getProperty('multiple');
39 });
40 }
41 /** Gets the name of the select. */
42 getName() {
43 return __awaiter(this, void 0, void 0, function* () {
44 // The "name" property of the native select is never undefined.
45 return (yield (yield this.host()).getProperty('name'));
46 });
47 }
48 /** Gets the id of the select. */
49 getId() {
50 return __awaiter(this, void 0, void 0, function* () {
51 // We're guaranteed to have an id, because the `matNativeControl` always assigns one.
52 return (yield (yield this.host()).getProperty('id'));
53 });
54 }
55 /** Focuses the select and returns a void promise that indicates when the action is complete. */
56 focus() {
57 return __awaiter(this, void 0, void 0, function* () {
58 return (yield this.host()).focus();
59 });
60 }
61 /** Blurs the select and returns a void promise that indicates when the action is complete. */
62 blur() {
63 return __awaiter(this, void 0, void 0, function* () {
64 return (yield this.host()).blur();
65 });
66 }
67 /** Whether the select is focused. */
68 isFocused() {
69 return __awaiter(this, void 0, void 0, function* () {
70 return (yield this.host()).isFocused();
71 });
72 }
73 /** Gets the options inside the select panel. */
74 getOptions(filter = {}) {
75 return __awaiter(this, void 0, void 0, function* () {
76 return this.locatorForAll(MatNativeOptionHarness.with(filter))();
77 });
78 }
79 /**
80 * Selects the options that match the passed-in filter. If the select is in multi-selection
81 * mode all options will be clicked, otherwise the harness will pick the first matching option.
82 */
83 selectOptions(filter = {}) {
84 return __awaiter(this, void 0, void 0, function* () {
85 const [isMultiple, options] = yield parallel(() => {
86 return [this.isMultiple(), this.getOptions(filter)];
87 });
88 if (options.length === 0) {
89 throw Error('Select does not have options matching the specified filter');
90 }
91 const [host, optionIndexes] = yield parallel(() => [
92 this.host(),
93 parallel(() => options.slice(0, isMultiple ? undefined : 1).map(option => option.getIndex()))
94 ]);
95 yield host.selectOptions(...optionIndexes);
96 });
97 }
98}
99MatNativeSelectHarness.hostSelector = 'select[matNativeControl]';
100//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF0aXZlLXNlbGVjdC1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL2lucHV0L3Rlc3RpbmcvbmF0aXZlLXNlbGVjdC1oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRzs7QUFFSCxPQUFPLEVBQUMsZ0JBQWdCLEVBQUUsUUFBUSxFQUFDLE1BQU0sc0JBQXNCLENBQUM7QUFDaEUsT0FBTyxFQUFDLDBCQUEwQixFQUFDL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