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

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

initial commit

  • Property mode set to 100644
File size: 10.1 KB
Line 
1import { __awaiter } from 'tslib';
2import { ContentContainerComponentHarness, HarnessPredicate, ComponentHarness } from '@angular/cdk/testing';
3
4/**
5 * @license
6 * Copyright Google LLC All Rights Reserved.
7 *
8 * Use of this source code is governed by an MIT-style license that can be
9 * found in the LICENSE file at https://angular.io/license
10 */
11/** Harness for interacting with a standard Angular Material step in tests. */
12class MatStepHarness extends ContentContainerComponentHarness {
13 /**
14 * Gets a `HarnessPredicate` that can be used to search for a `MatStepHarness` that meets
15 * certain criteria.
16 * @param options Options for filtering which steps are considered a match.
17 * @return a `HarnessPredicate` configured with the given options.
18 */
19 static with(options = {}) {
20 return new HarnessPredicate(MatStepHarness, options)
21 .addOption('label', options.label, (harness, label) => HarnessPredicate.stringMatches(harness.getLabel(), label))
22 .addOption('selected', options.selected, (harness, selected) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isSelected()) === selected; }))
23 .addOption('completed', options.completed, (harness, completed) => __awaiter(this, void 0, void 0, function* () { return (yield harness.isCompleted()) === completed; }))
24 .addOption('invalid', options.invalid, (harness, invalid) => __awaiter(this, void 0, void 0, function* () { return (yield harness.hasErrors()) === invalid; }));
25 }
26 /** Gets the label of the step. */
27 getLabel() {
28 return __awaiter(this, void 0, void 0, function* () {
29 return (yield this.locatorFor('.mat-step-text-label')()).text();
30 });
31 }
32 /** Gets the `aria-label` of the step. */
33 getAriaLabel() {
34 return __awaiter(this, void 0, void 0, function* () {
35 return (yield this.host()).getAttribute('aria-label');
36 });
37 }
38 /** Gets the value of the `aria-labelledby` attribute. */
39 getAriaLabelledby() {
40 return __awaiter(this, void 0, void 0, function* () {
41 return (yield this.host()).getAttribute('aria-labelledby');
42 });
43 }
44 /** Whether the step is selected. */
45 isSelected() {
46 return __awaiter(this, void 0, void 0, function* () {
47 const host = yield this.host();
48 return (yield host.getAttribute('aria-selected')) === 'true';
49 });
50 }
51 /** Whether the step has been filled out. */
52 isCompleted() {
53 return __awaiter(this, void 0, void 0, function* () {
54 const state = yield this._getIconState();
55 return state === 'done' || (state === 'edit' && !(yield this.isSelected()));
56 });
57 }
58 /**
59 * Whether the step is currently showing its error state. Note that this doesn't mean that there
60 * are or aren't any invalid form controls inside the step, but that the step is showing its
61 * error-specific styling which depends on there being invalid controls, as well as the
62 * `ErrorStateMatcher` determining that an error should be shown and that the `showErrors`
63 * option was enabled through the `STEPPER_GLOBAL_OPTIONS` injection token.
64 */
65 hasErrors() {
66 return __awaiter(this, void 0, void 0, function* () {
67 return (yield this._getIconState()) === 'error';
68 });
69 }
70 /** Whether the step is optional. */
71 isOptional() {
72 return __awaiter(this, void 0, void 0, function* () {
73 // If the node with the optional text is present, it means that the step is optional.
74 const optionalNode = yield this.locatorForOptional('.mat-step-optional')();
75 return !!optionalNode;
76 });
77 }
78 /**
79 * Selects the given step by clicking on the label. The step may not be selected
80 * if the stepper doesn't allow it (e.g. if there are validation errors).
81 */
82 select() {
83 return __awaiter(this, void 0, void 0, function* () {
84 yield (yield this.host()).click();
85 });
86 }
87 getRootHarnessLoader() {
88 return __awaiter(this, void 0, void 0, function* () {
89 const contentId = yield (yield this.host()).getAttribute('aria-controls');
90 return this.documentRootLocatorFactory().harnessLoaderFor(`#${contentId}`);
91 });
92 }
93 /**
94 * Gets the state of the step. Note that we have a `StepState` which we could use to type the
95 * return value, but it's basically the same as `string`, because the type has `| string`.
96 */
97 _getIconState() {
98 return __awaiter(this, void 0, void 0, function* () {
99 // The state is exposed on the icon with a class that looks like `mat-step-icon-state-{{state}}`
100 const icon = yield this.locatorFor('.mat-step-icon')();
101 const classes = (yield icon.getAttribute('class'));
102 const match = classes.match(/mat-step-icon-state-([a-z]+)/);
103 if (!match) {
104 throw Error(`Could not determine step state from "${classes}".`);
105 }
106 return match[1];
107 });
108 }
109}
110/** The selector for the host element of a `MatStep` instance. */
111MatStepHarness.hostSelector = '.mat-step-header';
112
113/**
114 * @license
115 * Copyright Google LLC All Rights Reserved.
116 *
117 * Use of this source code is governed by an MIT-style license that can be
118 * found in the LICENSE file at https://angular.io/license
119 */
120/** Harness for interacting with a standard Material stepper in tests. */
121class MatStepperHarness extends ComponentHarness {
122 /**
123 * Gets a `HarnessPredicate` that can be used to search for a `MatStepperHarness` that meets
124 * certain criteria.
125 * @param options Options for filtering which stepper instances are considered a match.
126 * @return a `HarnessPredicate` configured with the given options.
127 */
128 static with(options = {}) {
129 return new HarnessPredicate(MatStepperHarness, options)
130 .addOption('orientation', options.orientation, (harness, orientation) => __awaiter(this, void 0, void 0, function* () { return (yield harness.getOrientation()) === orientation; }));
131 }
132 /**
133 * Gets the list of steps in the stepper.
134 * @param filter Optionally filters which steps are included.
135 */
136 getSteps(filter = {}) {
137 return __awaiter(this, void 0, void 0, function* () {
138 return this.locatorForAll(MatStepHarness.with(filter))();
139 });
140 }
141 /** Gets the orientation of the stepper. */
142 getOrientation() {
143 return __awaiter(this, void 0, void 0, function* () {
144 const host = yield this.host();
145 return (yield host.hasClass('mat-stepper-horizontal')) ?
146 0 /* HORIZONTAL */ : 1 /* VERTICAL */;
147 });
148 }
149 /**
150 * Selects a step in this stepper.
151 * @param filter An optional filter to apply to the child steps. The first step matching the
152 * filter will be selected.
153 */
154 selectStep(filter = {}) {
155 return __awaiter(this, void 0, void 0, function* () {
156 const steps = yield this.getSteps(filter);
157 if (!steps.length) {
158 throw Error(`Cannot find mat-step matching filter ${JSON.stringify(filter)}`);
159 }
160 yield steps[0].select();
161 });
162 }
163}
164/** The selector for the host element of a `MatStepper` instance. */
165MatStepperHarness.hostSelector = '.mat-stepper-horizontal, .mat-stepper-vertical';
166
167/**
168 * @license
169 * Copyright Google LLC All Rights Reserved.
170 *
171 * Use of this source code is governed by an MIT-style license that can be
172 * found in the LICENSE file at https://angular.io/license
173 */
174/** Base class for stepper button harnesses. */
175class StepperButtonHarness extends ComponentHarness {
176 /** Gets the text of the button. */
177 getText() {
178 return __awaiter(this, void 0, void 0, function* () {
179 return (yield this.host()).text();
180 });
181 }
182 /** Clicks the button. */
183 click() {
184 return __awaiter(this, void 0, void 0, function* () {
185 return (yield this.host()).click();
186 });
187 }
188}
189/** Harness for interacting with a standard Angular Material stepper next button in tests. */
190class MatStepperNextHarness extends StepperButtonHarness {
191 /**
192 * Gets a `HarnessPredicate` that can be used to search for a `MatStepperNextHarness` that meets
193 * certain criteria.
194 * @param options Options for filtering which steps are considered a match.
195 * @return a `HarnessPredicate` configured with the given options.
196 */
197 static with(options = {}) {
198 return new HarnessPredicate(MatStepperNextHarness, options)
199 .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
200 }
201}
202/** The selector for the host element of a `MatStep` instance. */
203MatStepperNextHarness.hostSelector = '.mat-stepper-next';
204/** Harness for interacting with a standard Angular Material stepper previous button in tests. */
205class MatStepperPreviousHarness extends StepperButtonHarness {
206 /**
207 * Gets a `HarnessPredicate` that can be used to search for a `MatStepperPreviousHarness`
208 * that meets certain criteria.
209 * @param options Options for filtering which steps are considered a match.
210 * @return a `HarnessPredicate` configured with the given options.
211 */
212 static with(options = {}) {
213 return new HarnessPredicate(MatStepperPreviousHarness, options)
214 .addOption('text', options.text, (harness, text) => HarnessPredicate.stringMatches(harness.getText(), text));
215 }
216}
217/** The selector for the host element of a `MatStep` instance. */
218MatStepperPreviousHarness.hostSelector = '.mat-stepper-previous';
219
220/**
221 * @license
222 * Copyright Google LLC All Rights Reserved.
223 *
224 * Use of this source code is governed by an MIT-style license that can be
225 * found in the LICENSE file at https://angular.io/license
226 */
227
228/**
229 * @license
230 * Copyright Google LLC All Rights Reserved.
231 *
232 * Use of this source code is governed by an MIT-style license that can be
233 * found in the LICENSE file at https://angular.io/license
234 */
235
236export { MatStepHarness, MatStepperHarness, MatStepperNextHarness, MatStepperPreviousHarness };
237//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.