import { expect, test } from "@playwright/test"; import { signInAs } from "./fixtures/auth"; test("customer can browse and reach the booking confirm page", async ({ page }) => { // /book/confirm requires an authenticated session, so sign in first. await signInAs(page, "customer", "/"); await page.goto("/"); await expect(page.getByRole("heading", { name: /book a session/i })).toBeVisible(); // First service "Book" link → /book?serviceId=... const firstBook = page.locator('a[href^="/book?serviceId="]').first(); await expect(firstBook).toBeVisible(); await firstBook.click(); await expect(page).toHaveURL(/\/book\?serviceId=/); await expect(page.getByRole("heading", { level: 1 })).toBeVisible(); // Pick a date a few days out so slots are likely available. const dateInput = page.locator('input[type="date"][name="date"]'); await expect(dateInput).toBeVisible(); const target = new Date(); target.setDate(target.getDate() + 3); const iso = target.toISOString().slice(0, 10); await dateInput.fill(iso); await page.getByRole("button", { name: /show times/i }).click(); await expect(page).toHaveURL(new RegExp(`date=${iso}`)); // Grab the first slot's href and visit it directly. const slot = page.locator('a[href^="/book/confirm?"]').first(); await expect(slot, "expected at least one available slot").toBeVisible(); const slotHref = await slot.getAttribute("href"); expect(slotHref).toMatch(/^\/book\/confirm\?/); await page.goto(slotHref!); // Already authenticated, so we land on the confirm form (not /login). await expect(page).toHaveURL(/\/book\/confirm\?/); await expect(page.getByRole("heading", { level: 1 })).toBeVisible(); // /account/bookings should be reachable while signed in. await page.goto("/account/bookings"); await expect(page).toHaveURL(/\/account\/bookings/); await expect(page.getByRole("heading", { level: 1 })).toBeVisible(); });