| 77 | |
| 78 | /** Harness for interacting with a list option. */ |
| 79 | export class MatListOptionHarness extends MatListItemHarnessBase { |
| 80 | /** The selector for the host element of a `MatListOption` instance. */ |
| 81 | static hostSelector = '.mat-mdc-list-option'; |
| 82 | |
| 83 | /** |
| 84 | * Gets a `HarnessPredicate` that can be used to search for a list option with specific |
| 85 | * attributes. |
| 86 | * @param options Options for filtering which list option instances are considered a match. |
| 87 | * @return a `HarnessPredicate` configured with the given options. |
| 88 | */ |
| 89 | static with<T extends MatListOptionHarness>( |
| 90 | this: ComponentHarnessConstructor<T>, |
| 91 | options: ListOptionHarnessFilters = {}, |
| 92 | ): HarnessPredicate<T> { |
| 93 | return getListItemPredicate(this, options).addOption( |
| 94 | 'is selected', |
| 95 | options.selected, |
| 96 | async (harness, selected) => (await harness.isSelected()) === selected, |
| 97 | ); |
| 98 | } |
| 99 | |
| 100 | private _beforeCheckbox = this.locatorForOptional('.mdc-list-item__start .mdc-checkbox'); |
| 101 | private _beforeRadio = this.locatorForOptional('.mdc-list-item__start .mdc-radio'); |
| 102 | |
| 103 | /** Gets the position of the checkbox relative to the list option content. */ |
| 104 | async getCheckboxPosition(): Promise<MatListOptionTogglePosition> { |
| 105 | return (await this._beforeCheckbox()) !== null ? 'before' : 'after'; |
| 106 | } |
| 107 | |
| 108 | /** Gets the position of the radio relative to the list option content. */ |
| 109 | async getRadioPosition(): Promise<MatListOptionTogglePosition> { |
| 110 | return (await this._beforeRadio()) !== null ? 'before' : 'after'; |
| 111 | } |
| 112 | |
| 113 | /** Whether the list option is selected. */ |
| 114 | async isSelected(): Promise<boolean> { |
| 115 | return (await (await this.host()).getAttribute('aria-selected')) === 'true'; |
| 116 | } |
| 117 | |
| 118 | /** Focuses the list option. */ |
| 119 | async focus(): Promise<void> { |
| 120 | return (await this.host()).focus(); |
| 121 | } |
| 122 | |
| 123 | /** Blurs the list option. */ |
| 124 | async blur(): Promise<void> { |
| 125 | return (await this.host()).blur(); |
| 126 | } |
| 127 | |
| 128 | /** Whether the list option is focused. */ |
| 129 | async isFocused(): Promise<boolean> { |
| 130 | return (await this.host()).isFocused(); |
| 131 | } |
| 132 | |
| 133 | /** Toggles the checked state of the checkbox. */ |
| 134 | async toggle() { |
| 135 | return (await this.host()).click(); |
| 136 | } |
nothing calls this directly
no test coverage detected
searching dependent graphs…