storefront, storefront-errors, theme, error-boundary and filters. filters.spec.ts carried the last hand-rolled copies of createCategory, createTag and createItem, and the hardcoded `http://localhost:5173` that meant changing the port in the config would have moved every test except this one. Seeding now goes through support/api, and the host it needs lives in one constant. It has to be a constant rather than the config's baseURL: beforeAll runs with worker-scoped fixtures only and cannot read a test-scoped option, which is why the URL was inlined there in the first place. New FilterDrawer object. The two rules it encodes are the ones the tests exist to pin down and neither is guessable from a locator: categories are a tree because the filter matches a node and everything filed beneath it, and tags combine with AND rather than OR, so selecting two means "must have both". The active-filter chips go on StorefrontPage rather than the drawer, because that is where they render — and the scoping matters, since the drawer carries a "Clear all" of its own that an unscoped locator also matches. StorefrontPage gains the three things the catalogue says instead of listing items. They are named together deliberately: the distinction between "No items yet" and "Couldn't load items" is the point, and several tests assert one is showing while the other is not, because telling a customer the shop is empty when the server is broken hides the outage. The theme switch and the attribute it writes are both on Header now. The switch is in the header and `data-theme` lands on <body>, so a spec previously had to know about `body` to observe the control it had just clicked. Verified: 12/12 across the four small specs, 8/8 on filters, tsc clean, lint unchanged at the 30-warning src baseline. Refs #137
56 lines
2.1 KiB
TypeScript
56 lines
2.1 KiB
TypeScript
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 signUpButton: Locator;
|
|
readonly cartButton: Locator;
|
|
readonly themeToggle: Locator;
|
|
/**
|
|
* Where the theme actually lands. The switch is in the header, and the
|
|
* attribute it writes is on <body> — so the control and its observable
|
|
* effect are named together rather than a spec knowing about `body`.
|
|
*/
|
|
readonly themedBody: 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.signUpButton = page.getByRole('button', { name: 'Sign up' });
|
|
this.cartButton = page.getByRole('button', { name: /Cart/ });
|
|
this.themeToggle = page.getByRole('switch');
|
|
this.themedBody = page.locator('body');
|
|
}
|
|
|
|
/**
|
|
* 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<void> {
|
|
await expect(this.myAccountButton).toBeVisible({ timeout: 20000 });
|
|
}
|
|
|
|
async waitForSignedOut(): Promise<void> {
|
|
await expect(this.myAccountButton).toHaveCount(0);
|
|
}
|
|
|
|
/** The theme currently applied, as the attribute a stylesheet reads. */
|
|
async currentTheme(): Promise<string | null> {
|
|
return this.themedBody.getAttribute('data-theme');
|
|
}
|
|
}
|