/** * @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 { MatLegacyChipAvatarHarness } from './chip-avatar-harness'; import { MatLegacyChipRemoveHarness } from './chip-remove-harness'; /** * Harness for interacting with a standard selectable Angular Material chip in tests. * @deprecated Use `MatChipHarness` from `@angular/material/chips/testing` instead. See https://material.angular.io/guide/mdc-migration for information about migrating. * @breaking-change 17.0.0 */ export class MatLegacyChipHarness extends ContentContainerComponentHarness { /** The selector for the host element of a `MatChip` instance. */ static { this.hostSelector = '.mat-chip'; } /** * Gets a `HarnessPredicate` that can be used to search for a `MatChipHarness` that meets * certain criteria. * @param options Options for filtering which chip instances are considered a match. * @return a `HarnessPredicate` configured with the given options. */ static with(options = {}) { return new HarnessPredicate(MatLegacyChipHarness, options) .addOption('text', options.text, (harness, label) => HarnessPredicate.stringMatches(harness.getText(), label)) .addOption('selected', options.selected, async (harness, selected) => (await harness.isSelected()) === selected); } /** Gets the text of the chip. */ async getText() { return (await this.host()).text({ exclude: '.mat-chip-avatar, .mat-chip-trailing-icon, .mat-icon', }); } /** * Whether the chip is selected. * @deprecated Use `MatChipOptionHarness.isSelected` instead. * @breaking-change 12.0.0 */ async isSelected() { return (await this.host()).hasClass('mat-chip-selected'); } /** Whether the chip is disabled. */ async isDisabled() { return (await this.host()).hasClass('mat-chip-disabled'); } /** * Selects the given chip. Only applies if it's selectable. * @deprecated Use `MatChipOptionHarness.select` instead. * @breaking-change 12.0.0 */ async select() { if (!(await this.isSelected())) { await this.toggle(); } } /** * Deselects the given chip. Only applies if it's selectable. * @deprecated Use `MatChipOptionHarness.deselect` instead. * @breaking-change 12.0.0 */ async deselect() { if (await this.isSelected()) { await this.toggle(); } } /** * Toggles the selected state of the given chip. Only applies if it's selectable. * @deprecated Use `MatChipOptionHarness.toggle` instead. * @breaking-change 12.0.0 */ async toggle() { return (await this.host()).sendKeys(' '); } /** Removes the given chip. Only applies if it's removable. */ async remove() { await (await this.host()).sendKeys(TestKey.DELETE); } /** * Gets the remove button inside of a chip. * @param filter Optionally filters which remove buttons are included. */ async getRemoveButton(filter = {}) { return this.locatorFor(MatLegacyChipRemoveHarness.with(filter))(); } /** * Gets the avatar inside a chip. * @param filter Optionally filters which avatars are included. */ async getAvatar(filter = {}) { return this.locatorForOptional(MatLegacyChipAvatarHarness.with(filter))(); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1oYXJuZXNzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vLi4vc3JjL21hdGVyaWFsL2xlZ2FjeS1jaGlwcy90ZXN0aW5nL2NoaXAtaGFybmVzcy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQTs7Ozs7O0dBTUc7QUFFSCxPQUFPLEVBQUMsZ0NBQWdDLEVBQUUsZ0JBQWdCLEVBQUUsT0FBTyxFQUFDLE1BQU0sc0JBQXNCLENBQUM7QUFDakcsT0FBTyxFQUFDLDBCQUEwQixFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFNakUsT0FBTyxFQUFDLDBCQUEwQixFQUFDLE1BQU0sdUJBQXVCLENBQUM7QUFFakU7Ozs7R0FJRztBQUNILE1BQU0sT0FBTyxvQkFBcUIsU0FBUSxnQ0FBZ0M7SUFDeEUsaUVBQWlFO2FBQzFELGlCQUFZLEdBQUcsV0FBVyxDQUFDO0lBRWxDOzs7OztPQUtHO0lBQ0gsTUFBTSxDQUFDLElBQUksQ0FBQyxVQUFvQyxFQUFFO1FBQ2hELE9BQU8sSUFBSSxnQkFBZ0IsQ0FBQyxvQkFBb0IsRUFBRSxPQUFPLENBQUM7YUFDdkQsU0FBUyxDQUFDLE1BQU0sRUFBRSxPQUFPLENBQUMsSUFBSSxFQUFFLENBQUMsT0FBTyxFQUFFLEtBQ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