UNPKG

@skyux/help-inline

Version:

This library was generated with [Nx](https://nx.dev).

99 lines (95 loc) 3.03 kB
import { SkyComponentHarness } from '@skyux/core/testing'; import { SkyPopoverHarness } from '@skyux/popovers/testing'; /** * Harness for interacting with a help inline button component in tests. */ class SkyHelpInlineHarness extends SkyComponentHarness { /** * @internal */ static { this.hostSelector = 'sky-help-inline'; } #getInlineHelpButton = this.locatorFor('.sky-help-inline'); /** * Gets a `HarnessPredicate` that can be used to search for a * `SkyHelpInlineHarness` that meets certain criteria. */ static with(filters) { return SkyHelpInlineHarness.getDataSkyIdPredicate(filters); } /** * Clicks the help inline button. */ async click() { const button = await this.#getInlineHelpButton(); if (await button.hasClass('sky-help-inline-hidden')) { throw new Error('Unable to click the help inline button because it is hidden.'); } await button.click(); } /** * Gets the `aria-controls` value. */ async getAriaControls() { return await (await this.#getInlineHelpButton()).getAttribute('aria-controls'); } /** * Gets the `aria-expanded` value. */ async getAriaExpanded() { if ((await this.getAriaControls()) === null) { throw new Error('aria-expanded is only set when `ariaControls` is set.'); } return ((await (await this.#getInlineHelpButton()).getAttribute('aria-expanded')) === 'true'); } /** * Gets the `aria-label` value. */ async getAriaLabel() { return await (await this.#getInlineHelpButton()).getAttribute('aria-label'); } /** * Gets the `aria-labelledby` value. * @internal */ async getAriaLabelledBy() { return await (await this.#getInlineHelpButton()) .getAttribute('aria-labelledby') .then((ref) => { if (ref) { // Remove the 'aria-labelledby' prefix id. return ref.substring(ref.indexOf(' ') + 1); } return null; }); } /** * Gets the label text. */ async getLabelText() { const ariaLabel = await this.getAriaLabel(); if (ariaLabel?.startsWith('Show help content ')) { return ariaLabel.replace('Show help content for ', ''); } return undefined; } /** * Gets the help popover content. */ async getPopoverContent() { return await (await this.#getPopoverHarnessContent())?.getBodyText(); } /** * Gets the help popover title. */ async getPopoverTitle() { return await (await this.#getPopoverHarnessContent())?.getTitleText(); } async #getPopoverHarnessContent() { return await (await this.locatorForOptional(SkyPopoverHarness)())?.getPopoverContent(); } } /** * Generated bundle index. Do not edit. */ export { SkyHelpInlineHarness }; //# sourceMappingURL=skyux-help-inline-testing.mjs.map