import { expect, test, type Page } from "./utils/test"; import { expectNoCriticalA11yViolations } from "./utils/axe"; import { expectAllPasswordRequirementsMet, expectPasswordRequirementsVisible, expectSomePasswordRequirementsMissing } from "./utils/auth"; import { expectNoHorizontalOverflow, narrowMobileViewport } from "./utils/mobile"; import { skipOrFailWhenE2eFixtureMissing } from "./utils/readiness"; async function openRegistrationPlanStep(page: Page): Promise { const planStep = page.locator('[data-ui-id="ui.auth.register.planStep"]'); if (await planStep.isVisible()) return; const email = page.locator('[data-ui-id="ui.auth.register.email"]').first(); if ((await email.inputValue()) === "") await email.fill(`registration-contract-${Date.now()}@example.test`); const password = page.locator('[data-ui-id="ui.auth.register.password"]').first(); if ((await password.count()) > 0 && (await password.isVisible()) && (await password.inputValue()) === "") await password.fill("LongEnough1!"); const firstName = page.locator('[data-ui-id="ui.auth.register.firstName"]').first(); const lastName = page.locator('[data-ui-id="ui.auth.register.lastName"]').first(); const company = page.locator('[data-ui-id="ui.auth.register.company"]').first(); if ((await firstName.count()) > 0 && (await firstName.inputValue()) === "") await firstName.fill("E2E"); if ((await lastName.count()) > 0 && (await lastName.inputValue()) === "") await lastName.fill("Registration"); if ((await company.count()) > 0 && (await company.inputValue()) === "") await company.fill("E2E Registration"); await page.locator('[data-ui-id="ui.auth.register.toPlanStep"]').click(); await expect(planStep).toBeVisible(); } test.describe("register page a11y", () => { test("/register has no critical or serious axe violations", async ({ page }) => { await page.goto("/register", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { await expect(page.locator('input[type="email"], input[name="email"], input#email').first()).toBeVisible(); await expectNoCriticalA11yViolations(page); return; } await expect(page.locator("body")).toBeVisible(); await expectNoCriticalA11yViolations(page); }); test("/register announces password requirement status through accessible names", async ({ page }) => { await page.goto("/register", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } const passwordInput = page.locator('input[type="password"], input[name="password"], input#password').first(); if ((await passwordInput.count()) === 0 || !(await passwordInput.isVisible())) { skipOrFailWhenE2eFixtureMissing("Registration password input is not rendered in this environment"); } const requirements = page.locator('[aria-live="polite"]').first(); await expectPasswordRequirementsVisible(requirements); await passwordInput.fill("short"); await expectSomePasswordRequirementsMissing(requirements); await passwordInput.fill("LongEnough1!"); await expectAllPasswordRequirementsMet(requirements); }); test("/register shows the canonical paid plans and honors a deep-linked choice", async ({ page }) => { await page.goto("/register?plan=business", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } await openRegistrationPlanStep(page); const planSelection = page.locator('[data-ui-id="ui.auth.register.planSelection"]'); await expect(planSelection).toBeVisible(); await expect(planSelection.getByText("Core", { exact: true })).toBeVisible(); await expect(planSelection.getByText("Swarm", { exact: true })).toBeVisible(); await expect(planSelection.getByText("Colony", { exact: true })).toBeVisible(); await expect(planSelection.getByRole("radio")).toHaveCount(3); const colony = planSelection.getByRole("radio", { name: /^Colony/iu }); await expect(colony).toBeChecked(); await expect(page.locator('input[name="selectedSubscriptionPriceId"]')).toHaveValue((await colony.getAttribute("value")) ?? ""); }); test("/register submit contract posts expected fields without creating an account", async ({ page }) => { const redirectTo = "/app/dashboard"; await page.goto(`/register?redirect=${encodeURIComponent(redirectTo)}`, { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } const form = page.locator("form").first(); const emailInput = form.locator('[data-ui-id="ui.auth.register.email"], input[type="email"], input[name="email"], input#email').first(); const passwordInput = form.locator('[data-ui-id="ui.auth.register.password"], input[type="password"], input[name="password"], input#password').first(); if ((await form.count()) === 0 || (await emailInput.count()) === 0 || (await passwordInput.count()) === 0) { skipOrFailWhenE2eFixtureMissing("Registration form is not rendered in this environment"); } const email = `contract-${Date.now()}@example.test`; const firstName = "E2E"; const lastName = "Contract"; const company = "E2E Contract"; await emailInput.fill(email); await passwordInput.fill("LongEnough1!"); const companyInput = form.locator('[data-ui-id="ui.auth.register.company"], input[name="company"]').first(); const hasCompanyInput = (await companyInput.count()) > 0; if (hasCompanyInput) await companyInput.fill(company); const firstNameInput = form.locator('[data-ui-id="ui.auth.register.firstName"], input[name="first-name"]').first(); const lastNameInput = form.locator('[data-ui-id="ui.auth.register.lastName"], input[name="last-name"]').first(); const hasFirstNameInput = (await firstNameInput.count()) > 0; const hasLastNameInput = (await lastNameInput.count()) > 0; if (hasFirstNameInput) await firstNameInput.fill(firstName); if (hasLastNameInput) await lastNameInput.fill(lastName); await openRegistrationPlanStep(page); await page.locator('[data-ui-id="ui.auth.register.consentTerms"]').click(); await page.locator('[data-ui-id="ui.auth.register.consentPrivacy"]').click(); const currentPathname = new URL(page.url()).pathname; let resolveSubmitted!: (formData: URLSearchParams) => void; const submitted = new Promise((resolve) => { resolveSubmitted = resolve; }); await page.route("**/*", async (route) => { const request = route.request(); const requestUrl = new URL(request.url()); // React Router single-fetch posts form actions to `${pathname}.data`, so // match both the route path and its `.data` sibling. const matchesRoute = requestUrl.pathname === currentPathname || requestUrl.pathname === `${currentPathname}.data`; if (request.method() !== "POST" || !matchesRoute) { await route.continue(); return; } const formData = new URLSearchParams(request.postData() ?? ""); resolveSubmitted(formData); await route.fulfill({ status: 200, contentType: "text/html", body: "Registration intercepted", }); }); const selectedSubscriptionPriceId = await form.locator('input[name="selectedSubscriptionPriceId"]').inputValue(); await form.locator('button[type="submit"]').first().click(); const formData = await submitted; expect(formData.get("csrf") ?? "").not.toBe(""); expect(formData.get("email")).toBe(email); expect(formData.get("password")).toBe("LongEnough1!"); expect(formData.get("redirectTo")).toBe(redirectTo); expect(formData.get("selectedSubscriptionPriceId")).toBe(selectedSubscriptionPriceId); if (hasCompanyInput) expect(formData.get("company")).toBe(company); if (hasFirstNameInput) expect(formData.get("first-name")).toBe(firstName); if (hasLastNameInput) expect(formData.get("last-name")).toBe(lastName); }); }); test.describe("register validation mobile a11y", () => { test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true }); test("/register exposes validation feedback accessibly on mobile", async ({ page }) => { await page.goto("/register", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } const emailInput = page.locator('input[type="email"], input[name="email"], input#email').first(); const passwordInput = page.locator('input[type="password"], input[name="password"], input#password').first(); if ((await emailInput.count()) === 0 || (await passwordInput.count()) === 0) { skipOrFailWhenE2eFixtureMissing("Registration form is not rendered in this environment"); } const companyInput = page.locator('input[name="company"]').first(); if ((await companyInput.count()) > 0) await companyInput.fill("E2E Validation"); const firstNameInput = page.locator('input[name="first-name"]').first(); if ((await firstNameInput.count()) > 0) await firstNameInput.fill("E2E"); const lastNameInput = page.locator('input[name="last-name"]').first(); if ((await lastNameInput.count()) > 0) await lastNameInput.fill("Validation"); await emailInput.fill("registration-validation@example.test"); await passwordInput.fill("LongEnough1!"); await openRegistrationPlanStep(page); const officeSeats = page.locator('[data-ui-id="ui.auth.register.officeSeats"]'); await officeSeats.fill("0"); await page.locator('[data-ui-id="ui.auth.register.consentTerms"]').click(); await page.locator('[data-ui-id="ui.auth.register.consentPrivacy"]').click(); await page.locator('button[type="submit"]').first().click(); const formError = page.getByRole("alert").first(); await expect(formError).toBeVisible(); await expect(officeSeats).toBeEnabled(); const requirements = page.locator('[aria-live="polite"]').first(); if ((await requirements.count()) > 0) { await expectAllPasswordRequirementsMet(requirements); } await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); });