import { expect, test } from "./utils/test"; import { expectNoCriticalA11yViolations } from "./utils/axe"; import { getTenantCredentials, loginAsTenantUser, tenantRolesAndPermissionsPath, 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"; // R-P2b (D-P2 Admin RBAC): one merged "Rollen und Berechtigungen" tab (S02); // role assignment happens inline in the members list (D01 dropdown) instead of // the old users matrix (route redirects to settings/members). const credentials = getTenantCredentials(); const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH; const rolesAndPermissionsPath = process.env.E2E_TENANT_ROLES_AND_PERMISSIONS_PATH ?? (dashboardPath ? tenantRolesAndPermissionsPath(dashboardPath) : undefined); const membersPath = process.env.E2E_TENANT_MEMBERS_PATH ?? (dashboardPath ? tenantSettingsMembersPath(dashboardPath) : undefined); test.describe("tenant roles and permissions mobile a11y", () => { test.use({ isMobile: true, hasTouch: true }); test.beforeEach(() => { skipOrFailWhenE2eInputsMissing( ["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"], "Tenant roles and permissions mobile E2E inputs not configured" ); if (!rolesAndPermissionsPath) { skipOrFailWhenE2eFixtureMissing("Tenant roles and permissions path could not be derived; set E2E_TENANT_ROLES_AND_PERMISSIONS_PATH"); } }); for (const viewport of [narrowMobileViewport, compactMobileViewport]) { test(`keeps the merged roles tab usable at ${viewport.width}px`, async ({ page }) => { await page.setViewportSize(viewport); await loginAsTenantUser(page, credentials!); const response = await page.goto(rolesAndPermissionsPath!, { waitUntil: "domcontentloaded" }); await skipIfUnavailable(page, response, `Tenant roles and permissions path ${rolesAndPermissionsPath}`); const rolesPath = `${rolesAndPermissionsPath}/roles`; // Index redirects into the merged S02 roles tab. await expect(page).toHaveURL(new RegExp(`${escapeRegExp(rolesPath)}(?:[?#].*)?$`, "u")); await expect(page.locator('[data-ui-id="ui.settings.rolesAndPermissions.page"]').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.settings.rolesAndPermissions.roles"] table').first()).toBeVisible(); await expect(page.locator('[data-ui-id="ui.settings.rolesAndPermissions.roles.filter"]').first()).toBeVisible(); // The "new role" control is permission-gated and may not render for this // fixture; assert it only when present (matches the desktop spec's scope). const rolesNew = page.locator('[data-ui-id="ui.settings.rolesAndPermissions.roles.new"]').first(); if ((await rolesNew.count()) > 0) { await expect(rolesNew).toBeVisible(); } await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); // Legacy permissions sub-tab redirects into the merged roles tab. await page.goto(`${rolesAndPermissionsPath}/permissions`, { waitUntil: "domcontentloaded" }); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(rolesPath)}(?:[?#].*)?$`, "u")); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); } test("submits the inline role toggle contract (D01) without mutating fixture data", async ({ page }) => { await page.setViewportSize(narrowMobileViewport); await loginAsTenantUser(page, credentials!); if (!membersPath) { skipOrFailWhenE2eFixtureMissing("Tenant members path could not be derived; set E2E_TENANT_MEMBERS_PATH"); } // The old users matrix redirects to the members list; D01 lives there now. const response = await page.goto(`${rolesAndPermissionsPath}/users`, { waitUntil: "domcontentloaded" }); await skipIfUnavailable(page, response, `Tenant roles users path ${rolesAndPermissionsPath}/users`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(membersPath!)}(?:[?#].*)?$`, "u")); const roleDropdown = page.locator('[data-ui-id="ui.settings.members.roleDropdown"]').first(); if ((await roleDropdown.count()) === 0 || !(await roleDropdown.isVisible())) { skipOrFailWhenE2eFixtureMissing("Tenant members fixture has no editable role dropdown for mobile contract coverage"); } await roleDropdown.tap(); const roleCheckbox = page.getByRole("checkbox").first(); if ((await roleCheckbox.count()) === 0) { skipOrFailWhenE2eFixtureMissing("Tenant members fixture exposes no assignable roles for mobile contract coverage"); } const submitted = await interceptCurrentRoutePost(page, { status: 204 }); await roleCheckbox.tap(); await expect.poll(() => submitted.value, { message: "role toggle POST payload was captured" }).not.toBeNull(); expect(postDataIncludesField(submitted.value, "action", /^edit$/u)).toBe(true); expect(postDataIncludesField(submitted.value, "user-id", /.+/u)).toBe(true); expect(postDataIncludesField(submitted.value, "role-id", /.+/u)).toBe(true); expect(postDataIncludesField(submitted.value, "add", /^(true|false)$/u)).toBe(true); expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true); }); });