import { Locator, Page, expect } from '@playwright/test'; /** * The site header, which is where a test finds out whether anyone is signed in. * * Registering and logging in both close their modal and return the customer to * the page behind it rather than navigating to /account, so the URL says * nothing about whether a session exists. The account button in the header is * what does. */ export class Header { readonly siteTitle: Locator; readonly myAccountButton: Locator; readonly logInButton: Locator; readonly cartButton: Locator; readonly themeToggle: Locator; constructor(page: Page) { this.siteTitle = page.getByRole('heading', { name: 'Redefined Designs' }); this.myAccountButton = page.getByRole('button', { name: 'My Account' }); this.logInButton = page.getByRole('button', { name: 'Log in' }); this.cartButton = page.getByRole('button', { name: /Cart/ }); this.themeToggle = page.getByRole('switch'); } /** * Waits until the header shows a signed-in customer. * * The timeout is generous because this waits on a bcrypt round-trip rather * than a render, and every worker in a parallel run registers at once. The * default five seconds is comfortably beaten on an idle machine and missed on * a loaded one, which is the recipe for a test that fails only in CI. */ async waitForSignedIn(): Promise { await expect(this.myAccountButton).toBeVisible({ timeout: 20000 }); } async waitForSignedOut(): Promise { await expect(this.myAccountButton).toHaveCount(0); } }