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

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

initial commit

  • Property mode set to 100644
File size: 6.4 KB
Line 
1import { __awaiter } from 'tslib';
2import { ComponentHarness, HarnessPredicate, parallel } from '@angular/cdk/testing';
3import { coerceNumberProperty, 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 */
12/** Harness for interacting with a standard mat-slider in tests. */
13class MatSliderHarness extends ComponentHarness {
14 constructor() {
15 super(...arguments);
16 this._textLabel = this.locatorFor('.mat-slider-thumb-label-text');
17 this._wrapper = this.locatorFor('.mat-slider-wrapper');
18 }
19 /**
20 * Gets a `HarnessPredicate` that can be used to search for a `MatSliderHarness` that meets
21 * certain criteria.
22 * @param options Options for filtering which slider instances are considered a match.
23 * @return a `HarnessPredicate` configured with the given options.
24 */
25 static with(options = {}) {
26 return new HarnessPredicate(MatSliderHarness, options);
27 }
28 /** Gets the slider's id. */
29 getId() {
30 return __awaiter(this, void 0, void 0, function* () {
31 const id = yield (yield this.host()).getAttribute('id');
32 // In case no id has been specified, the "id" property always returns
33 // an empty string. To make this method more explicit, we return null.
34 return id !== '' ? id : null;
35 });
36 }
37 /**
38 * Gets the current display value of the slider. Returns a null promise if the thumb label is
39 * disabled.
40 */
41 getDisplayValue() {
42 return __awaiter(this, void 0, void 0, function* () {
43 const [host, textLabel] = yield parallel(() => [this.host(), this._textLabel()]);
44 if (yield host.hasClass('mat-slider-thumb-label-showing')) {
45 return textLabel.text();
46 }
47 return null;
48 });
49 }
50 /** Gets the current percentage value of the slider. */
51 getPercentage() {
52 return __awaiter(this, void 0, void 0, function* () {
53 return this._calculatePercentage(yield this.getValue());
54 });
55 }
56 /** Gets the current value of the slider. */
57 getValue() {
58 return __awaiter(this, void 0, void 0, function* () {
59 return coerceNumberProperty(yield (yield this.host()).getAttribute('aria-valuenow'));
60 });
61 }
62 /** Gets the maximum value of the slider. */
63 getMaxValue() {
64 return __awaiter(this, void 0, void 0, function* () {
65 return coerceNumberProperty(yield (yield this.host()).getAttribute('aria-valuemax'));
66 });
67 }
68 /** Gets the minimum value of the slider. */
69 getMinValue() {
70 return __awaiter(this, void 0, void 0, function* () {
71 return coerceNumberProperty(yield (yield this.host()).getAttribute('aria-valuemin'));
72 });
73 }
74 /** Whether the slider is disabled. */
75 isDisabled() {
76 return __awaiter(this, void 0, void 0, function* () {
77 const disabled = (yield this.host()).getAttribute('aria-disabled');
78 return coerceBooleanProperty(yield disabled);
79 });
80 }
81 /** Gets the orientation of the slider. */
82 getOrientation() {
83 return __awaiter(this, void 0, void 0, function* () {
84 // "aria-orientation" will always be set to either "horizontal" or "vertical".
85 return (yield this.host()).getAttribute('aria-orientation');
86 });
87 }
88 /**
89 * Sets the value of the slider by clicking on the slider track.
90 *
91 * Note that in rare cases the value cannot be set to the exact specified value. This
92 * can happen if not every value of the slider maps to a single pixel that could be
93 * clicked using mouse interaction. In such cases consider using the keyboard to
94 * select the given value or expand the slider's size for a better user experience.
95 */
96 setValue(value) {
97 return __awaiter(this, void 0, void 0, function* () {
98 const [sliderEl, wrapperEl, orientation] = yield parallel(() => [this.host(), this._wrapper(), this.getOrientation()]);
99 let percentage = yield this._calculatePercentage(value);
100 const { height, width } = yield wrapperEl.getDimensions();
101 const isVertical = orientation === 'vertical';
102 // In case the slider is inverted in LTR mode or not inverted in RTL mode,
103 // we need to invert the percentage so that the proper value is set.
104 if (yield sliderEl.hasClass('mat-slider-invert-mouse-coords')) {
105 percentage = 1 - percentage;
106 }
107 // We need to round the new coordinates because creating fake DOM
108 // events will cause the coordinates to be rounded down.
109 const relativeX = isVertical ? 0 : Math.round(width * percentage);
110 const relativeY = isVertical ? Math.round(height * percentage) : 0;
111 yield wrapperEl.click(relativeX, relativeY);
112 });
113 }
114 /** Focuses the slider. */
115 focus() {
116 return __awaiter(this, void 0, void 0, function* () {
117 return (yield this.host()).focus();
118 });
119 }
120 /** Blurs the slider. */
121 blur() {
122 return __awaiter(this, void 0, void 0, function* () {
123 return (yield this.host()).blur();
124 });
125 }
126 /** Whether the slider is focused. */
127 isFocused() {
128 return __awaiter(this, void 0, void 0, function* () {
129 return (yield this.host()).isFocused();
130 });
131 }
132 /** Calculates the percentage of the given value. */
133 _calculatePercentage(value) {
134 return __awaiter(this, void 0, void 0, function* () {
135 const [min, max] = yield parallel(() => [this.getMinValue(), this.getMaxValue()]);
136 return (value - min) / (max - min);
137 });
138 }
139}
140/** The selector for the host element of a `MatSlider` instance. */
141MatSliderHarness.hostSelector = '.mat-slider';
142
143/**
144 * @license
145 * Copyright Google LLC All Rights Reserved.
146 *
147 * Use of this source code is governed by an MIT-style license that can be
148 * found in the LICENSE file at https://angular.io/license
149 */
150
151/**
152 * @license
153 * Copyright Google LLC All Rights Reserved.
154 *
155 * Use of this source code is governed by an MIT-style license that can be
156 * found in the LICENSE file at https://angular.io/license
157 */
158
159export { MatSliderHarness };
160//# sourceMappingURL=testing.js.map
Note: See TracBrowser for help on using the repository browser.