Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/tests/e2e/tenant-roles-permissions.mobile-a11y.spec.ts
T

102 lines
5.6 KiB
TypeScript

import { expect, test } from "./utils/test";
import { expectNoCriticalA11yViolations } from "./utils/axe";
import {
getTenantCredentials,
loginAsTenantUser,
tenantLegacyRolesAndPermissionsPath,
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/team).
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 legacyRolesAndPermissionsPath = dashboardPath ? tenantLegacyRolesAndPermissionsPath(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 || !legacyRolesAndPermissionsPath) {
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}`);
// The helper resolves directly to the canonical Team-Hub roles tab.
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(rolesAndPermissionsPath!)}(?:[?#].*)?$`, "u"));
await expect(page.locator('[data-ui-id="ui.settings.hub.team"]').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(`${legacyRolesAndPermissionsPath}/permissions`, { waitUntil: "domcontentloaded" });
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(rolesAndPermissionsPath!)}(?:[?#].*)?$`, "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(`${legacyRolesAndPermissionsPath}/users`, { waitUntil: "domcontentloaded" });
await skipIfUnavailable(page, response, `Tenant roles users path ${legacyRolesAndPermissionsPath}/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);
});
});