/** * @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 { ContentContainerComponentHarness, HarnessPredicate, TestKey, } from '@angular/cdk/testing'; import { MatChipAvatarHarness } from './chip-avatar-harness'; import { MatChipRemoveHarness } from './chip-remove-harness'; /** Harness for interacting with a mat-chip in tests. */ export class MatChipHarness extends ContentContainerComponentHarness { constructor() { super(...arguments); this._primaryAction = this.locatorFor('.mdc-evolution-chip__action--primary'); } static { this.hostSelector = '.mat-mdc-basic-chip, .mat-mdc-chip'; } /** * Gets a `HarnessPredicate` that can be used to search for a chip with specific attributes. * @param options Options for narrowing the search. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(this, options) .addOption('text', options.text, (harness, label) => { return HarnessPredicate.stringMatches(harness.getText(), label); }) .addOption('disabled', options.disabled, async (harness, disabled) => { return (await harness.isDisabled()) === disabled; }); } /** Gets a promise for the text content the option. */ async getText() { return (await this.host()).text({ exclude: '.mat-mdc-chip-avatar, .mat-mdc-chip-trailing-icon, .mat-icon', }); } /** Whether the chip is disabled. */ async isDisabled() { return (await this.host()).hasClass('mat-mdc-chip-disabled'); } /** Delete a chip from the set. */ async remove() { const hostEl = await this.host(); await hostEl.sendKeys(TestKey.DELETE); } /** * Gets the remove button inside of a chip. * @param filter Optionally filters which chips are included. */ async getRemoveButton(filter = {}) { return this.locatorFor(MatChipRemoveHarness.with(filter))(); } /** * Gets the avatar inside a chip. * @param filter Optionally filters which avatars are included. */ async getAvatar(filter = {}) { return this.locatorForOptional(MatChipAvatarHarness.with(filter))(); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL2NoaXBzL3Rlc3RpbmcvY2hpcC1oYXJuZXNzLnRzIl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