/** * @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 { ComponentHarness, HarnessPredicate, } from '@angular/cdk/testing'; /** Harness for interacting with a grid's chip input in tests. */ export class MatChipInputHarness extends ComponentHarness { static { this.hostSelector = '.mat-mdc-chip-input'; } /** * Gets a `HarnessPredicate` that can be used to search for a chip input with specific * attributes. * @param options Options for filtering which input instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options) .addOption('value', options.value, async (harness, value) => { return (await harness.getValue()) === value; }) .addOption('placeholder', options.placeholder, async (harness, placeholder) => { return (await harness.getPlaceholder()) === placeholder; }) .addOption('disabled', options.disabled, async (harness, disabled) => { return (await harness.isDisabled()) === disabled; }); } /** 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 never undefined. return await (await this.host()).getProperty('value'); } /** 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(); } /** * 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); } } /** Sends a chip separator key to the input element. */ async sendSeparatorKey(key) { const inputEl = await this.host(); return inputEl.sendKeys(key); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1pbnB1dC1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdX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