import { expect, test } from "./utils/test"; import { expectNoCriticalA11yViolations } from "./utils/axe"; import { getTenantCredentials, loginAsTenantUser, tenantSettingsMembersPath } from "./utils/auth"; import { compactMobileViewport, expectNoHorizontalOverflow, narrowMobileViewport } from "./utils/mobile"; import { escapeRegExp, interceptCurrentRoutePost, postDataIncludesField, skipIfUnavailable } from "./utils/navigation"; import { skipOrFailWhenE2eFixtureMissing, skipOrFailWhenE2eInputsMissing } from "./utils/readiness"; const credentials = getTenantCredentials(); const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH; const membersPath = process.env.E2E_TENANT_MEMBERS_PATH ?? (dashboardPath ? tenantSettingsMembersPath(dashboardPath) : undefined); test.describe("tenant members mobile a11y", () => { test.use({ isMobile: true, hasTouch: true }); test.beforeEach(() => { skipOrFailWhenE2eInputsMissing(["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"], "Tenant members E2E inputs not configured"); if (!membersPath) { skipOrFailWhenE2eFixtureMissing("Tenant members path could not be derived; set E2E_TENANT_MEMBERS_PATH"); } }); for (const viewport of [narrowMobileViewport, compactMobileViewport]) { test(`renders members table at ${viewport.width}px without overflow or critical a11y violations`, async ({ page }) => { await page.setViewportSize(viewport); await loginAsTenantUser(page, credentials!); const response = await page.goto(membersPath!, { waitUntil: "domcontentloaded" }); await skipIfUnavailable(page, response, `Tenant members path ${membersPath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(membersPath!)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.settings.members.page"]').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.settings.members.search"]').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.settings.members.table"]').first()).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); } test("submits new member invite contract with csrf without mutating data", async ({ page }) => { await page.setViewportSize(narrowMobileViewport); await loginAsTenantUser(page, credentials!); const response = await page.goto(`${membersPath!}/new`, { waitUntil: "domcontentloaded" }); await skipIfUnavailable(page, response, `Tenant new member path ${membersPath}/new`); const form = page.locator('[data-ui-id="ui.settings.members.new.form"]').first(); await expect(form).toBeVisible(); await form.locator('input[name="email"]').fill("e2e-invite-preview@example.test"); await form.locator('input[name="first-name"]').fill("E2E"); await form.locator('input[name="last-name"]').fill("Invite"); // "send invitation" is a Radix checkbox: the input[name] is a hidden form // proxy, so toggle it through its visible label instead of the hidden input. const inviteCheckbox = form.locator('input[name="send-invitation-email"]'); if (!(await inviteCheckbox.isChecked().catch(() => false))) { await form.locator('label[for="send-invitation-email"]').first().click(); } await expect(inviteCheckbox).toBeChecked(); const csrf = form.locator('input[name="csrf"]').first(); if ((await csrf.count()) > 0) { await expect(csrf).not.toHaveValue(""); } const submitted = await interceptCurrentRoutePost(page, { status: 204 }); await form.locator('button[type="submit"]').first().click(); await expect.poll(() => submitted.value).not.toBeNull(); expect(postDataIncludesField(submitted.value, "email", /^e2e-invite-preview@example\.test$/u)).toBe(true); expect(postDataIncludesField(submitted.value, "first-name", /^E2E$/u)).toBe(true); expect(postDataIncludesField(submitted.value, "last-name", /^Invite$/u)).toBe(true); expect(postDataIncludesField(submitted.value, "send-invitation-email", /^(on|true)$/u)).toBe(true); if ((await csrf.count()) > 0) { expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true); } }); });