/** * @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 { HarnessPredicate } from '@angular/cdk/testing'; import { MatFormFieldControlHarness } from '@angular/material/form-field/testing/control'; /** Sets up the filter predicates for a datepicker input harness. */ export function getInputPredicate(type, options) { return new HarnessPredicate(type, options) .addOption('value', options.value, (harness, value) => { return HarnessPredicate.stringMatches(harness.getValue(), value); }) .addOption('placeholder', options.placeholder, (harness, placeholder) => { return HarnessPredicate.stringMatches(harness.getPlaceholder(), placeholder); }); } /** Base class for datepicker input harnesses. */ export class MatDatepickerInputHarnessBase extends MatFormFieldControlHarness { /** Whether the input is disabled. */ async isDisabled() { return (await this.host()).getProperty('disabled'); } /** Whether the input is required. */ async isRequired() { return (await this.host()).getProperty('required'); } /** Gets the value of the input. */ async getValue() { // The "value" property of the native input is always defined. return await (await this.host()).getProperty('value'); } /** * Sets the value of the input. The value will be set by simulating * keypresses that correspond to the given value. */ async setValue(newValue) { const inputEl = await this.host(); await inputEl.clear(); // We don't want to send keys for the value if the value is an empty // string in order to clear the value. Sending keys with an empty string // still results in unnecessary focus events. if (newValue) { await inputEl.sendKeys(newValue); } await inputEl.dispatchEvent('change'); } /** Gets the placeholder of the input. */ async getPlaceholder() { return await (await this.host()).getProperty('placeholder'); } /** * Focuses the input and returns a promise that indicates when the * action is complete. */ async focus() { return (await this.host()).focus(); } /** * Blurs the input and returns a promise that indicates when the * action is complete. */ async blur() { return (await this.host()).blur(); } /** Whether the input is focused. */ async isFocused() { return (await this.host()).isFocused(); } /** Gets the formatted minimum date for the input's value. */ async getMin() { return (await this.host()).getAttribute('min'); } /** Gets the formatted maximum date for the input's value. */ async getMax() { return (await this.host()).getAttribute('max'); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZGF0ZXBpY2tlci1pbnB1dC1oYXJuZXNzLWJhc2UuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6Wy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