Jack Maclennan Portfolio
    Preparing search index...

    Fixture for Modal within HamburgerMenu.

          test('renders modal correctly', async ({ hamburgerMenu }) => {
    await hamburgerMenu.openModal();
    expect(await hamburgerMenu.getModal().rendersCorrectly()).toBeTruthy();
    });

    Provides method helpers for locating child elements and interactivity. Extends the base Modal class with HamburgerMenu-specific functionality.

    export class HamburgerModal extends Modal {
    /** @public Child {@link SocialIcons}. */
    private readonly socialIcons: SocialIcons;
    /** @public Child {@link SiteLinks}. */
    private readonly siteLinks: SiteLinks;
    /** @public Child close-icon. */
    private readonly closeIcon: Locator;

    /**
    * @param page - Playwright page object.
    */
    public constructor(page: Page) {
    super(page);
    this.socialIcons = new SocialIcons(
    this.modal.getByRole('group', { name: 'Social links' }).filter({ visible: true })
    );
    this.siteLinks = new SiteLinks(
    this.modal.getByRole('navigation', { name: 'Site links' }).filter({ visible: true })
    );
    this.closeIcon = this.modal.getByRole('button', { name: 'exit hamburger menu' });
    }

    /** Testing helper method. */
    public async rendersCorrectly(): Promise<boolean> {
    if (await this.getWrapper().isHidden()) {
    await expect(this.getSocialIcons().getWrapper(), 'site links hidden when modal closed').toBeHidden();
    await expect(this.getSiteLinks().getWrapper(), 'site links hidden when modal closed').toBeHidden();
    await expect(this.getCloseIcon(), 'close icon hidden when modal closed').toBeHidden();
    await expect(this.getWrapper()).toBeHidden();
    } else {
    expect(await this.getSocialIcons().rendersCorrectly()).toBeTruthy();
    expect(await this.getSiteLinks().rendersCorrectly()).toBeTruthy();
    await expect(this.getCloseIcon(), 'close icon should be visible when modal open').toBeVisible();
    }
    return true;
    }

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

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

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

    /** Closes modal by interacting with {@link closeIcon}. */
    public async closeModal(): Promise<void> {
    await expect(this.modal, 'modal should be visible').toBeVisible();
    await this.getCloseIcon().click();
    await expect(this.modal, 'modal should be hidden').toBeHidden();
    }

    /**
    * Closes the modal when screen width exceeds the mobile breakpoint.
    * @param breakpointWidth - The width at which the modal should close (default: 768px).
    */
    public async closeOnScreenChange(breakpointWidth: number = 768): Promise<boolean> {
    return await super.closeOnScreenChange(breakpointWidth);
    }
    }

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    socialIcons: SocialIcons

    Child SocialIcons.

    siteLinks: SiteLinks

    Child SiteLinks.

    closeIcon: Locator

    Child close-icon.

    modal: Locator

    Modal wrapper element.

    page: Page

    Playwright page object.

    Methods

    • Closes the modal when screen width exceeds the mobile breakpoint.

      Parameters

      • breakpointWidth: number = 768

        The width at which the modal should close (default: 768px).

      Returns Promise<boolean>

    • Waits for screen size change and handles modal state accordingly.

      Parameters

      • width: number

        Target width to resize to.

      • height: number

        Target height to resize to.

      Returns Promise<void>