/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ import { coerceNumberProperty } from '@angular/cdk/coercion'; import { ComponentHarness, HarnessPredicate, parallel, } from '@angular/cdk/testing'; /** Harness for interacting with a thumb inside of a Material slider in tests. */ export class MatSliderThumbHarness extends ComponentHarness { static { this.hostSelector = 'input[matSliderThumb], input[matSliderStartThumb], input[matSliderEndThumb]'; } /** * Gets a `HarnessPredicate` that can be used to search for a slider thumb with specific attributes. * @param options Options for filtering which thumb instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options).addOption('position', options.position, async (harness, value) => { return (await harness.getPosition()) === value; }); } /** Gets the position of the thumb inside the slider. */ async getPosition() { // Meant to mimic MDC's logic where `matSliderThumb` is treated as END. const isStart = (await (await this.host()).getAttribute('matSliderStartThumb')) != null; return isStart ? 0 /* ThumbPosition.START */ : 1 /* ThumbPosition.END */; } /** Gets the value of the thumb. */ async getValue() { return await (await this.host()).getProperty('valueAsNumber'); } /** Sets the value of the thumb. */ async setValue(newValue) { const input = await this.host(); // Since this is a range input, we can't simulate the user interacting with it so we set the // value directly and dispatch a couple of fake events to ensure that everything fires. await input.setInputValue(newValue + ''); await input.dispatchEvent('input'); await input.dispatchEvent('change'); } /** Gets the current percentage value of the slider. */ async getPercentage() { const [value, min, max] = await parallel(() => [ this.getValue(), this.getMinValue(), this.getMaxValue(), ]); return (value - min) / (max - min); } /** Gets the maximum value of the thumb. */ async getMaxValue() { return coerceNumberProperty(await (await this.host()).getProperty('max')); } /** Gets the minimum value of the thumb. */ async getMinValue() { return coerceNumberProperty(await (await this.host()).getProperty('min')); } /** Gets the text representation of the slider's value. */ async getDisplayValue() { return (await (await this.host()).getAttribute('aria-valuetext')) || ''; } /** Whether the thumb is disabled. */ async isDisabled() { return (await this.host()).getProperty('disabled'); } /** Gets the name of the thumb. */ async getName() { return await (await this.host()).getProperty('name'); } /** Gets the id of the thumb. */ async getId() { return await (await this.host()).getProperty('id'); } /** * Focuses the thumb and returns a promise that indicates when the * action is complete. */ async focus() { return (await this.host()).focus(); } /** * Blurs the thumb and returns a promise that indicates when the * action is complete. */ async blur() { return (await this.host()).blur(); } /** Whether the thumb is focused. */ async isFocused() { return (await this.host()).isFocused(); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic2xpZGVyLXRodW1iLWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvc2xpZGVyL3Rlc3Rpbmcvc2xpZGVyLXRodW1iLWhhcm5lc3MudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsT0FBTyxFQUFDLG9CQUFvQixFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFDM0QsT0FBTyxFQUNMLGdCQUFnQixFQUVoQixnQkFBZ0IsRUFDaEIsUUFBUSxHQUNULE1BQU0sc0JBQXNCLENBQUM7QUFHOUIsaUZBQWlGO0FBQ2pGLE1BQU0sT0FBTyxxQkFBc0IsU0FBUSxnQkFBZ0I7YUFDbEQsaUJBQVksR0FDakIsNkVBQTZFLENBQUM7SUFFaEY7Ozs7T0FJRztJQUNILE1BQU0sQ0FBQyxJQUFJLENBRVQsVUFBcUMsRUFBRTtRQUV2QyxPQUFPLElBQUksZ0JBQWdCLENBQUMsSUFBSSxFQUFFLE9BQU8sQ0FBQyxDQUFDLFNBQVMsQ0FDbEQsVUFBVSxFQUNWLE9BQU8sQ0FBQyxRQUFRLEVBQ2hCLEtBQUssRUFBRSxPQUFPLEVBQUUsS0FBSyxFQUFFLEVBQUU7WUFDdkIsT0FBTyxDQUFDLE1BQU0sT0FBTyxDQUFDLFdBQVcsRUFBRSxDQUFDLEtBQUssS0FBSyxDQUFDO1FBQ2pELENBQUMsQ0FDRixDQUFDO0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