Files
HiveGrid-Wireframes/03 Quellen und Referenzen/hivegrid-cloud/tests/e2e/readiness-golden-path.mobile-a11y.spec.ts
T

195 lines
8.2 KiB
TypeScript

import { expect, test, type Locator, type Page } from "./utils/test";
import { expectNoCriticalA11yViolations } from "./utils/axe";
import { getTenantCredentials, loginAsTenantUser } from "./utils/auth";
import { expectNoHorizontalOverflow, narrowMobileViewport } from "./utils/mobile";
import { escapeRegExp, failOnPaymentProviderNetworkRequests, skipIfUnavailable } from "./utils/navigation";
import { skipOrFailWhenE2eFixtureMissing, skipOrFailWhenE2eInputsMissing } from "./utils/readiness";
const credentials = getTenantCredentials();
const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH;
const subscriptionPath = process.env.E2E_TENANT_SUBSCRIPTION_PATH;
const pluginSettingsPath = process.env.E2E_PLUGIN_SETTINGS_PATH;
test.describe("readiness golden path mobile a11y", () => {
test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true });
test.beforeEach(async ({ page }) => {
await failOnPaymentProviderNetworkRequests(page);
});
test("navigates authenticated mobile readiness surfaces without mutations", async ({ page }) => {
skipOrFailWhenE2eInputsMissing(
[
"E2E_TENANT_EMAIL",
"E2E_TENANT_PASSWORD",
"E2E_TENANT_DASHBOARD_PATH",
"E2E_TENANT_SUBSCRIPTION_PATH",
"E2E_PLUGIN_SETTINGS_PATH",
],
"Readiness golden path inputs not configured"
);
await loginAsTenantUser(page, credentials!);
const dashboardResponse = await page.goto(dashboardPath!, { waitUntil: "domcontentloaded" });
await skipIfUnavailable(page, dashboardResponse, `Tenant dashboard path ${dashboardPath}`);
await expect(page).toHaveURL(pathPattern(dashboardPath!));
await expect(page.locator('[data-ui-id="ui.action.shell.sidebarTrigger"]').first()).toBeVisible();
await expectReadinessPage(page);
const mobileSidebar = page.locator('[data-ui-id="ui.surface.app.sidebar"]').first();
await expect(mobileSidebar).toHaveAttribute("aria-hidden", "true");
await page.locator('[data-ui-id="ui.action.shell.sidebarTrigger"]').first().click();
await expect(mobileSidebar).not.toHaveAttribute("aria-hidden", "true");
await clickAndExpectPath(mobileSidebar.locator('[data-ui-id="ui.nav.app.settings"]').first(), page, /\/settings\/profile(?:[?#].*)?$/u);
await expect(mobileSidebar).toHaveAttribute("aria-hidden", "true");
await expectReadinessPage(page);
await clickVisibleLinkToPath(page, subscriptionPath!, "Subscription settings link");
await expect(page.locator('[data-ui-id^="ui.billing.selfServiceSubscription."]').first()).toBeVisible({ timeout: 10_000 });
await expectReadinessPage(page);
await expect(page.locator('[data-ui-id="ui.billing.selfServiceSubscription.builder"]').first()).toBeVisible({ timeout: 10_000 });
await expect(page.locator('[data-ui-id="ui.billing.selfServiceSubscription.preview"]').first()).toBeVisible({ timeout: 10_000 });
await clickVisibleLinkToPath(page, pluginSettingsPath!, "Plugin settings link");
await expect(page.locator('[data-ui-id="ui.plugins.page"]').first()).toBeVisible({ timeout: 10_000 });
await expectReadinessPage(page);
});
});
async function expectReadinessPage(page: Page): Promise<void> {
await expectNoHorizontalOverflow(page);
await expectNoCriticalA11yViolations(page);
}
async function clickVisibleLinkToPath(page: Page, path: string, label: string): Promise<void> {
if (await tryClickVisibleLinkToPath(page, path)) {
return;
}
// On mobile the account/settings shortcuts (e.g. the subscription link) collapse
// into the shell "more" overflow popover, which mounts its links in a portal on
// open. Open it and retry before declaring the link missing.
const moreMenu = page.locator('[data-ui-id="ui.action.shell.more"]').first();
if (await isVisible(moreMenu)) {
await moreMenu.click();
await page
.locator(`a[href="${path}"]`)
.first()
.waitFor({ state: "visible", timeout: 3000 })
.catch(() => undefined);
if (await tryClickVisibleLinkToPath(page, path)) {
return;
}
await page.keyboard.press("Escape").catch(() => undefined);
}
// On mobile the settings sub-nav (Profile/Subscription/Plugins/…) collapses into a
// section <Select> combobox that navigates on choose; the desktop <a> links are
// display:hidden. Drive the combobox by the target section's label.
if (await trySelectSettingsTabToPath(page, path)) {
return;
}
// Cross-section settings links are intentionally absent from each section's
// local tab bar. Return to the canonical settings hub and use its card link,
// matching the user-visible navigation hierarchy.
const settingsMarker = "/settings/";
const settingsIndex = path.indexOf(settingsMarker);
if (settingsIndex >= 0) {
const hubSegment = path.slice(settingsIndex + settingsMarker.length).split("/")[0];
const settingsHubPath = `${path.slice(0, settingsIndex)}${settingsMarker}${hubSegment}`;
await page.goto(settingsHubPath, { waitUntil: "domcontentloaded" });
if (new URL(page.url()).pathname === path.split("?")[0]) {
return;
}
if (await tryClickVisibleLinkToPath(page, path)) {
return;
}
}
skipOrFailWhenE2eFixtureMissing(`${label} was not rendered for ${path}`);
}
async function trySelectSettingsTabToPath(page: Page, path: string): Promise<boolean> {
const combobox = page.getByRole("combobox", { name: /Select\.\.\.|Tab navigation/i }).first();
if (!(await isVisible(combobox))) {
return false;
}
const pathname = path.split("?")[0].replace(/\/+$/u, "");
const settingsMarker = "/settings/";
const settingsIndex = pathname.indexOf(settingsMarker);
const settingsSegments = settingsIndex >= 0 ? pathname.slice(settingsIndex + settingsMarker.length).split("/") : [];
if (settingsSegments.length === 0) {
return false;
}
const hubSegment = settingsSegments[0]!;
const optionName =
{
billing: /Billing|Abrechnung/i,
integrations: /Extensions|Erweiterungen|Integrationen/i,
profile: /My account|Mein Konto/i,
workspace: /Workspace|Arbeitsbereich/i,
compliance: /Compliance|Datenschutz/i,
team: /Team/i,
}[hubSegment] ??
new RegExp(
hubSegment
.split("-")
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
.join(" "),
"i"
);
await combobox.click();
const option = page.getByRole("option", { name: optionName }).first();
if (!(await isVisible(option))) {
await page.keyboard.press("Escape").catch(() => undefined);
return false;
}
const hubPath = `${pathname.slice(0, settingsIndex)}${settingsMarker}${hubSegment}`;
await Promise.all([page.waitForURL((url) => url.pathname === hubPath || url.pathname.startsWith(`${hubPath}/`)), option.click()]);
if (new URL(page.url()).pathname === pathname) return true;
return tryClickVisibleLinkToPath(page, path);
}
async function tryClickVisibleLinkToPath(page: Page, path: string): Promise<boolean> {
const links = page.locator("a[href]");
// Snapshot every href in a single evaluateAll so a streaming surface (e.g. the
// workflow-engine SSE list) re-rendering mid-scan can't make per-node
// getAttribute calls hang on a detached node.
const hrefs = await links.evaluateAll((els) => els.map((el) => el.getAttribute("href")));
for (let index = 0; index < hrefs.length; index += 1) {
if (!hrefMatchesPath(hrefs[index], path)) {
continue;
}
const link = links.nth(index);
if (await link.isVisible()) {
await clickAndExpectPath(link, page, pathPattern(path));
return true;
}
}
return false;
}
async function clickAndExpectPath(locator: Locator, page: Page, expectedUrl: RegExp): Promise<void> {
await expect(locator).toBeVisible();
await Promise.all([page.waitForURL(expectedUrl), locator.click()]);
}
async function isVisible(locator: Locator): Promise<boolean> {
return (await locator.count()) > 0 && (await locator.isVisible());
}
function hrefMatchesPath(href: string | null, path: string): boolean {
if (!href) return false;
if (href === path) return true;
try {
const url = new URL(href, "http://e2e.local");
return `${url.pathname}${url.search}` === path || url.pathname === path;
} catch {
return false;
}
}
function pathPattern(path: string): RegExp {
return new RegExp(`${escapeRegExp(path)}(?:[?#].*)?$`, "u");
}