Jack Maclennan Portfolio
    Preparing search index...

    Fixture for Select component

      public constructor(
    private readonly page: Page,
    private readonly parent: Locator
    ) {
    this.themeSelect = this.parent.getByTestId('theme-select');
    this.select = new Select(this.themeSelect);
    }

    Provides method helpers for locating child elements and interactivity.

    export default class Select implements Component {
    /** @public Component wrapper. */
    private readonly select: Locator;
    /** @public Button element used to open select {@link menu}. */
    private readonly button: Locator;
    /** @public Menu element containing options. */
    private readonly menu: Locator;

    /**
    * Fixture constructor - initialise variables.
    * @param parent - Parent element.
    */
    public constructor(public readonly parent: Locator) {
    this.select = this.parent.getByTestId('custom-select');
    this.button = this.select.getByTestId('custom-select-button');
    this.menu = this.select.getByTestId('custom-select-menu');
    }

    /** Getter method. @returns {@link select}. */
    public getWrapper(): Locator {
    return this.select;
    }

    /** Testing helper method. */
    public async rendersCorrectly(): Promise<boolean> {
    await expect(this.getButton(), 'select button should be visible').toBeVisible();
    await expect(this.getMenu(), 'select menu should be hidden').toBeHidden();
    return true;
    }

    /** Getter method. @returns {@link button}. */
    public getButton(): Locator {
    return this.button;
    }

    /** Getter method. @returns {@link menu}. */
    public getMenu(): Locator {
    return this.menu;
    }

    /** Opens select menu by interacting with {@link button}. */
    public async openMenu(): Promise<void> {
    this.getButton().click();
    }

    /**
    * Selects option by interacting with {@link menu}.
    * @param identifier - Test ID of option element.
    */
    public async selectOption(identifier: string): Promise<void> {
    await this.openMenu();
    await expect(this.getMenu()).toBeVisible();
    await this.getMenu().getByTestId(identifier).click();
    await expect(this.getMenu()).toBeHidden();
    }
    }

    Implements

    Index

    Constructors

    Properties

    select: Locator

    Component wrapper.

    button: Locator

    Button element used to open select menu.

    menu: Locator

    Menu element containing options.

    parent: Locator

    Parent element.

    Methods

    • Selects option by interacting with menu.

      Parameters

      • identifier: string

        Test ID of option element.

      Returns Promise<void>