Jack Maclennan Portfolio
    Preparing search index...

    Fixture for ThemeSelect component

      public constructor(private readonly page: Page) {
    this.navBar = this.page.getByTestId('nav-bar');
    this.logoLink = this.navBar.getByTestId('logo-link');
    this.desktopComponents = this.navBar.getByTestId('desktop-components');
    this.mobileComponents = this.navBar.getByTestId('mobile-components');
    this.siteLinks = new SiteLinks(this.navBar.getByTestId('desktop-components'));
    this.socialIcons = new SocialIcons(this.navBar.getByTestId('desktop-components'));
    this.themeSelects = {
    mobileThemeSelect: new ThemeSelect(page, this.navBar.getByTestId('mobile-components')),
    desktopThemeSelect: new ThemeSelect(page, this.navBar.getByTestId('desktop-components'))
    };
    this.hamburgerMenu = new HamburgerMenu(this.page);
    }

    Provides method helpers for locating children elements and interactivity.

    Used in example to be accessed in testing environment.

    export default class ThemeSelect implements Component {
    /** Component wrapper. {@link themeSelect} */
    private readonly themeSelect: Locator;
    /** Child {@link select}. */
    private readonly select: Select;

    /**
    * Fixture constructor - initialise variables.
    * @param page - Playwright Page object.
    * @param parent - Parent element.
    */
    public constructor(
    private readonly page: Page,
    private readonly parent: Locator
    ) {
    this.themeSelect = this.parent.getByTestId('theme-select');
    this.select = new Select(this.themeSelect);
    }

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

    /** Testing helper method. */
    public async rendersCorrectly(): Promise<boolean> {
    expect(await this.getSelect().rendersCorrectly()).toBeTruthy();
    return true;
    }

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

    /** Getter method. @returns Theme value stored in local storage. */
    public async getTheme(): Promise<string | null> {
    return this.page.evaluate((): string | null => window.localStorage.getItem('theme'));
    }

    /** Setter method; sets theme value stored in local storage. */
    public async setTheme(theme: string): Promise<void> {
    await this.select.selectOption(`${theme}-option`);
    }
    }

    Implements

    Index

    Constructors

    Properties

    themeSelect: Locator

    Component wrapper. themeSelect

    select: Select

    Child select.

    page: Page

    Playwright Page object.

    parent: Locator

    Parent element.

    Methods

    • Setter method; sets theme value stored in local storage.

      Parameters

      • theme: string

      Returns Promise<void>