source: trip-planner-front/node_modules/@angular/material/fesm2015/checkbox/testing.js@ 6c1585f

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

initial commit

  • Property mode set to 100644
File size: 6.8 KB
Line 
1import { __awaiter } from 'tslib';
2import { coerceBooleanProperty } from '@angular/cdk/coercion';
3import { ComponentHarness, HarnessPredicate } from '@angular/cdk/testing';
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 */
12class _MatCheckboxHarnessBase extends ComponentHarness {
13 /** Whether the checkbox is checked. */
14 isChecked() {
15 return __awaiter(this, void 0, void 0, function* () {
16 const checked = (yield this._input()).getProperty('checked');
17 return coerceBooleanProperty(yield checked);
18 });
19 }
20 /** Whether the checkbox is in an indeterminate state. */
21 isIndeterminate() {
22 return __awaiter(this, void 0, void 0, function* () {
23 const indeterminate = (yield this._input()).getProperty('indeterminate');
24 return coerceBooleanProperty(yield indeterminate);
25 });
26 }
27 /** Whether the checkbox is disabled. */
28 isDisabled() {
29 return __awaiter(this, void 0, void 0, function* () {
30 const disabled = (yield this._input()).getAttribute('disabled');
31 return coerceBooleanProperty(yield disabled);
32 });
33 }
34 /** Whether the checkbox is required. */
35 isRequired() {
36 return __awaiter(this, void 0, void 0, function* () {
37 const required = (yield this._input()).getProperty('required');
38 return coerceBooleanProperty(yield required);
39 });
40 }
41 /** Whether the checkbox is valid. */
42 isValid() {
43 return __awaiter(this, void 0, void 0, function* () {
44 const invalid = (yield this.host()).hasClass('ng-invalid');
45 return !(yield invalid);
46 });
47 }
48 /** Gets the checkbox's name. */
49 getName() {
50 return __awaiter(this, void 0, void 0, function* () {
51 return (yield this._input()).getAttribute('name');
52 });
53 }
54 /** Gets the checkbox's value. */
55 getValue() {
56 return __awaiter(this, void 0, void 0, function* () {
57 return (yield this._input()).getProperty('value');
58 });
59 }
60 /** Gets the checkbox's aria-label. */
61 getAriaLabel() {
62 return __awaiter(this, void 0, void 0, function* () {
63 return (yield this._input()).getAttribute('aria-label');
64 });
65 }
66 /** Gets the checkbox's aria-labelledby. */
67 getAriaLabelledby() {
68 return __awaiter(this, void 0, void 0, function* () {
69 return (yield this._input()).getAttribute('aria-labelledby');
70 });
71 }
72 /** Gets the checkbox's label text. */
73 getLabelText() {
74 return __awaiter(this, void 0, void 0, function* () {
75 return (yield this._label()).text();
76 });
77 }
78 /** Focuses the checkbox. */
79 focus() {
80 return __awaiter(this, void 0, void 0, function* () {
81 return (yield this._input()).focus();
82 });
83 }
84 /** Blurs the checkbox. */
85 blur() {
86 return __awaiter(this, void 0, void 0, function* () {
87 return (yield this._input()).blur();
88 });
89 }
90 /** Whether the checkbox is focused. */
91 isFocused() {
92 return __awaiter(this, void 0, void 0, function* () {
93 return (yield this._input()).isFocused();
94 });
95 }
96 /**
97 * Puts the checkbox in a checked state by toggling it if it is currently unchecked, or doing
98 * nothing if it is already checked.
99 *
100 * Note: This attempts to check the checkbox as a user would, by clicking it. Therefore if you
101 * are using `MAT_CHECKBOX_DEFAULT_OPTIONS` to change the behavior on click, calling this method
102 * might not have the expected result.
103 */
104 check() {
105 return __awaiter(this, void 0, void 0, function* () {
106 if (!(yield this.isChecked())) {
107 yield this.toggle();
108 }
109 });
110 }
111 /**
112 * Puts the checkbox in an unchecked state by toggling it if it is currently checked, or doing
113 * nothing if it is already unchecked.
114 *
115 * Note: This attempts to uncheck the checkbox as a user would, by clicking it. Therefore if you
116 * are using `MAT_CHECKBOX_DEFAULT_OPTIONS` to change the behavior on click, calling this method
117 * might not have the expected result.
118 */
119 uncheck() {
120 return __awaiter(this, void 0, void 0, function* () {
121 if (yield this.isChecked()) {
122 yield this.toggle();
123 }
124 });
125 }
126}
127/** Harness for interacting with a standard mat-checkbox in tests. */
128class MatCheckboxHarness extends _MatCheckboxHarnessBase {
129 constructor() {
130 super(...arguments);
131 this._input = this.locatorFor('input');
132 this._label = this.locatorFor('.mat-checkbox-label');
133 this._inputContainer = this.locatorFor('.mat-checkbox-inner-container');
134 }
135 /**
136 * Gets a `HarnessPredicate` that can be used to search for a `MatCheckboxHarness` that meets
137 * certain criteria.
138 * @param options Options for filtering which checkbox instances are considered a match.
139 * @return a `HarnessPredicate` configured with the given options.
140 */
141 static with(options = {}) {
142 return new HarnessPredicate(MatCheckboxHarness, options)
143 .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabelText(), label))
144 // We want to provide a filter option for "name" because the name of the checkbox is
145 // only set on the underlying input. This means that it's not possible for developers
146 // to retrieve the harness of a specific checkbox with name through a CSS selector.
147 .addOption('name', options.name, (harness, name) => __awaiter(this, void 0, void 0, function* () { return (yield harness.getName()) === name; }));
148 }
149 toggle() {
150 return __awaiter(this, void 0, void 0, function* () {
151 return (yield this._inputContainer()).click();
152 });
153 }
154}
155/** The selector for the host element of a `MatCheckbox` instance. */
156MatCheckboxHarness.hostSelector = '.mat-checkbox';
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
166/**
167 * @license
168 * Copyright Google LLC All Rights Reserved.
169 *
170 * Use of this source code is governed by an MIT-style license that can be
171 * found in the LICENSE file at https://angular.io/license
172 */
173
174/**
175 * @license
176 * Copyright Google LLC All Rights Reserved.
177 *
178 * Use of this source code is governed by an MIT-style license that can be
179 * found in the LICENSE file at https://angular.io/license
180 */
181
182export { MatCheckboxHarness, _MatCheckboxHarnessBase };
183//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.