{"version":3,"file":"testing.mjs","sources":["../../../../../../../src/material/legacy-slider/testing/slider-harness.ts"],"sourcesContent":["/**\n * @license\n * Copyright Google LLC All Rights Reserved.\n *\n * Use of this source code is governed by an MIT-style license that can be\n * found in the LICENSE file at https://angular.io/license\n */\n\nimport {ComponentHarness, HarnessPredicate, parallel} from '@angular/cdk/testing';\nimport {coerceBooleanProperty, coerceNumberProperty} from '@angular/cdk/coercion';\nimport {LegacySliderHarnessFilters} from './slider-harness-filters';\n\n/**\n * Harness for interacting with a standard mat-slider in tests.\n * @deprecated Use `MatSliderHarness` from `@angular/material/slider/testing` instead. See https://material.angular.io/guide/mdc-migration for information about migrating.\n * @breaking-change 17.0.0\n */\nexport class MatLegacySliderHarness extends ComponentHarness {\n /** The selector for the host element of a `MatSlider` instance. */\n static hostSelector = '.mat-slider';\n\n /**\n * Gets a `HarnessPredicate` that can be used to search for a `MatSliderHarness` that meets\n * certain criteria.\n * @param options Options for filtering which slider instances are considered a match.\n * @return a `HarnessPredicate` configured with the given options.\n */\n static with(options: LegacySliderHarnessFilters = {}): HarnessPredicate {\n return new HarnessPredicate(MatLegacySliderHarness, options);\n }\n\n private _textLabel = this.locatorFor('.mat-slider-thumb-label-text');\n private _wrapper = this.locatorFor('.mat-slider-wrapper');\n\n /** Gets the slider's id. */\n async getId(): Promise {\n const id = await (await this.host()).getAttribute('id');\n // In case no id has been specified, the \"id\" property always returns\n // an empty string. To make this method more explicit, we return null.\n return id !== '' ? id : null;\n }\n\n /**\n * Gets the current display value of the slider. Returns a null promise if the thumb label is\n * disabled.\n */\n async getDisplayValue(): Promise {\n const [host, textLabel] = await parallel(() => [this.host(), this._textLabel()]);\n if (await host.hasClass('mat-slider-thumb-label-showing')) {\n return textLabel.text();\n }\n return null;\n }\n\n /** Gets the current percentage value of the slider. */\n async getPercentage(): Promise {\n return this._calculatePercentage(await this.getValue());\n }\n\n /** Gets the current value of the slider. */\n async getValue(): Promise {\n return coerceNumberProperty(await (await this.host()).getAttribute('aria-valuenow'));\n }\n\n /** Gets the maximum value of the slider. */\n async getMaxValue(): Promise {\n return coerceNumberProperty(await (await this.host()).getAttribute('aria-valuemax'));\n }\n\n /** Gets the minimum value of the slider. */\n async getMinValue(): Promise {\n return coerceNumberProperty(await (await this.host()).getAttribute('aria-valuemin'));\n }\n\n /** Whether the slider is disabled. */\n async isDisabled(): Promise {\n const disabled = (await this.host()).getAttribute('aria-disabled');\n return coerceBooleanProperty(await disabled);\n }\n\n /** Gets the orientation of the slider. */\n async getOrientation(): Promise<'horizontal' | 'vertical'> {\n // \"aria-orientation\" will always be set to either \"horizontal\" or \"vertical\".\n return (await this.host()).getAttribute('aria-orientation') as any;\n }\n\n /**\n * Sets the value of the slider by clicking on the slider track.\n *\n * Note that in rare cases the value cannot be set to the exact specified value. This\n * can happen if not every value of the slider maps to a single pixel that could be\n * clicked using mouse interaction. In such cases consider using the keyboard to\n * select the given value or expand the slider's size for a better user experience.\n */\n async setValue(value: number): Promise {\n const [sliderEl, wrapperEl, orientation] = await parallel(() => [\n this.host(),\n this._wrapper(),\n this.getOrientation(),\n ]);\n let percentage = await this._calculatePercentage(value);\n const {height, width} = await wrapperEl.getDimensions();\n const isVertical = orientation === 'vertical';\n\n // In case the slider is inverted in LTR mode or not inverted in RTL mode,\n // we need to invert the percentage so that the proper value is set.\n if (await sliderEl.hasClass('mat-slider-invert-mouse-coords')) {\n percentage = 1 - percentage;\n }\n\n // We need to round the new coordinates because creating fake DOM\n // events will cause the coordinates to be rounded down.\n const relativeX = isVertical ? 0 : Math.round(width * percentage);\n const relativeY = isVertical ? Math.round(height * percentage) : 0;\n\n await wrapperEl.click(relativeX, relativeY);\n }\n\n /** Focuses the slider. */\n async focus(): Promise {\n return (await this.host()).focus();\n }\n\n /** Blurs the slider. */\n async blur(): Promise {\n return (await this.host()).blur();\n }\n\n /** Whether the slider is focused. */\n async isFocused(): Promise {\n return (await this.host()).isFocused();\n }\n\n /** Calculates the percentage of the given value. */\n private async _calculatePercentage(value: number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