Jack Maclennan Portfolio
    Preparing search index...

    Fixture for SiteLinks component

        this.siteLinks = new SiteLinks(
    this.navBar.getByRole('navigation', { name: 'Site links' }).filter({ visible: true })
    );

    Provides method helpers for locating children elements and interactivity.

    Used in example to be accessed in testing environment.

    export default class SiteLinks implements ListComponent {
    /** @public Projects link element. */
    private readonly projectsLink: Locator;
    /** @public Experience link element. */
    private readonly experienceLink: Locator;
    /** @public About me link element. */
    private readonly aboutMeLink: Locator;
    /** @public Link to docs GitHub Page. */
    private readonly docsLink: Locator;

    /**
    * Fixture constructor - initialise variables.
    * @param siteLinks - Site links locator.
    */
    public constructor(private readonly siteLinks: Locator) {
    this.projectsLink = this.siteLinks.getByRole('link', { name: 'projects' });
    this.experienceLink = this.siteLinks.getByRole('link', { name: 'experience' });
    this.aboutMeLink = this.siteLinks.getByRole('link', { name: 'about me' });
    this.docsLink = this.siteLinks.getByRole('link', { name: 'docs' });
    }

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

    /** Testing helper method. */
    public async rendersCorrectly(): Promise<boolean> {
    await expect(this.getWrapper(), 'wrapper is visible').toBeVisible();
    await expect(this.getProjectsLink(), 'projects link is visible').toBeVisible();
    await expect(this.getExperienceLink(), 'experience link is visible').toBeVisible();
    await expect(this.getAboutMeLink(), 'about me link is visible').toBeVisible();
    await expect(this.getDocsLink(), 'docs link is visible').toBeVisible();
    expect(await this.getListLength(), 'list length is 4').toBe(4);
    return true;
    }

    /** Testing helper method; ensures links function as intended. */
    public async navigatesCorrectly(page: Page, beforeEach?: () => Promise<void>): Promise<boolean> {
    if (beforeEach !== undefined) await beforeEach();
    await this.navigateToProjects(page);
    await expect(page, 'navigate to projects page').toHaveURL('/projects');
    if (beforeEach !== undefined) await beforeEach();
    await this.navigateToExperience(page);
    await expect(page, 'navigate to experience page').toHaveURL('/experience');
    if (beforeEach !== undefined) await beforeEach();
    await this.navigateToAboutMe(page);
    await expect(page, 'navigate to about me page').toHaveURL('/about-me');
    if (beforeEach !== undefined) await beforeEach();
    await this.navigateToDocs(page);
    return true;
    }

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

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

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

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

    /** Interact with {@link projectsLink}. @param page - Playwright Page object */
    public async navigateToProjects(page: Page): Promise<void> {
    const projectsLink: Locator = this.getProjectsLink();
    expect(projectsLink, 'projects link is visible').toBeVisible();
    await projectsLink.click();
    await page.waitForURL('**/projects');
    }

    /** Interact with {@link experienceLink}. @param page - Playwright Page object */
    public async navigateToExperience(page: Page): Promise<void> {
    const experienceLink: Locator = this.getExperienceLink();
    expect(experienceLink, 'experience link is visible').toBeVisible();
    await experienceLink.click();
    await page.waitForURL('**/experience');
    }

    /** Interact with {@link aboutMeLink}. @param page - Playwright Page object */
    public async navigateToAboutMe(page: Page): Promise<void> {
    const aboutMeLink: Locator = this.getAboutMeLink();
    expect(aboutMeLink, 'about me link is visible').toBeVisible();
    await aboutMeLink.click();
    await page.waitForURL('**/about-me');
    }

    /** Interact with {@link docsLink}. @param page - Playwright Page object */
    public async navigateToDocs(page: Page): Promise<void> {
    const docsLink: Locator = this.getDocsLink();
    expect(docsLink, 'docs link is visible').toBeVisible();
    await expect(docsLink, 'docs link has correct href').toHaveAttribute(
    'href',
    'https://maclenjack.github.io/jack-maclennan-portfolio-docs/'
    );
    await expect(docsLink, 'docs link opens in a new tab').toHaveAttribute('target', '_blank');

    const [newPage] = await Promise.all([page.waitForEvent('popup'), docsLink.click()]);

    await newPage.waitForLoadState('domcontentloaded');
    await expect(newPage, 'docs page opened correctly').toHaveURL(
    'https://maclenjack.github.io/jack-maclennan-portfolio-docs/'
    );
    await newPage.close();
    }

    /** Getter method. @returns Link element children. */
    public getListItems(): Locator {
    return this.siteLinks.getByRole('link');
    }

    /** Getter method. @inheritDoc */
    public async getListLength(): Promise<number> {
    return this.getListItems().count();
    }

    /** Getter method. @returns Link child at given index. */
    public getListItemByIndex(index: number): Locator {
    return this.getListItems().nth(index);
    }
    }

    Implements

    Index

    Constructors

    Properties

    projectsLink: Locator

    Projects link element.

    experienceLink: Locator

    Experience link element.

    aboutMeLink: Locator

    About me link element.

    docsLink: Locator

    Link to docs GitHub Page.

    siteLinks: Locator

    Site links locator.

    Methods

    • Testing helper method; ensures links function as intended.

      Parameters

      • page: Page
      • OptionalbeforeEach: () => Promise<void>

      Returns Promise<boolean>