import { expect, test } from "./utils/test"; import { expectNoCriticalA11yViolations } from "./utils/axe"; import { getTenantCredentials, loginAsTenantUser } from "./utils/auth"; import { expectNoHorizontalOverflow, narrowMobileViewport } from "./utils/mobile"; import { escapeRegExp, skipIfUnavailable } from "./utils/navigation"; import { skipOrFailWhenE2eInputsMissing } from "./utils/readiness"; const credentials = getTenantCredentials(); const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH; const aiUsagePath = process.env.E2E_TENANT_AI_USAGE_PATH ?? deriveAiUsagePath(dashboardPath); test.describe("tenant AI usage mobile a11y", () => { test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true }); test.beforeEach(() => { skipOrFailWhenE2eInputsMissing(["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"], "Tenant AI usage E2E inputs not configured"); }); test("renders quota and forecast without mobile overflow or critical a11y violations", async ({ page }) => { await loginAsTenantUser(page, credentials!); const response = await page.goto(aiUsagePath!, { waitUntil: "domcontentloaded" }); await skipIfUnavailable(page, response, `Tenant AI usage path ${aiUsagePath}`); await expect(page).toHaveURL(new RegExp(`${escapeRegExp(aiUsagePath!)}(?:[?#].*)?$`, "u")); await expect(page.locator("main").first()).toBeVisible(); await expect(page.getByRole("progressbar", { name: /AI quota usage|KI.*Nutzung/i })).toBeVisible(); await expect(page.getByRole("heading", { name: /End-of-month forecast|Prognose/i })).toBeVisible(); await expectNoHorizontalOverflow(page); await expectNoCriticalA11yViolations(page); }); }); function deriveAiUsagePath(path: string | undefined): string | undefined { if (!path) return undefined; const normalized = path.startsWith("/") ? path : `/${path}`; return normalized.endsWith("/dashboard") ? normalized.replace(/\/dashboard$/u, "/settings/ai-usage") : undefined; }