| 16 | |
| 17 | /** Harness for interacting with an Angular Material tab in tests. */ |
| 18 | export class MatTabHarness extends ContentContainerComponentHarness<string> { |
| 19 | /** The selector for the host element of a `MatTab` instance. */ |
| 20 | static hostSelector = '.mat-mdc-tab'; |
| 21 | |
| 22 | /** |
| 23 | * Gets a `HarnessPredicate` that can be used to search for a tab with specific attributes. |
| 24 | * @param options Options for filtering which tab instances are considered a match. |
| 25 | * @return a `HarnessPredicate` configured with the given options. |
| 26 | */ |
| 27 | static with<T extends MatTabHarness>( |
| 28 | this: ComponentHarnessConstructor<T>, |
| 29 | options: TabHarnessFilters = {}, |
| 30 | ): HarnessPredicate<T> { |
| 31 | return new HarnessPredicate(this, options) |
| 32 | .addOption('label', options.label, (harness, label) => |
| 33 | HarnessPredicate.stringMatches(harness.getLabel(), label), |
| 34 | ) |
| 35 | .addOption( |
| 36 | 'selected', |
| 37 | options.selected, |
| 38 | async (harness, selected) => (await harness.isSelected()) == selected, |
| 39 | ); |
| 40 | } |
| 41 | |
| 42 | /** Gets the label of the tab. */ |
| 43 | async getLabel(): Promise<string> { |
| 44 | return (await this.host()).text(); |
| 45 | } |
| 46 | |
| 47 | /** Gets the aria-label of the tab. */ |
| 48 | async getAriaLabel(): Promise<string | null> { |
| 49 | return (await this.host()).getAttribute('aria-label'); |
| 50 | } |
| 51 | |
| 52 | /** Gets the value of the "aria-labelledby" attribute. */ |
| 53 | async getAriaLabelledby(): Promise<string | null> { |
| 54 | return (await this.host()).getAttribute('aria-labelledby'); |
| 55 | } |
| 56 | |
| 57 | /** Whether the tab is selected. */ |
| 58 | async isSelected(): Promise<boolean> { |
| 59 | const hostEl = await this.host(); |
| 60 | return (await hostEl.getAttribute('aria-selected')) === 'true'; |
| 61 | } |
| 62 | |
| 63 | /** Whether the tab is disabled. */ |
| 64 | async isDisabled(): Promise<boolean> { |
| 65 | const hostEl = await this.host(); |
| 66 | return (await hostEl.getAttribute('aria-disabled')) === 'true'; |
| 67 | } |
| 68 | |
| 69 | /** Selects the given tab by clicking on the label. Tab cannot be selected if disabled. */ |
| 70 | async select(): Promise<void> { |
| 71 | await (await this.host()).click('center'); |
| 72 | } |
| 73 | |
| 74 | /** Gets the text content of the tab. */ |
| 75 | async getTextContent(): Promise<string> { |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…