import { expect, test, type Page } from "./utils/test"; import { expectNoCriticalA11yViolations } from "./utils/axe"; import { expectAllPasswordRequirementsMet, expectPasswordRequirementsVisible, expectSomePasswordRequirementsMissing, getTenantCredentials, loginAsTenantUser, tenantSettingsAccountPath, tenantSettingsProfilePath, tenantSettingsSubscriptionPath, } from "./utils/auth"; import { compactMobileViewport, expectNoHorizontalOverflow, narrowMobileViewport } from "./utils/mobile"; import { escapeRegExp, failOnStripeNetworkRequests, interceptCurrentRoutePost, postDataIncludesField, singleFetchActionError, skipIfUnavailable } from "./utils/navigation"; import { optionalE2eBooleanInput, skipOrFailWhenE2eFixtureMissing, skipOrFailWhenE2eInputsMissing, skipOrFailWhenE2eOptInMissing } from "./utils/readiness"; const credentials = getTenantCredentials(); const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH ?? "/app/dashboard"; // On mobile the sidebar lives in a closed Sheet (only mounted when opened), so // its trigger is the visible shell affordance. Accept the trigger too, so "the // authenticated shell rendered" holds on mobile (trigger) and desktop (sidebar). const appSidebarSelector = '[data-ui-id="ui.surface.app.sidebar"], [data-ui-id="ui.surface.app.sidebar.mobile"], [data-mobile="true"], [data-ui-id="ui.action.shell.sidebarTrigger"]'; const zeroTenantAccountStatePattern = /(?:you belong to 0|0 accounts?|no organizations|no organisations|no account belongs|does not belong to (?:an|any) account|keinem konto|keiner organisation)/iu; // On mobile the app nav lives inside the sidebar Sheet, which is closed by // default; open it via the trigger (only when the link is not already mounted, // to avoid toggling an already-open sidebar shut) before asserting the link. async function expectDashboardNavLink(page: Page, dashboardPath: string): Promise { const link = page.locator('[data-ui-id="ui.nav.app.dashboard"]').first(); let openedSheet = false; if ((await link.count()) === 0) { const trigger = page.locator('[data-ui-id="ui.action.shell.sidebarTrigger"]').first(); if (await trigger.isVisible().catch(() => false)) { await trigger.click(); openedSheet = true; } } await expect(link).toHaveAttribute("href", new RegExp(`${escapeRegExp(dashboardPath)}(?:[?#].*)?$`, "u")); if (openedSheet) { // Restore the default closed state so subsequent overflow/a11y scans don't // run against an open drawer overlay. await page.keyboard.press("Escape").catch(() => undefined); await expect(link).toHaveCount(0).catch(() => undefined); } } test.describe("registration to account dashboard mobile a11y", () => { test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true }); test("keeps register usable on mobile with live password requirement feedback", async ({ page }) => { await page.goto("/register", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { await expect(page.locator('[data-ui-id="ui.auth.login.email"], input[type="email"], input[name="email"], input#email').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } await expect(page.locator("body")).toBeVisible(); await expectNoHorizontalOverflow(page); const emailInput = page.locator('[data-ui-id="ui.auth.register.email"]').first(); const passwordInput = page.locator('[data-ui-id="ui.auth.register.password"]').first(); await expect(page.locator('[data-ui-id="ui.auth.register.form"]').first()).toBeVisible(); await expect(emailInput).toBeVisible(); if ((await passwordInput.count()) === 0 || !(await passwordInput.isVisible())) { skipOrFailWhenE2eFixtureMissing("Registration password input is not rendered in this environment"); } const requirements = page.locator('[data-ui-id="ui.auth.register.passwordRequirements"]').first(); await expect(requirements).toHaveAttribute("aria-live", "polite"); // The number of requirements is driven by the server password policy (4 on // this environment), so assert a meaningful lower bound rather than a fixed 5. await expect.poll(() => requirements.locator("li").count()).toBeGreaterThanOrEqual(4); await expectPasswordRequirementsVisible(requirements); await passwordInput.fill("short"); await expectSomePasswordRequirementsMissing(requirements); await passwordInput.fill("LongEnough1!"); await expectAllPasswordRequirementsMet(requirements); await expect(page.locator('[data-ui-id="ui.auth.register.submit"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("keeps dashboard redirects wired through registration auth options on mobile", async ({ page }) => { const redirectTo = dashboardPath; 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('[data-ui-id="ui.auth.register.form"], form').first(); if ((await form.count()) === 0) { skipOrFailWhenE2eFixtureMissing("Registration form is not rendered in this environment"); } await expect(form).toBeVisible(); await expect(form.locator('input[name="redirectTo"]').first()).toHaveValue(redirectTo); await expect(form.locator('input[name="csrf"]').first()).not.toHaveValue(""); const githubLink = page.locator('a[href^="/oauth/github/start?redirectTo="]').first(); if ((await githubLink.count()) > 0 && (await githubLink.isVisible())) { const href = await githubLink.getAttribute("href"); expect(new URL(href ?? "", "http://e2e.local").searchParams.get("redirectTo")).toBe(redirectTo); } await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("posts the registration contract on mobile without creating an account", async ({ page }) => { const redirectTo = dashboardPath; 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('[data-ui-id="ui.auth.register.form"], 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 = `mobile-contract-${Date.now()}@example.test`; const company = "Mobile Contract"; const firstName = "Mobile"; const lastName = "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 expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const submitted = await interceptCurrentRoutePost(page, { status: 200, body: "Registration intercepted", contentType: "text/html", }); await form.locator('[data-ui-id="ui.auth.register.submit"], button[type="submit"]').first().click(); await expect.poll(() => submitted.value, { timeout: 5_000 }).not.toBeNull(); expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true); expect(postDataIncludesField(submitted.value, "email", new RegExp(`^${escapeRegExp(email)}$`, "u"))).toBe(true); expect(postDataIncludesField(submitted.value, "password", /^LongEnough1!$/u)).toBe(true); expect(postDataIncludesField(submitted.value, "redirectTo", new RegExp(`^${escapeRegExp(redirectTo)}$`, "u"))).toBe(true); if (hasCompanyInput) expect(postDataIncludesField(submitted.value, "company", new RegExp(`^${escapeRegExp(company)}$`, "u"))).toBe(true); if (hasFirstNameInput) expect(postDataIncludesField(submitted.value, "first-name", new RegExp(`^${escapeRegExp(firstName)}$`, "u"))).toBe(true); if (hasLastNameInput) expect(postDataIncludesField(submitted.value, "last-name", new RegExp(`^${escapeRegExp(lastName)}$`, "u"))).toBe(true); }); test("can register a new user, reach a tenant dashboard, and log back in when explicitly enabled", async ({ page, context }) => { skipOrFailWhenE2eOptInMissing("E2E_ALLOW_REGISTRATION_CREATE", "skipping mutating registration provisioning flow"); const expectsEmailVerification = optionalE2eBooleanInput("E2E_REGISTRATION_EXPECTS_EMAIL_VERIFICATION"); if (expectsEmailVerification === true) { skipOrFailWhenE2eFixtureMissing("Dashboard provisioning readiness is covered only when registration does not stop for email verification"); } await failOnStripeNetworkRequests(page); await page.goto("/register", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } const form = page.locator('[data-ui-id="ui.auth.register.form"], 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(); const submitButton = form.locator('[data-ui-id="ui.auth.register.submit"], button[type="submit"]').first(); if ((await form.count()) === 0 || (await emailInput.count()) === 0 || (await passwordInput.count()) === 0) { skipOrFailWhenE2eFixtureMissing("Registration form with password input is not rendered in this environment"); } const uniqueId = Date.now(); const email = `registration-provisioning-${uniqueId}@example.test`; const password = `LongEnough1!${uniqueId}`; const company = `E2E Registration ${uniqueId}`; await emailInput.fill(email); await passwordInput.fill(password); 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(); if ((await firstNameInput.count()) > 0) { await firstNameInput.fill("Registration"); } const lastNameInput = form.locator('[data-ui-id="ui.auth.register.lastName"], input[name="last-name"]').first(); if ((await lastNameInput.count()) > 0) { await lastNameInput.fill("Provisioning"); } await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); await Promise.all([page.waitForLoadState("domcontentloaded").catch(() => undefined), submitButton.click()]); const verificationBanner = page.getByText(/verification email|verify your email|bestätigungs.*e-mail|e-mail.*bestätigt/i).first(); const foundEmailVerification = /\/register(?:[?#].*)?$/u.test(page.url()) && (await verificationBanner.count()) > 0; if (foundEmailVerification) { skipOrFailWhenE2eFixtureMissing( "Registration requires email verification but E2E_REGISTRATION_EXPECTS_EMAIL_VERIFICATION=0 expects dashboard provisioning readiness" ); } await expect(page).not.toHaveURL(/\/(?:register|login|new-account)(?:[?#].*)?$/u); await expect(page).toHaveURL(/\/dashboard(?:[?#].*)?$/u, { timeout: 15_000 }); const createdDashboardPath = new URL(page.url()).pathname; await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expectProvisionedDashboardContinuity(page, createdDashboardPath); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); await expectProvisionedSettingsContinuity(page, createdDashboardPath, hasCompanyInput ? company : undefined); await expectProvisionedSubscriptionPage(page, createdDashboardPath); await context.clearCookies(); await page.goto(`/login?redirect=${encodeURIComponent(createdDashboardPath)}`, { waitUntil: "domcontentloaded" }); await page.locator('[data-ui-id="ui.auth.login.email"], input[type="email"], input[name="email"], input#email').first().fill(email); await page.locator('[data-ui-id="ui.auth.login.password"], input[type="password"], input[name="password"], input#password').first().fill(password); await Promise.all([page.waitForLoadState("domcontentloaded"), page.locator('[data-ui-id="ui.auth.login.submit"], button[type="submit"]').first().click()]); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(createdDashboardPath)}(?:[?#].*)?$`, "u"), { timeout: 15_000 }); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expectProvisionedDashboardContinuity(page, createdDashboardPath); await expectProvisionedSettingsContinuity(page, createdDashboardPath, hasCompanyInput ? company : undefined); await expectProvisionedSubscriptionPage(page, createdDashboardPath); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("can register a new user and stop at the email verification state when explicitly enabled", async ({ page }) => { skipOrFailWhenE2eOptInMissing("E2E_ALLOW_REGISTRATION_CREATE", "skipping mutating registration email-verification flow"); const expectsEmailVerification = optionalE2eBooleanInput("E2E_REGISTRATION_EXPECTS_EMAIL_VERIFICATION"); if (expectsEmailVerification !== true) { // Inverse-pair test: boiler runs with E2E_REGISTRATION_EXPECTS_EMAIL_VERIFICATION=0, // where registration provisions a tenant dashboard directly (covered by the sibling // "reach a tenant dashboard" test). This email-verification half is genuinely // inapplicable in that env, so skip honestly instead of fail-closing. test.skip(true, "Email verification readiness only applies when E2E_REGISTRATION_EXPECTS_EMAIL_VERIFICATION=1"); } await failOnStripeNetworkRequests(page); await page.goto("/register", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } const form = page.locator('[data-ui-id="ui.auth.register.form"], 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(); const submitButton = form.locator('[data-ui-id="ui.auth.register.submit"], button[type="submit"]').first(); if ((await form.count()) === 0 || (await emailInput.count()) === 0 || (await passwordInput.count()) === 0) { skipOrFailWhenE2eFixtureMissing("Registration form with password input is not rendered in this environment"); } const uniqueId = Date.now(); await emailInput.fill(`registration-verification-${uniqueId}@example.test`); await passwordInput.fill(`LongEnough1!${uniqueId}`); const companyInput = form.locator('[data-ui-id="ui.auth.register.company"], input[name="company"]').first(); if ((await companyInput.count()) > 0) { await companyInput.fill(`E2E Verification ${uniqueId}`); } const firstNameInput = form.locator('[data-ui-id="ui.auth.register.firstName"], input[name="first-name"]').first(); if ((await firstNameInput.count()) > 0) { await firstNameInput.fill("Registration"); } const lastNameInput = form.locator('[data-ui-id="ui.auth.register.lastName"], input[name="last-name"]').first(); if ((await lastNameInput.count()) > 0) { await lastNameInput.fill("Verification"); } await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); await Promise.all([page.waitForLoadState("domcontentloaded").catch(() => undefined), submitButton.click()]); await expect(page).toHaveURL(/\/register(?:[?#].*)?$/u, { timeout: 15_000 }); await expect(page.getByText(/verification email|verify your email|bestätigungs.*e-mail|e-mail.*bestätigt/i).first()).toBeVisible({ timeout: 15_000 }); await expect(page.locator('[data-ui-id="ui.auth.register.form"]').first()).toHaveCount(0); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toHaveCount(0); await expect(page.locator(appSidebarSelector).first()).toHaveCount(0); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("announces registration errors without leaving the form stuck", async ({ page }) => { await page.goto("/register", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } const form = page.locator('[data-ui-id="ui.auth.register.form"], 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(); const submitButton = form.locator('[data-ui-id="ui.auth.register.submit"], button[type="submit"]').first(); if ((await form.count()) === 0 || (await emailInput.count()) === 0 || (await passwordInput.count()) === 0) { skipOrFailWhenE2eFixtureMissing("Registration form is not rendered in this environment"); } await emailInput.fill(`mobile-error-${Date.now()}@example.test`); await passwordInput.fill("short"); // Let the real server validate (a short password fails before any account is // created); a faked JSON body is not valid single-fetch turbo-stream and would // break RR7's decoder, so we assert the genuine inline error instead. const submitted = await interceptCurrentRoutePost(page, { passthrough: true }); await submitButton.click(); await expect.poll(() => submitted.value, { timeout: 5_000 }).not.toBeNull(); await expect(form).toBeVisible(); await expect(page.getByRole("alert")).toContainText( /password is required|password must be|passwort.*(erforderlich|mindestens|zeichen)/i ); await expect(submitButton).toBeEnabled(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("keeps valid registration input retryable after duplicate-email errors", async ({ page }) => { await page.goto("/register", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } const form = page.locator('[data-ui-id="ui.auth.register.form"], 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(); const submitButton = form.locator('[data-ui-id="ui.auth.register.submit"], button[type="submit"]').first(); if ((await form.count()) === 0 || (await emailInput.count()) === 0 || (await passwordInput.count()) === 0) { skipOrFailWhenE2eFixtureMissing("Registration form is not rendered in this environment"); } // Use an already-registered email so the server returns a genuine duplicate // error (no account is created); a faked JSON body would break single-fetch. const email = getTenantCredentials()?.email ?? `duplicate-registration-${Date.now()}@example.test`; const password = "LongEnough1!aB"; await emailInput.fill(email); await passwordInput.fill(password); const companyInput = form.locator('[data-ui-id="ui.auth.register.company"], input[name="company"]').first(); if ((await companyInput.count()) > 0) { await companyInput.fill("Duplicate Registration"); } await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const submitted = await interceptCurrentRoutePost(page, { passthrough: true }); await submitButton.click(); await expect.poll(() => submitted.value, { timeout: 5_000 }).not.toBeNull(); await expect(form).toBeVisible(); await expect(page.getByRole("alert")).toContainText(/already (exists|registered)|existiert bereits|bereits.*(konto|registriert)/i); await expect(emailInput).toHaveValue(email); await expect(passwordInput).toHaveValue(password); await expect(submitButton).toBeEnabled(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("replays tenant dashboard deep links after login on mobile", async ({ page, context }) => { skipOrFailWhenE2eInputsMissing( ["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"], "Authenticated dashboard redirect replay inputs not configured" ); await context.clearCookies(); const protectedResponse = await page.goto(dashboardPath, { waitUntil: "domcontentloaded" }); expect(protectedResponse?.status() ?? 200).toBeLessThan(500); const loginUrl = new URL(page.url()); if (loginUrl.pathname !== "/login") { if (process.env.REQUIRE_E2E_READINESS === "1") { throw new Error(`Expected unauthenticated dashboard deep link to redirect to /login, got ${page.url()}`); } skipOrFailWhenE2eFixtureMissing(`Dashboard deep link did not redirect to login in this environment: ${page.url()}`); } expect(loginUrl.searchParams.get("redirectTo")).toBe(dashboardPath); await expect(page.locator('[data-ui-id="ui.auth.login.form"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); await page.locator('[data-ui-id="ui.auth.login.email"], input[type="email"], input[name="email"], input#email').first().fill(credentials!.email); await page .locator('[data-ui-id="ui.auth.login.password"], input[type="password"], input[name="password"], input#password') .first() .fill(credentials!.password); await Promise.all([page.waitForLoadState("domcontentloaded"), page.locator('[data-ui-id="ui.auth.login.submit"], button[type="submit"]').first().click()]); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(dashboardPath)}(?:[?#].*)?$`, "u"), { timeout: 15_000 }); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("guards seeded tenant account membership before dashboard and account smoke", async ({ page }) => { skipOrFailWhenE2eInputsMissing( ["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH", "E2E_TENANT_SETTINGS_ACCOUNT_PATH"], "Seeded tenant account membership guard inputs not configured" ); await loginAsTenantUser(page, credentials!); await expectSeededTenantAccountContext(page, "tenant login"); const dashboardResponse = await page.goto(dashboardPath, { waitUntil: "domcontentloaded" }); expect(dashboardResponse?.status() ?? 200).toBeLessThan(500); await expectSeededTenantAccountContext(page, `dashboard ${dashboardPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(dashboardPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expectDashboardNavLink(page, dashboardPath); const accountPath = tenantSettingsAccountPath(dashboardPath); const accountResponse = await page.goto(accountPath, { waitUntil: "domcontentloaded" }); expect(accountResponse?.status() ?? 200).toBeLessThan(500); await expectSeededTenantAccountContext(page, `account settings ${accountPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(accountPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.surface.shell.main"]').first()).toBeVisible(); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expectDashboardNavLink(page, dashboardPath); const accountNameInput = page.locator('[data-ui-id="ui.settings.account.name"], form input[name="name"]').first(); const accountSlugInput = page.locator('[data-ui-id="ui.settings.account.slug"], form input[name="slug"]').first(); const accountDeleteButton = page.locator('[data-ui-id="ui.settings.account.delete"]').first(); await expect(accountNameInput).toBeVisible(); await expect(accountSlugInput).toBeVisible(); await expect(accountDeleteButton).toBeVisible(); await expect(accountDeleteButton).toHaveAttribute("type", "button"); const currentName = (await accountNameInput.inputValue()).trim(); const currentSlug = (await accountSlugInput.inputValue()).trim(); expect(currentName, "seeded tenant account name should not be empty").not.toBe(""); expect(currentSlug, "seeded tenant account slug should not be empty").not.toBe(""); if (process.env.E2E_TENANT_ACCOUNT_NAME) { expect(currentName).toBe(process.env.E2E_TENANT_ACCOUNT_NAME); } if (process.env.E2E_TENANT_ACCOUNT_SLUG) { expect(currentSlug).toBe(process.env.E2E_TENANT_ACCOUNT_SLUG); } await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("keeps dashboard redirect in the mobile login auth shell without credentials", async ({ page }) => { const response = await page.goto(`/login?redirectTo=${encodeURIComponent(dashboardPath)}`, { waitUntil: "domcontentloaded" }); expect(response?.status() ?? 200).toBeLessThan(500); const form = page.locator('[data-ui-id="ui.auth.login.form"]').first(); await expect(form).toBeVisible(); await expect(form.locator('input[name="redirectTo"]').first()).toHaveValue(dashboardPath); await expect(form.locator('[data-ui-id="ui.auth.login.email"], input[type="email"], input[name="email"], input#email').first()).toBeVisible(); await expect(form.locator('[data-ui-id="ui.auth.login.password"], input[type="password"], input[name="password"], input#password').first()).toBeVisible(); await expect(form.locator('[data-ui-id="ui.auth.login.submit"], button[type="submit"]').first()).toBeEnabled(); const githubLink = page.locator('a[href^="/oauth/github/start?redirectTo="]').first(); if ((await githubLink.count()) > 0 && (await githubLink.isVisible())) { const href = await githubLink.getAttribute("href"); expect(new URL(href ?? "", "http://e2e.local").searchParams.get("redirectTo")).toBe(dashboardPath); } await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("keeps account settings and dashboard usable without mutating data", async ({ page }) => { skipOrFailWhenE2eInputsMissing( ["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH", "E2E_TENANT_SETTINGS_ACCOUNT_PATH", "E2E_TENANT_SETTINGS_PROFILE_PATH"], "Authenticated account dashboard smoke inputs not configured" ); await loginAsTenantUser(page, credentials!); const accountPath = tenantSettingsAccountPath(dashboardPath); const accountResponse = await page.goto(accountPath, { waitUntil: "domcontentloaded" }); expect(accountResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, accountResponse, `Account settings path ${accountPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(accountPath)}(?:[?#].*)?$`, "u")); await expect(page).not.toHaveURL(/\/login(?:[?#].*)?$/u); await expect(page.locator('[data-ui-id="ui.surface.shell.main"]').first()).toBeVisible(); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expect(page.getByRole("heading").first()).toBeVisible(); const accountNameInput = page.locator('[data-ui-id="ui.settings.account.name"], form input[name="name"]').first(); const accountSlugInput = page.locator('[data-ui-id="ui.settings.account.slug"], form input[name="slug"]').first(); await expect(accountNameInput).toBeVisible(); await expect(accountSlugInput).toBeVisible(); const currentName = (await accountNameInput.inputValue()).trim(); const currentSlug = (await accountSlugInput.inputValue()).trim(); if (process.env.E2E_TENANT_ACCOUNT_NAME) { expect(currentName).toBe(process.env.E2E_TENANT_ACCOUNT_NAME); } if (process.env.E2E_TENANT_ACCOUNT_SLUG) { expect(currentSlug).toBe(process.env.E2E_TENANT_ACCOUNT_SLUG); } const accountSubmit = await interceptCurrentRoutePost(page, { status: 200, body: "{}", contentType: "application/json", }); await page.locator('[data-ui-id="ui.settings.account.submit"], form button[type="submit"]').first().click(); await expect.poll(() => accountSubmit.value, { timeout: 5_000 }).not.toBeNull(); expect(postDataIncludesField(accountSubmit.value, "action", /^edit$/u)).toBe(true); expect(postDataIncludesField(accountSubmit.value, "csrf", /.+/u)).toBe(true); expect(postDataIncludesField(accountSubmit.value, "name", new RegExp(`^${escapeRegExp(currentName)}$`, "u"))).toBe(true); expect(postDataIncludesField(accountSubmit.value, "slug", new RegExp(`^${escapeRegExp(currentSlug)}$`, "u"))).toBe(true); await page.unroute("**/*"); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const profilePath = tenantSettingsProfilePath(dashboardPath); const profileResponse = await page.goto(profilePath, { waitUntil: "domcontentloaded" }); expect(profileResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, profileResponse, `Profile settings path ${profilePath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(profilePath)}(?:[?#].*)?$`, "u")); await expect(page).not.toHaveURL(/\/login(?:[?#].*)?$/u); await expect(page.locator('[data-ui-id="ui.surface.shell.main"]').first()).toBeVisible(); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.settings.profile.page"]').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.settings.profile.form"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const sidebarTrigger = page.locator('[data-ui-id="ui.action.shell.sidebarTrigger"]').first(); if ((await sidebarTrigger.count()) > 0 && (await sidebarTrigger.isVisible())) { await sidebarTrigger.click(); const mobileSidebar = page.locator('[data-mobile="true"]').first(); await expect(mobileSidebar).toBeVisible(); const dashboardLink = mobileSidebar.locator('[data-ui-id="ui.nav.app.dashboard"]').first(); await expect(dashboardLink).toBeVisible(); await dashboardLink.click(); } else { const dashboardResponse = await page.goto(dashboardPath, { waitUntil: "domcontentloaded" }); expect(dashboardResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, dashboardResponse, `Dashboard path ${dashboardPath}`); } await expect(page).toHaveURL(new RegExp(`${escapeRegExp(dashboardPath)}(?:[?#].*)?$`, "u")); await expect(page).not.toHaveURL(/\/login(?:[?#].*)?$/u); await expect(page.locator('[data-ui-id="ui.nav.app.dashboard"]').first()).toHaveAttribute("href", /\/dashboard(?:[?#].*)?$/u); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("keeps account dashboard subscription links tenant-scoped on mobile without Stripe", async ({ page }) => { skipOrFailWhenE2eInputsMissing( ["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH", "E2E_TENANT_SUBSCRIPTION_PATH"], "Authenticated account dashboard subscription scope inputs not configured" ); await failOnStripeNetworkRequests(page); await loginAsTenantUser(page, credentials!); const accountPath = tenantSettingsAccountPath(dashboardPath); const accountResponse = await page.goto(accountPath, { waitUntil: "domcontentloaded" }); expect(accountResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, accountResponse, `Account settings path ${accountPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(accountPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.settings.account.form"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const dashboardResponse = await page.goto(dashboardPath, { waitUntil: "domcontentloaded" }); expect(dashboardResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, dashboardResponse, `Dashboard path ${dashboardPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(dashboardPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); const subscriptionPath = process.env.E2E_TENANT_SUBSCRIPTION_PATH ?? tenantSettingsSubscriptionPath(dashboardPath); const subscriptionResponse = await page.goto(subscriptionPath, { waitUntil: "domcontentloaded" }); expect(subscriptionResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, subscriptionResponse, `Subscription settings path ${subscriptionPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(subscriptionPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.subscription.page"]').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.subscription.billing.portal"]').first()).toHaveAttribute("type", "button"); const checkoutLink = page.locator('[data-ui-id="ui.subscription.checkout.link"]').first(); if ((await checkoutLink.count()) > 0 && (await checkoutLink.isVisible())) { const checkoutHref = await checkoutLink.getAttribute("href"); expect(checkoutHref).not.toMatch(/stripe\.com|^https?:\/\//u); expect(new URL(checkoutHref ?? "", "http://e2e.local").pathname).toBe(`/subscribe/${tenantSlugFromSettingsPath(subscriptionPath)}`); } expect(page.url()).not.toMatch(/stripe\.com/u); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("navigates account to dashboard to subscription with mobile shell selectors without mutating data", async ({ page }) => { skipOrFailWhenE2eInputsMissing( ["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH", "E2E_TENANT_SUBSCRIPTION_PATH"], "Authenticated account-to-subscription mobile navigation inputs not configured" ); await failOnStripeNetworkRequests(page); await loginAsTenantUser(page, credentials!); const accountPath = tenantSettingsAccountPath(dashboardPath); const accountResponse = await page.goto(accountPath, { waitUntil: "domcontentloaded" }); expect(accountResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, accountResponse, `Account settings path ${accountPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(accountPath)}(?:[?#].*)?$`, "u")); const accountForm = page.locator('[data-ui-id="ui.settings.account.form"]').first(); await expect(accountForm).toBeVisible(); await expect(accountForm.locator('[data-ui-id="ui.settings.account.name"], input[name="name"]').first()).toBeVisible(); await expect(accountForm.locator('[data-ui-id="ui.settings.account.slug"], input[name="slug"]').first()).toBeVisible(); await expect(accountForm.locator('[data-ui-id="ui.settings.account.submit"], button[type="submit"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const mobileSidebar = page.locator('[data-ui-id="ui.surface.app.sidebar.mobile"], [data-mobile="true"]').first(); await expect(mobileSidebar).toBeHidden(); await page.locator('[data-ui-id="ui.action.shell.sidebarTrigger"]').first().click(); await expect(mobileSidebar).toBeVisible(); const dashboardLink = mobileSidebar.locator('[data-ui-id="ui.nav.app.dashboard"]').first(); await expect(dashboardLink).toBeVisible(); await dashboardLink.click(); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(dashboardPath)}(?:[?#].*)?$`, "u")); await expect(mobileSidebar).toBeHidden(); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); // The "more" overflow is a popover whose trigger may not have hydrated yet right // after the SPA navigation to the dashboard; a single click can no-op or open and // re-close. Retry-open until the subscription action mounts (only clicking while // it's hidden so we never toggle an open popover shut). const moreTrigger = page.locator('[data-ui-id="ui.action.shell.more"]').first(); const subscriptionAction = page.locator('[data-ui-id="ui.action.shell.subscription"]').first(); await expect(async () => { if (!(await subscriptionAction.isVisible())) { await moreTrigger.click(); } await expect(subscriptionAction).toBeVisible({ timeout: 2000 }); }).toPass({ timeout: 15000 }); const subscriptionPath = process.env.E2E_TENANT_SUBSCRIPTION_PATH ?? tenantSettingsSubscriptionPath(dashboardPath); const subscriptionLink = await findVisibleLinkByPath(page, '[data-ui-id="ui.action.shell.subscription"]', subscriptionPath); if (!subscriptionLink) { skipOrFailWhenE2eFixtureMissing("No mobile shell subscription settings link rendered for this fixture"); } await expect(subscriptionLink).toHaveAttribute("href", new RegExp(`${escapeRegExp(subscriptionPath)}(?:[?#].*)?$`, "u")); const subscriptionResponsePromise = page .waitForResponse((response) => new URL(response.url()).pathname === normalizePathname(subscriptionPath) && response.request().method() === "GET", { timeout: 5_000, }) .catch(() => null); await subscriptionLink.click(); const subscriptionResponse = await subscriptionResponsePromise; await skipIfUnavailable(page, subscriptionResponse, `Subscription settings path ${subscriptionPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(subscriptionPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.subscription.page"]').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.subscription.products"]').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.subscription.billing.portal"]').first()).toHaveAttribute("type", "button"); expect(page.url()).not.toMatch(/stripe\.com/u); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("replays new-account login redirects and returns to the dashboard on mobile", async ({ page, context }) => { skipOrFailWhenE2eInputsMissing( ["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"], "Authenticated new-account redirect replay inputs not configured" ); const newAccountPath = process.env.E2E_NEW_ACCOUNT_PATH ?? "/new-account"; await context.clearCookies(); await page.goto(`/login?redirectTo=${encodeURIComponent(newAccountPath)}`, { waitUntil: "domcontentloaded" }); const loginForm = page.locator('[data-ui-id="ui.auth.login.form"]').first(); await expect(loginForm).toBeVisible(); await expect(loginForm.locator('input[name="redirectTo"]').first()).toHaveValue(newAccountPath); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); await loginForm.locator('[data-ui-id="ui.auth.login.email"], input[type="email"], input[name="email"], input#email').first().fill(credentials!.email); await loginForm .locator('[data-ui-id="ui.auth.login.password"], input[type="password"], input[name="password"], input#password') .first() .fill(credentials!.password); await Promise.all([ page.waitForLoadState("domcontentloaded"), loginForm.locator('[data-ui-id="ui.auth.login.submit"], button[type="submit"]').first().click(), ]); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(newAccountPath)}(?:[?#].*)?$`, "u"), { timeout: 15_000 }); const form = page.locator('[data-ui-id="ui.account.create.form"]').first(); await expect(form).toBeVisible(); await expect(form.locator('[data-ui-id="ui.account.create.name"], input[name="name"]').first()).toBeVisible(); await expect(form.locator('input[name="action"][value="create"]').first()).toHaveCount(1); await expect(form.locator('input[name="csrf"]').first()).not.toHaveValue(""); await expect(form.locator('[data-ui-id="ui.account.create.submit"], button[type="submit"]').first()).toBeEnabled(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const dashboardResponse = await page.goto(dashboardPath, { waitUntil: "domcontentloaded" }); expect(dashboardResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, dashboardResponse, `Dashboard path ${dashboardPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(dashboardPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("keeps account deletion blocked and retryable when a subscription is active", async ({ page }) => { skipOrFailWhenE2eInputsMissing( ["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"], "Active subscription account deletion smoke inputs not configured" ); await loginAsTenantUser(page, credentials!); const accountPath = tenantSettingsAccountPath(dashboardPath); const accountResponse = await page.goto(accountPath, { waitUntil: "domcontentloaded" }); expect(accountResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, accountResponse, `Account settings path ${accountPath}`); const deleteButton = page.locator('[data-ui-id="ui.settings.account.delete"]').first(); if ((await deleteButton.count()) === 0 || !(await deleteButton.isVisible())) { skipOrFailWhenE2eFixtureMissing("No account deletion control rendered for this fixture"); } // Account delete is an RR7 single-fetch Form POST to `.data`; a raw JSON 400 // breaks the turbo-stream decoder. Use the single-fetch error envelope so the // failed-delete path resolves cleanly and the account stays put. const submittedPostData = await interceptCurrentRoutePost(page, singleFetchActionError("Cannot delete an account with active subscriptions.")); await deleteButton.click(); const dialog = page .locator('[role="alertdialog"]') .filter({ has: page.locator("button") }) .last(); await expect(dialog).toBeVisible(); await dialog.locator('[data-ui-id="ui.confirm.action"]').first().click(); await expect.poll(() => submittedPostData.value, { message: "account deletion POST payload was captured" }).not.toBeNull(); expect(postDataIncludesField(submittedPostData.value, "action", /^delete$/u)).toBe(true); expect(postDataIncludesField(submittedPostData.value, "csrf", /.+/u)).toBe(true); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(accountPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.settings.account.form"]').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.settings.account.delete"]').first()).toBeVisible(); await page.unroute("**/*"); const dashboardResponse = await page.goto(dashboardPath, { waitUntil: "domcontentloaded" }); expect(dashboardResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, dashboardResponse, `Dashboard path ${dashboardPath}`); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("posts the account creation contract on mobile without creating an account", async ({ page }) => { skipOrFailWhenE2eInputsMissing(["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD"], "Non-mutating account creation contract inputs not configured"); await loginAsTenantUser(page, credentials!); const newAccountPath = process.env.E2E_NEW_ACCOUNT_PATH ?? "/new-account"; const response = await page.goto(newAccountPath, { waitUntil: "domcontentloaded" }); expect(response?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, response, `New account path ${newAccountPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(newAccountPath)}(?:[?#].*)?$`, "u")); await expect(page).not.toHaveURL(/\/login(?:[?#].*)?$/u); const form = page.locator('[data-ui-id="ui.account.create.form"]').first(); const nameInput = form.locator('[data-ui-id="ui.account.create.name"], input[name="name"]').first(); const submitButton = form.locator('[data-ui-id="ui.account.create.submit"], button[type="submit"]').first(); await expect(form).toBeVisible(); await expect(nameInput).toBeVisible(); await expect(submitButton).toBeVisible(); const accountName = `E2E Contract ${Date.now()}`; await nameInput.fill(accountName); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const submitted = await interceptCurrentRoutePost(page, { status: 200, body: "Account creation intercepted", contentType: "text/html", }); await submitButton.click(); await expect.poll(() => submitted.value, { timeout: 5_000 }).not.toBeNull(); expect(postDataIncludesField(submitted.value, "action", /^create$/u)).toBe(true); expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true); expect(postDataIncludesField(submitted.value, "name", new RegExp(`^${escapeRegExp(accountName)}$`, "u"))).toBe(true); }); test("keeps account creation input retryable after server errors", async ({ page }) => { skipOrFailWhenE2eInputsMissing(["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD"], "Non-mutating account creation error recovery inputs not configured"); await loginAsTenantUser(page, credentials!); const newAccountPath = process.env.E2E_NEW_ACCOUNT_PATH ?? "/new-account"; const response = await page.goto(newAccountPath, { waitUntil: "domcontentloaded" }); expect(response?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, response, `New account path ${newAccountPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(newAccountPath)}(?:[?#].*)?$`, "u")); await expect(page).not.toHaveURL(/\/login(?:[?#].*)?$/u); const form = page.locator('[data-ui-id="ui.account.create.form"]').first(); const nameInput = form.locator('[data-ui-id="ui.account.create.name"], input[name="name"]').first(); const submitButton = form.locator('[data-ui-id="ui.account.create.submit"], button[type="submit"]').first(); await expect(form).toBeVisible(); await expect(nameInput).toBeVisible(); await expect(submitButton).toBeVisible(); const accountName = `E2E Retry ${Date.now()}`; await nameInput.fill(accountName); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const syntheticError = "E2E synthetic account creation failure"; const submitted = await interceptCurrentRoutePost(page, singleFetchActionError(syntheticError)); await submitButton.click(); await expect.poll(() => submitted.value, { timeout: 5_000 }).not.toBeNull(); expect(postDataIncludesField(submitted.value, "action", /^create$/u)).toBe(true); expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true); expect(postDataIncludesField(submitted.value, "name", new RegExp(`^${escapeRegExp(accountName)}$`, "u"))).toBe(true); await expect(form).toBeVisible(); await expect(nameInput).toHaveValue(accountName); // TenantNew surfaces the action error through the shared ErrorModal dialog, // which aria-hides the sibling inline alert — assert the dialog, then dismiss // it so the form is genuinely retryable and the a11y scan runs unobstructed. const errorDialog = page.getByRole("dialog").filter({ hasText: syntheticError }); await expect(errorDialog).toBeVisible(); await errorDialog.getByRole("button", { name: /close|schließen|schliessen/i }).first().click(); await expect(errorDialog).toBeHidden(); await expect(nameInput).toHaveValue(accountName); await expect(submitButton).toBeEnabled(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); test("can create a tenant account and reach its dashboard when explicitly enabled", async ({ page }) => { skipOrFailWhenE2eInputsMissing(["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD"], "Account creation flow inputs not configured"); skipOrFailWhenE2eOptInMissing("E2E_ALLOW_ACCOUNT_CREATE", "skipping mutating account creation flow"); await failOnStripeNetworkRequests(page); await loginAsTenantUser(page, credentials!); const newAccountPath = process.env.E2E_NEW_ACCOUNT_PATH ?? "/new-account"; const response = await page.goto(newAccountPath, { waitUntil: "domcontentloaded" }); expect(response?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, response, `New account path ${newAccountPath}`); await expect(page).not.toHaveURL(/\/login(?:[?#].*)?$/u); const uniqueName = `E2E Mobile ${Date.now()}`; await page.locator('[data-ui-id="ui.account.create.name"], form input[name="name"]').first().fill(uniqueName); await Promise.all([ page.waitForLoadState("domcontentloaded"), page.locator('[data-ui-id="ui.account.create.submit"], form button[type="submit"]').first().click(), ]); await expect(page).toHaveURL(/\/dashboard(?:[?#].*)?$/u, { timeout: 15_000 }); const createdDashboardPath = new URL(page.url()).pathname; await expectDashboardNavLink(page, createdDashboardPath); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const createdAccountPath = tenantSettingsAccountPath(createdDashboardPath); const accountResponse = await page.goto(createdAccountPath, { waitUntil: "domcontentloaded" }); expect(accountResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, accountResponse, `Created account settings path ${createdAccountPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(createdAccountPath)}(?:[?#].*)?$`, "u")); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.settings.account.name"], form input[name="name"]').first()).toHaveValue(uniqueName); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const dashboardResponse = await page.goto(createdDashboardPath, { waitUntil: "domcontentloaded" }); expect(dashboardResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, dashboardResponse, `Created dashboard path ${createdDashboardPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(createdDashboardPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expectDashboardNavLink(page, createdDashboardPath); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); await expectProvisionedSubscriptionPage(page, createdDashboardPath); }); test("can onboard a registered user with no tenant through account creation when explicitly enabled", async ({ page, context }) => { skipOrFailWhenE2eOptInMissing("E2E_ALLOW_NO_TENANT_ACCOUNT_CREATE", "skipping mutating no-tenant account creation flow"); skipOrFailWhenE2eInputsMissing(["E2E_NO_TENANT_EMAIL", "E2E_NO_TENANT_PASSWORD"], "No-tenant account creation flow inputs not configured"); await failOnStripeNetworkRequests(page); const noTenantCredentials = { email: process.env.E2E_NO_TENANT_EMAIL!, password: process.env.E2E_NO_TENANT_PASSWORD!, }; const newAccountPath = process.env.E2E_NEW_ACCOUNT_PATH ?? "/new-account"; await context.clearCookies(); await page.goto(`/login?redirectTo=${encodeURIComponent(newAccountPath)}`, { waitUntil: "domcontentloaded" }); await page.locator('[data-ui-id="ui.auth.login.email"], input[type="email"], input[name="email"], input#email').first().fill(noTenantCredentials.email); await page .locator('[data-ui-id="ui.auth.login.password"], input[type="password"], input[name="password"], input#password') .first() .fill(noTenantCredentials.password); await Promise.all([page.waitForLoadState("domcontentloaded"), page.locator('[data-ui-id="ui.auth.login.submit"], button[type="submit"]').first().click()]); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(newAccountPath)}(?:[?#].*)?$`, "u"), { timeout: 15_000 }); const form = page.locator('[data-ui-id="ui.account.create.form"]').first(); await expect(form).toBeVisible(); await expect(form.locator('[data-ui-id="ui.account.create.name"], input[name="name"]').first()).toBeVisible(); await expect(form.locator('input[name="action"][value="create"]').first()).toHaveCount(1); await expect(form.locator('input[name="csrf"]').first()).not.toHaveValue(""); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const uniqueName = `E2E No Tenant ${Date.now()}`; await form.locator('[data-ui-id="ui.account.create.name"], input[name="name"]').first().fill(uniqueName); await Promise.all([ page.waitForLoadState("domcontentloaded"), form.locator('[data-ui-id="ui.account.create.submit"], button[type="submit"]').first().click(), ]); await expect(page).toHaveURL(/\/dashboard(?:[?#].*)?$/u, { timeout: 15_000 }); const createdDashboardPath = new URL(page.url()).pathname; await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expectDashboardNavLink(page, createdDashboardPath); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const createdAccountPath = tenantSettingsAccountPath(createdDashboardPath); const accountResponse = await page.goto(createdAccountPath, { waitUntil: "domcontentloaded" }); expect(accountResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, accountResponse, `No-tenant created account settings path ${createdAccountPath}`); await expect(page.locator('[data-ui-id="ui.settings.account.name"], form input[name="name"]').first()).toHaveValue(uniqueName); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); }); async function expectProvisionedDashboardContinuity(page: Page, createdDashboardPath: string): Promise { await expect(page).toHaveURL(new RegExp(`${escapeRegExp(createdDashboardPath)}(?:[?#].*)?$`, "u")); await expectDashboardNavLink(page, createdDashboardPath); } async function expectSeededTenantAccountContext(page: Page, context: string): Promise { await expect(page, `${context} should stay in an authenticated tenant account context`).not.toHaveURL(/\/(?:login|new-account)(?:[?#].*)?$/u); await expect(page.locator('[data-ui-id="ui.account.create.form"]').first(), `${context} should not show account creation for the seeded tenant user`).toHaveCount(0); await expect(page.locator("body"), `${context} should not render a zero-account tenant state`).not.toContainText(zeroTenantAccountStatePattern); } async function expectProvisionedSettingsContinuity(page: Page, createdDashboardPath: string, expectedAccountName?: string): Promise { const accountPath = tenantSettingsAccountPath(createdDashboardPath); const accountResponse = await page.goto(accountPath, { waitUntil: "domcontentloaded" }); expect(accountResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, accountResponse, `Provisioned account settings path ${accountPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(accountPath)}(?:[?#].*)?$`, "u")); await expect(page).not.toHaveURL(/\/login(?:[?#].*)?$/u); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expectDashboardNavLink(page, createdDashboardPath); const accountNameInput = page.locator('[data-ui-id="ui.settings.account.name"], form input[name="name"]').first(); await expect(accountNameInput).toBeVisible(); if (expectedAccountName) { await expect(accountNameInput).toHaveValue(expectedAccountName); } await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const profilePath = tenantSettingsProfilePath(createdDashboardPath); const profileResponse = await page.goto(profilePath, { waitUntil: "domcontentloaded" }); expect(profileResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, profileResponse, `Provisioned profile settings path ${profilePath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(profilePath)}(?:[?#].*)?$`, "u")); await expect(page).not.toHaveURL(/\/login(?:[?#].*)?$/u); await expect(page.locator(appSidebarSelector).first()).toBeVisible(); await expectDashboardNavLink(page, createdDashboardPath); await expect(page.locator('[data-ui-id="ui.settings.profile.page"]').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.settings.profile.form"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); const dashboardResponse = await page.goto(createdDashboardPath, { waitUntil: "domcontentloaded" }); expect(dashboardResponse?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, dashboardResponse, `Provisioned dashboard path ${createdDashboardPath}`); await expect(page.locator('[data-ui-id="ui.dashboard.page"]').first()).toBeVisible(); await expectProvisionedDashboardContinuity(page, createdDashboardPath); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); } async function expectProvisionedSubscriptionPage(page: Page, createdDashboardPath: string): Promise { const subscriptionPath = tenantSettingsSubscriptionPath(createdDashboardPath); const response = await page.goto(subscriptionPath, { waitUntil: "domcontentloaded" }); expect(response?.status() ?? 200).toBeLessThan(500); await skipIfUnavailable(page, response, `Provisioned subscription settings path ${subscriptionPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(subscriptionPath)}(?:[?#].*)?$`, "u")); await expect(page).not.toHaveURL(/\/login(?:[?#].*)?$/u); await expect(page.locator('[data-ui-id="ui.subscription.page"]').first()).toBeVisible({ timeout: 10_000 }); await expectDashboardNavLink(page, createdDashboardPath); await expect(page.locator('[data-ui-id="ui.subscription.billing.portal"]').first()).toBeVisible(); const checkoutLink = page.locator('[data-ui-id="ui.subscription.checkout.link"]').first(); if ((await checkoutLink.count()) > 0 && (await checkoutLink.isVisible())) { await expect(checkoutLink).toHaveAttribute( "href", new RegExp(`\\/subscribe\\/${escapeRegExp(tenantSlugFromSettingsPath(subscriptionPath))}(?:[?#].*)?$`, "u") ); await expect(checkoutLink).not.toHaveAttribute("href", /stripe\.com|^https?:\/\//u); } expect(page.url()).not.toMatch(/stripe\.com/u); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); } function tenantSlugFromSettingsPath(path: string): string { const segments = path.split("/").filter(Boolean); const settingsIndex = segments.indexOf("settings"); return settingsIndex > 0 ? segments[settingsIndex - 1] : (segments.at(-1) ?? "app"); } async function findVisibleLinkByPath(page: Page, actionSelector: string, expectedPath: string) { // The action lives inside a Radix popover that mounts its content in a portal // after the trigger click; wait for it to attach before the one-shot scan so we // don't read zero links and false-trip the fixture guard. await page.locator(actionSelector).first().waitFor({ state: "visible", timeout: 3000 }).catch(() => undefined); const links = page.locator(`${actionSelector} >> xpath=ancestor::a[1]`); const expectedPathname = normalizePathname(expectedPath); const count = await links.count(); for (let index = 0; index < count; index += 1) { const link = links.nth(index); if (!(await link.isVisible())) continue; const href = await link.getAttribute("href"); if (href && new URL(href, page.url()).pathname === expectedPathname) { return link; } } return null; } function normalizePathname(pathOrUrl: string): string { return new URL(pathOrUrl, "http://e2e.local").pathname; } test.describe("registration compact mobile a11y", () => { test.use({ viewport: compactMobileViewport, isMobile: true, hasTouch: true }); test("keeps password requirements readable and announced at 320px without submitting", async ({ page }) => { await page.goto("/register", { waitUntil: "domcontentloaded" }); if (/\/login(?:[?#].*)?$/u.test(page.url())) { await expect(page.locator('[data-ui-id="ui.auth.login.email"], input[type="email"], input[name="email"], input#email').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); skipOrFailWhenE2eFixtureMissing("Registration redirects to login in this environment"); } const form = page.locator('[data-ui-id="ui.auth.register.form"]').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 passwordInput.count()) === 0 || !(await passwordInput.isVisible())) { skipOrFailWhenE2eFixtureMissing("Registration password input is not rendered in this environment"); } await expect(form).toBeVisible(); const requirements = page.locator('[data-ui-id="ui.auth.register.passwordRequirements"]').first(); await expect(requirements).toHaveAttribute("aria-live", "polite"); await expect(requirements).toHaveAccessibleName(/password requirements|passwort.*anforderungen|account\.register\.passwordRequirements\.label/i); // The number of requirements is driven by the server password policy (4 on // this environment), so assert a meaningful lower bound rather than a fixed 5. await expect.poll(() => requirements.locator("li").count()).toBeGreaterThanOrEqual(4); await expectPasswordRequirementsVisible(requirements); await passwordInput.fill("tiny"); await expectSomePasswordRequirementsMissing(requirements); await expectNoHorizontalOverflow(page); await passwordInput.fill("LongEnough1!"); await expectAllPasswordRequirementsMet(requirements); await expect(page.locator('[data-ui-id="ui.auth.register.submit"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); });