Jack Maclennan Portfolio
    Preparing search index...

    Fixture for ThemeSelect component

          testOptions.forEach(({ theme, themeName }: TestOption, i: number) => {
    test(`set theme to ${themeName}`, async ({ navBar }) => {
    const themeSelect: ThemeSelect = navBar.getThemeSelect();
    await themeSelect.setTheme(testOptions[(i + 1) % 3].themeName);
    await themeSelect.setTheme(themeName);
    const resolvedTheme = await themeSelect.getTheme();
    expect(resolvedTheme, 'stored theme value is correct').toEqual(theme);
    });
    });

    Provides method helpers for locating children elements and interactivity.

    Used in example to be accessed in testing environment.

    export default class ThemeSelect extends Select {
    /**
    * Fixture constructor - initialise variables.
    * @param page - Playwright Page object.
    * @param themeSelect - ThemeSelect locator.
    */
    public constructor(
    private readonly page: Page,
    public readonly themeSelect: Locator
    ) {
    super(themeSelect);
    }

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

    /** Testing helper method. */
    public async rendersCorrectly(): Promise<boolean> {
    await expect(this.getWrapper(), 'theme select should be visible').toBeVisible();
    await super.rendersCorrectly();
    return true;
    }

    /** Getter method. @returns {@link select}. */
    public getSelect(): Locator {
    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> {
    const themeLabels: Record<string, string> = {
    'light-mode': 'Light',
    'dark-mode': 'Dark',
    'system-default': 'System'
    };
    await super.selectOption(themeLabels[theme] || theme);
    }
    }

    Hierarchy (View Summary)

    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 locator containing the select component.

    page: Page

    Playwright Page object.

    themeSelect: Locator

    ThemeSelect locator.

    Methods

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

      Parameters

      • theme: string

      Returns Promise<void>