227 lines
12 KiB
TypeScript
227 lines
12 KiB
TypeScript
import { expect, test, type Page } from "./utils/test";
|
|
import type { Response } from "@playwright/test";
|
|
import { getTenantCredentials, loginAsTenantUser } from "./utils/auth";
|
|
import { expectNoCriticalA11yViolations } from "./utils/axe";
|
|
import { compactMobileViewport, expectNoHorizontalOverflow } from "./utils/mobile";
|
|
import { failOnPaymentProviderNetworkRequests } from "./utils/navigation";
|
|
import { skipOrFailWhenE2eInputsMissing } from "./utils/readiness";
|
|
|
|
const credentials = getTenantCredentials();
|
|
const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH ?? "/app/dashboard";
|
|
const subscriptionPath = process.env.E2E_TENANT_SUBSCRIPTION_PATH ?? tenantPath("settings/billing");
|
|
const usagePath = process.env.E2E_TENANT_USAGE_PATH ?? tenantPath("settings/billing/usage");
|
|
const billingPath = process.env.E2E_TENANT_BILLING_PATH ?? tenantPath("settings/billing/invoices");
|
|
const checklistPath = process.env.E2E_TENANT_CHECKLIST_PATH ?? tenantPath("onboarding/checklist");
|
|
const demoDataPath = process.env.E2E_TENANT_DEMO_DATA_PATH ?? tenantPath("settings/workspace/demo-data");
|
|
|
|
test.describe("AK-P20 read-only billing and onboarding smoke", () => {
|
|
test.beforeEach(async ({ page }) => {
|
|
await failOnPaymentProviderNetworkRequests(page);
|
|
});
|
|
|
|
test("renders the AK-P20 subscription overview and current billing state", async ({ page }) => {
|
|
requireTenantLoginInputs("Subscription smoke inputs not configured");
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(subscriptionPath, { waitUntil: "domcontentloaded" });
|
|
expect(response?.ok(), `Subscription settings returned ${response?.status() ?? "no response"}`).toBe(true);
|
|
|
|
await expect(page.locator('[data-ui-id="ui.billing.selfServiceSubscription.page"]')).toBeVisible();
|
|
await expect(
|
|
page.locator('[data-ui-id="ui.billing.selfServiceSubscription.current"], [data-ui-id="ui.billing.selfServiceSubscription.current.empty"]').first()
|
|
).toBeVisible();
|
|
await expect(page.locator('a[href$="/settings/billing/invoices"]').first()).toBeVisible();
|
|
|
|
const cancel = page.locator('[data-ui-id="ui.billing.selfServiceSubscription.cancel"]').first();
|
|
if ((await cancel.count()) > 0 && (await cancel.isVisible())) {
|
|
await cancel.click();
|
|
await expect(page.locator('[data-ui-id="ui.billing.selfServiceSubscription.cancelDialog"]')).toBeVisible();
|
|
await page.keyboard.press("Escape");
|
|
await expect(page.locator('[data-ui-id="ui.billing.selfServiceSubscription.cancelDialog"]')).toBeHidden();
|
|
}
|
|
|
|
const emailPackage = page
|
|
.locator('[data-ui-id^="ui.billing.selfServiceSubscription.emailMarketing."]:not([disabled])')
|
|
.first();
|
|
if ((await emailPackage.count()) > 0 && (await emailPackage.isVisible())) {
|
|
await emailPackage.click();
|
|
const emailCheckout = page.locator('[data-ui-id="ui.billing.selfServiceSubscription.emailMarketing.dialog"]');
|
|
await expect(emailCheckout).toBeVisible();
|
|
await expect(
|
|
emailCheckout
|
|
.getByRole("radiogroup", { name: /Zahlungsart|Payment method/iu })
|
|
.or(emailCheckout.getByText(/sicheren Mollie-Checkout|secure Mollie checkout/iu))
|
|
).toBeVisible();
|
|
await emailCheckout.locator('[data-ui-id="ui.billing.selfServiceSubscription.emailMarketing.dialog.cancel"]').click();
|
|
await expect(emailCheckout).toBeHidden();
|
|
}
|
|
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
});
|
|
|
|
test("shows non-billable usage limits and Lago/Mollie invoice status", async ({ page }) => {
|
|
requireTenantLoginInputs("Billing settings smoke inputs not configured");
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const usageResponse = await page.goto(usagePath, { waitUntil: "domcontentloaded" });
|
|
expect(usageResponse?.ok(), `Usage settings returned ${usageResponse?.status() ?? "no response"}`).toBe(true);
|
|
await expect(page.locator('[data-ui-id="ui.billing.usage.page"]')).toBeVisible();
|
|
await expectUsageContent(page);
|
|
await expect(page.locator('[data-ui-id^="ui.subscription.checkout"]')).toHaveCount(0);
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
|
|
const billingResponse = await page.goto(billingPath, { waitUntil: "domcontentloaded" });
|
|
expect(billingResponse?.ok(), `Billing payment settings returned ${billingResponse?.status() ?? "no response"}`).toBe(true);
|
|
await expect(page.locator('[data-ui-id="ui.billing.payment.page"]')).toBeVisible();
|
|
await expectBillingContent(page);
|
|
await expect(page.locator('[data-ui-id^="ui.subscription.checkout"]')).toHaveCount(0);
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
});
|
|
|
|
test("opens the first-steps workflow and exposes its primary action", async ({ page }) => {
|
|
requireTenantLoginInputs("Onboarding checklist smoke inputs not configured");
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(checklistPath, { waitUntil: "domcontentloaded" });
|
|
expect(response?.ok(), `First-steps checklist returned ${response?.status() ?? "no response"}`).toBe(true);
|
|
await expect(page.locator('[data-ui-id="ui.onboarding.firstSteps.page"]')).toBeVisible();
|
|
|
|
const openAction = page.locator('[data-ui-id^="ui.onboarding.firstSteps.open."]').first();
|
|
await expect(openAction).toBeVisible();
|
|
await expect(openAction).toHaveAttribute("type", "button");
|
|
await openAction.click();
|
|
await expect(page).toHaveURL(/\/settings\/profile\/?(?:\?.*)?$/u);
|
|
await expect(page.locator('[data-ui-id="ui.settings.profile.page"]')).toBeVisible();
|
|
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
});
|
|
|
|
test("keeps the environment-gated demo-data surface explicit", async ({ page }) => {
|
|
requireTenantLoginInputs("Demo-data smoke inputs not configured");
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(demoDataPath, { waitUntil: "domcontentloaded" });
|
|
await skipIfDemoEnvironmentUnavailable(page, response, "Demo-data settings path is intentionally unavailable in this environment");
|
|
await expect(page.locator('[data-ui-id="ui.onboarding.demoData.page"]')).toBeVisible();
|
|
|
|
const create = page.locator('[data-ui-id="ui.onboarding.demoData.create"]');
|
|
const remove = page.locator('[data-ui-id="ui.onboarding.demoData.delete"]');
|
|
if (await create.isVisible()) {
|
|
await create.click();
|
|
await expect(remove).toBeVisible();
|
|
await expect(page.locator('[data-ui-id="ui.onboarding.demoData.summary"]')).toBeVisible();
|
|
} else {
|
|
await expect(remove).toBeVisible();
|
|
await remove.click();
|
|
const confirmation = page.getByRole("alertdialog");
|
|
await expect(confirmation).toBeVisible();
|
|
await confirmation.getByRole("button", { name: /Abbrechen|Cancel/iu }).click();
|
|
await expect(confirmation).toBeHidden();
|
|
}
|
|
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
});
|
|
});
|
|
|
|
test.describe("AK-P20 compact mobile smoke", () => {
|
|
test.use({ viewport: compactMobileViewport, isMobile: true, hasTouch: true });
|
|
|
|
test("keeps subscription, usage, billing, and checklist readable at 320px", async ({ page }) => {
|
|
requireTenantLoginInputs("AK-P20 compact mobile inputs not configured");
|
|
await failOnPaymentProviderNetworkRequests(page);
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
for (const [path, uiId] of [
|
|
[subscriptionPath, "ui.billing.selfServiceSubscription"],
|
|
[usagePath, "ui.billing.usage.page"],
|
|
[billingPath, "ui.billing.payment.page"],
|
|
[checklistPath, "ui.onboarding.firstSteps.page"],
|
|
] as const) {
|
|
const response = await page.goto(path, { waitUntil: "domcontentloaded" });
|
|
expect(response?.ok(), `AK-P20 path ${path} returned ${response?.status() ?? "no response"}`).toBe(true);
|
|
const locator =
|
|
uiId === "ui.billing.selfServiceSubscription"
|
|
? page.locator('[data-ui-id="ui.billing.selfServiceSubscription.page"]').first()
|
|
: page.locator(`[data-ui-id="${uiId}"]`);
|
|
await expect(locator).toBeVisible();
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
}
|
|
});
|
|
|
|
test("keeps the environment-gated demo-data screen readable at 320px", async ({ page }) => {
|
|
requireTenantLoginInputs("AK-P20 mobile demo-data inputs not configured");
|
|
await failOnPaymentProviderNetworkRequests(page);
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(demoDataPath, { waitUntil: "domcontentloaded" });
|
|
await skipIfDemoEnvironmentUnavailable(page, response, "Demo-data settings path is intentionally unavailable in this environment");
|
|
await expect(page.locator('[data-ui-id="ui.onboarding.demoData.page"]')).toBeVisible();
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
});
|
|
});
|
|
|
|
async function expectUsageContent(page: Page): Promise<void> {
|
|
const automationMetric = page.getByText(/^(Automationsläufe|Automation runs)$/iu).first();
|
|
const emptyState = page.getByText(/^(Noch keine Nutzung vorhanden|No usage yet)$/iu).first();
|
|
await expect(automationMetric.or(emptyState)).toBeVisible();
|
|
if (await automationMetric.isVisible()) {
|
|
await expect(page.getByText(/^(Speicher|Storage)$/iu).first()).toBeVisible();
|
|
}
|
|
}
|
|
|
|
async function expectBillingContent(page: Page): Promise<void> {
|
|
const invoiceHistory = page.getByText(/^(Rechnungsverlauf|Invoice history)$/iu).first();
|
|
const emptyState = page.getByText(/^(Noch keine Rechnungen|No invoices yet)$/iu).first();
|
|
await expect(invoiceHistory.or(emptyState)).toBeVisible();
|
|
if (await invoiceHistory.isVisible()) {
|
|
await expect(page.getByText(/^(Rechnungsstatus|Invoice status)$/iu).first()).toBeVisible();
|
|
await expect(page.getByText(/^(Mollie-Zahlung|Mollie payment)$/iu).first()).toBeVisible();
|
|
}
|
|
}
|
|
|
|
async function skipIfDemoEnvironmentUnavailable(page: Page, response: Response | null, reason: string): Promise<void> {
|
|
const currentPath = new URL(page.url()).pathname;
|
|
if (/\/login\/?$/u.test(currentPath)) {
|
|
if (process.env.REQUIRE_E2E_READINESS === "1") {
|
|
throw new Error(`${reason}: redirected to login while REQUIRE_E2E_READINESS=1`);
|
|
}
|
|
test.skip(true, `${reason}: redirected to login`);
|
|
return;
|
|
}
|
|
|
|
const responseStatus = response?.status() ?? 0;
|
|
const bodyStatus = Number(await page.evaluate(() => document.body.dataset.statusCode ?? ""));
|
|
const effectiveStatus = bodyStatus || responseStatus;
|
|
const expectedPath = new URL(demoDataPath, "http://e2e.local").pathname;
|
|
if (effectiveStatus === 404 && currentPath === expectedPath) {
|
|
if (process.env.REQUIRE_E2E_READINESS === "1") {
|
|
throw new Error(`${reason}: returned 404 while REQUIRE_E2E_READINESS=1`);
|
|
}
|
|
test.skip(true, `${reason}: returned the expected environment 404`);
|
|
return;
|
|
}
|
|
|
|
expect(effectiveStatus, `${reason}: unexpected response status`).not.toBe(400);
|
|
expect(effectiveStatus, `${reason}: permission denied`).not.toBe(403);
|
|
expect(effectiveStatus, `${reason}: unexpected error response`).toBeLessThan(400);
|
|
expect(response?.ok(), `${reason}: returned ${effectiveStatus || "no response"}`).toBe(true);
|
|
}
|
|
|
|
function requireTenantLoginInputs(reason: string): void {
|
|
skipOrFailWhenE2eInputsMissing(["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"], reason);
|
|
}
|
|
|
|
function tenantPath(path: string): string {
|
|
const normalizedDashboard = dashboardPath.startsWith("/") ? dashboardPath : `/${dashboardPath}`;
|
|
const marker = "/dashboard";
|
|
const tenantBase = normalizedDashboard.endsWith(marker) ? normalizedDashboard.slice(0, -marker.length) : "/app";
|
|
return `${tenantBase}/${path}`;
|
|
}
|