/** * @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, parallel, } from '@angular/cdk/testing'; import { MatChipOptionHarness } from './chip-option-harness'; /** Harness for interacting with a mat-chip-listbox in tests. */ export class MatChipListboxHarness extends ComponentHarness { static { this.hostSelector = '.mat-mdc-chip-listbox'; } /** * Gets a `HarnessPredicate` that can be used to search for a chip listbox 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('disabled', options.disabled, async (harness, disabled) => { return (await harness.isDisabled()) === disabled; }); } /** Gets whether the chip listbox is disabled. */ async isDisabled() { return (await (await this.host()).getAttribute('aria-disabled')) === 'true'; } /** Gets whether the chip listbox is required. */ async isRequired() { return (await (await this.host()).getAttribute('aria-required')) === 'true'; } /** Gets whether the chip listbox is in multi selection mode. */ async isMultiple() { return (await (await this.host()).getAttribute('aria-multiselectable')) === 'true'; } /** Gets whether the orientation of the chip list. */ async getOrientation() { const orientation = await (await this.host()).getAttribute('aria-orientation'); return orientation === 'vertical' ? 'vertical' : 'horizontal'; } /** * Gets the list of chips inside the chip list. * @param filter Optionally filters which chips are included. */ async getChips(filter = {}) { return this.locatorForAll(MatChipOptionHarness.with(filter))(); } /** * Selects a chip inside the chip list. * @param filter An optional filter to apply to the child chips. * All the chips matching the filter will be selected. */ async selectChips(filter = {}) { const chips = await this.getChips(filter); if (!chips.length) { throw Error(`Cannot find chip matching filter ${JSON.stringify(filter)}`); } await parallel(() => chips.map(chip => chip.select())); } } //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiY2hpcC1saXN0Ym94LWhhcm5lc3MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi8uLi8uLi8uLi8uLi8uLi9zcmMvbWF0ZXJpYWwvY2hpcHMvdGVzdGluZy9jaGlwLWxpc3R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