Jack Maclennan Portfolio
    Preparing search index...

    Fixture for NavBar component

        test('renders correctly', async ({ navBar }) => {
    expect(await navBar.rendersCorrectly()).toBeTruthy();
    });

    Provides method helpers for locating child elements.

    export default class NavBar implements Component {
    /** @public Component wrapper. */
    private readonly navBar: Locator;
    /** @public Logo link element. */
    private readonly logoLink: Locator;
    /** @public Child {@link SiteLinks}. */
    private readonly siteLinks: SiteLinks;
    /** @public Child {@link SocialIcons}. */
    private readonly socialIcons: SocialIcons;
    /** @public Child {@link ThemeSelect}s. */
    private readonly themeSelect: ThemeSelect;
    /** @public Child {@link HamburgerMenu} */
    private readonly hamburgerMenu: HamburgerMenu;

    /**
    * Fixture constructor - initialise variables.
    * @param page - Playwright page object.
    */
    public constructor(private readonly page: Page) {
    this.navBar = this.page.getByRole('navigation', { name: 'Main navigation' });
    this.logoLink = this.navBar.getByRole('link', { name: 'home' });
    this.siteLinks = new SiteLinks(
    this.navBar.getByRole('navigation', { name: 'Site links' }).filter({ visible: true })
    );
    this.socialIcons = new SocialIcons(
    this.navBar.getByRole('group', { name: 'Social links' }).filter({ visible: true })
    );
    this.themeSelect = new ThemeSelect(
    this.page,
    this.navBar.getByRole('group', { name: 'theme selector' }).filter({ visible: true })
    );
    this.hamburgerMenu = new HamburgerMenu(this.page);
    }

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

    /** Testing helper method. */
    public async rendersCorrectly(): Promise<boolean> {
    const viewportSize = this.page.viewportSize();
    const isMobile = viewportSize !== null && viewportSize.width < 768;

    await expect(this.getWrapper(), 'navbar is visible').toBeVisible();
    await expect(this.getLogo(), 'logo is visible').toBeVisible();
    expect(this.getThemeSelect().rendersCorrectly()).toBeTruthy();
    if (isMobile) {
    await expect(this.getSiteLinks().getWrapper(), 'site links hidden on mobile').toBeHidden();
    await expect(this.getSocialIcons().getWrapper(), 'social icons hidden on mobile').toBeHidden();
    expect(await this.getHamburgerMenu().rendersCorrectly()).toBeTruthy();
    } else {
    await expect(this.getHamburgerMenu().getWrapper(), 'hamburger menu hidden on desktop').toBeHidden();
    expect(await this.getSiteLinks().rendersCorrectly()).toBeTruthy();
    expect(await this.getSiteLinks().navigatesCorrectly(this.page)).toBeTruthy();
    expect(await this.getSocialIcons().rendersCorrectly()).toBeTruthy();
    }
    return true;
    }

    /** Getter method. @returns {@link logoLink}. */
    getLogo(): Locator {
    return this.logoLink;
    }

    /** Getter method @returns visible theme select using Playwright's visibility filtering. */
    public getThemeSelect(): ThemeSelect {
    return this.themeSelect;
    }

    /** Getter method. @returns {@link siteLinks}. */
    getSiteLinks(): SiteLinks {
    return this.siteLinks;
    }

    /** Getter method. @returns {@link socialIcons}. */
    getSocialIcons(): SocialIcons {
    return this.socialIcons;
    }

    /** Getter method. @returns {@link hamburgerMenu}. */
    public getHamburgerMenu(): HamburgerMenu {
    return this.hamburgerMenu;
    }
    }

    Implements

    Index

    Constructors

    Properties

    navBar: Locator

    Component wrapper.

    logoLink: Locator

    Logo link element.

    siteLinks: SiteLinks

    Child SiteLinks.

    socialIcons: SocialIcons

    Child SocialIcons.

    themeSelect: ThemeSelect

    Child ThemeSelects.

    hamburgerMenu: HamburgerMenu
    page: Page

    Playwright page object.

    Methods