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 | */
|
---|
8 | import { __awaiter } from "tslib";
|
---|
9 | import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
|
---|
10 | /** Harness for interacting with a native `option` in tests. */
|
---|
11 | export class MatNativeOptionHarness extends ComponentHarness {
|
---|
12 | /**
|
---|
13 | * Gets a `HarnessPredicate` that can be used to search for a `MatNativeOptionHarness` that meets
|
---|
14 | * certain criteria.
|
---|
15 | * @param options Options for filtering which option instances are considered a match.
|
---|
16 | * @return a `HarnessPredicate` configured with the given options.
|
---|
17 | */
|
---|
18 | static with(options = {}) {
|
---|
19 | return new HarnessPredicate(MatNativeOptionHarness, options)
|
---|
20 | .addOption('text', options.text, (harness, title) => __awaiter(this, void 0, void 0, function* () { return HarnessPredicate.stringMatches(yield harness.getText(), title); }))
|
---|
21 | .addOption('index', options.index, (harness, index) => __awaiter(this, void 0, void 0, function* () { return (yield harness.getIndex()) === index; }))
|
---|
22 | .addOption('isSelected', options.isSelected, (harness, isSelected) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isSelected()) === isSelected; }));
|
---|
23 | }
|
---|
24 | /** Gets the option's label text. */
|
---|
25 | getText() {
|
---|
26 | return __awaiter(this, void 0, void 0, function* () {
|
---|
27 | return (yield this.host()).getProperty('label');
|
---|
28 | });
|
---|
29 | }
|
---|
30 | /** Index of the option within the native `select` element. */
|
---|
31 | getIndex() {
|
---|
32 | return __awaiter(this, void 0, void 0, function* () {
|
---|
33 | return (yield this.host()).getProperty('index');
|
---|
34 | });
|
---|
35 | }
|
---|
36 | /** Gets whether the option is disabled. */
|
---|
37 | isDisabled() {
|
---|
38 | return __awaiter(this, void 0, void 0, function* () {
|
---|
39 | return (yield this.host()).getProperty('disabled');
|
---|
40 | });
|
---|
41 | }
|
---|
42 | /** Gets whether the option is selected. */
|
---|
43 | isSelected() {
|
---|
44 | return __awaiter(this, void 0, void 0, function* () {
|
---|
45 | return (yield this.host()).getProperty('selected');
|
---|
46 | });
|
---|
47 | }
|
---|
48 | }
|
---|
49 | /** Selector used to locate option instances. */
|
---|
50 | MatNativeOptionHarness.hostSelector = 'select[matNativeControl] option';
|
---|
51 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoibmF0aXZlLW9wdGlvbi1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL2lucHV0L3Rlc3RpbmcvbmF0aXZlLW9wdGlvbi1oYXJuZXNzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRzs7QUFFSCxPQUFPLEVBQUMsZ0JBQWdCLEVBQUUsZ0JBQWdCLEVBQUMsTUFBTSxzQkFBc0IsQ0FBQztBQUd4RSwrREFBK0Q7QUFDL0QsTUFBTSxPQUFPLHNCQUF1QixTQUFRLGdCQUFnQjtJQUkxRDs7Ozs7T0FLRztJQUNILE1BQU0sQ0FBQyxJQUFJLENBQUMsVUFBc0MsRUFBRTtRQUNsRCxPQUFPLElBQUksZ0JBQWdCLENBQUMsc0JBQXNCLEVBQUUsT0FBTyxDQUFDO2FBQ3ZELFNBQVMsQ0FBQyxNQUFNLEVBQUUsT0FBTyxDQUFDLElBQUksRUFDM0IsQ0FBTyxPQUFPLEVBQUUsS0FBSyxFQUFFLEVBQUUsZ0RBQ3JCLE9BQUEsZ0JBQWdCLENBQUMsYUFBYSxDQUFDLE1BQU0sT0FBTyxDQUFDLE9BQU8sRUFBRSxFQUFFLEtBQUssQ0FBQyxDQUFBLEdBQUEsQ0FBQzthQUN0RSxTQUFTLENBQUMsT0FBTyxFQUFFLE9BQU8sQ0FBQyxLQUFLLEVBQzdCLENBQU8sT0FBTyxF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