source: trip-planner-front/node_modules/@angular/material/fesm2015/slide-toggle/testing.js@ 59329aa

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

initial commit

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