| 12 | |
| 13 | /** Harness for interacting with a mat-chip-option in tests. */ |
| 14 | export class MatChipOptionHarness extends MatChipHarness { |
| 15 | static override hostSelector = '.mat-mdc-chip-option'; |
| 16 | |
| 17 | /** |
| 18 | * Gets a `HarnessPredicate` that can be used to search for a chip option with specific |
| 19 | * attributes. |
| 20 | * @param options Options for narrowing the search. |
| 21 | * @return a `HarnessPredicate` configured with the given options. |
| 22 | */ |
| 23 | static override with<T extends MatChipHarness>( |
| 24 | this: ComponentHarnessConstructor<T>, |
| 25 | options: ChipOptionHarnessFilters = {}, |
| 26 | ): HarnessPredicate<T> { |
| 27 | return new HarnessPredicate(MatChipOptionHarness, options) |
| 28 | .addOption('text', options.text, (harness, label) => |
| 29 | HarnessPredicate.stringMatches(harness.getText(), label), |
| 30 | ) |
| 31 | .addOption( |
| 32 | 'selected', |
| 33 | options.selected, |
| 34 | async (harness, selected) => (await harness.isSelected()) === selected, |
| 35 | ) as unknown as HarnessPredicate<T>; |
| 36 | } |
| 37 | |
| 38 | /** Whether the chip is selected. */ |
| 39 | async isSelected(): Promise<boolean> { |
| 40 | return (await this.host()).hasClass('mat-mdc-chip-selected'); |
| 41 | } |
| 42 | |
| 43 | /** Selects the given chip. Only applies if it's selectable. */ |
| 44 | async select(): Promise<void> { |
| 45 | if (!(await this.isSelected())) { |
| 46 | await this.toggle(); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | /** Deselects the given chip. Only applies if it's selectable. */ |
| 51 | async deselect(): Promise<void> { |
| 52 | if (await this.isSelected()) { |
| 53 | await this.toggle(); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | /** Toggles the selected state of the given chip. */ |
| 58 | async toggle(): Promise<void> { |
| 59 | return (await this._primaryAction()).click(); |
| 60 | } |
| 61 | } |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…