| 26 | |
| 27 | /** Harness for interacting with a mat-chip in tests. */ |
| 28 | export class MatChipHarness extends ContentContainerComponentHarness { |
| 29 | protected _primaryAction = this.locatorFor('.mdc-evolution-chip__action--primary'); |
| 30 | |
| 31 | static hostSelector = '.mat-mdc-basic-chip, .mat-mdc-chip'; |
| 32 | |
| 33 | /** |
| 34 | * Gets a `HarnessPredicate` that can be used to search for a chip with specific attributes. |
| 35 | * @param options Options for narrowing the search. |
| 36 | * @return a `HarnessPredicate` configured with the given options. |
| 37 | */ |
| 38 | static with<T extends MatChipHarness>( |
| 39 | this: ComponentHarnessConstructor<T>, |
| 40 | options: ChipHarnessFilters = {}, |
| 41 | ): HarnessPredicate<T> { |
| 42 | return new HarnessPredicate(this, options) |
| 43 | .addOption('text', options.text, (harness, label) => { |
| 44 | return HarnessPredicate.stringMatches(harness.getText(), label); |
| 45 | }) |
| 46 | .addOption('disabled', options.disabled, async (harness, disabled) => { |
| 47 | return (await harness.isDisabled()) === disabled; |
| 48 | }); |
| 49 | } |
| 50 | |
| 51 | /** Gets a promise for the text content the option. */ |
| 52 | async getText(): Promise<string> { |
| 53 | return (await this.host()).text({ |
| 54 | exclude: |
| 55 | '.mat-mdc-chip-avatar, .mat-mdc-chip-leading-icon, .mat-mdc-chip-trailing-icon, .mat-icon', |
| 56 | }); |
| 57 | } |
| 58 | |
| 59 | /** Whether the chip is disabled. */ |
| 60 | async isDisabled(): Promise<boolean> { |
| 61 | return (await this.host()).hasClass('mat-mdc-chip-disabled'); |
| 62 | } |
| 63 | |
| 64 | /** Delete a chip from the set. */ |
| 65 | async remove(): Promise<void> { |
| 66 | const hostEl = await this.host(); |
| 67 | await hostEl.sendKeys(TestKey.DELETE); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Gets the edit button inside of a chip. |
| 72 | * @param filter Optionally filters which chips are included. |
| 73 | */ |
| 74 | async geEditButton(filter: ChipEditHarnessFilters = {}): Promise<MatChipEditHarness> { |
| 75 | return this.locatorFor(MatChipEditHarness.with(filter))(); |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Gets the remove button inside of a chip. |
| 80 | * @param filter Optionally filters which chips are included. |
| 81 | */ |
| 82 | async getRemoveButton(filter: ChipRemoveHarnessFilters = {}): Promise<MatChipRemoveHarness> { |
| 83 | return this.locatorFor(MatChipRemoveHarness.with(filter))(); |
| 84 | } |
| 85 |
nothing calls this directly
no test coverage detected