101 lines
4.8 KiB
TypeScript
101 lines
4.8 KiB
TypeScript
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, interceptCurrentRoutePost, postDataIncludesField, skipIfUnavailable } from "./utils/navigation";
|
|
import { skipOrFailWhenE2eFixtureMissing, skipOrFailWhenE2eInputsMissing } from "./utils/readiness";
|
|
|
|
const credentials = getTenantCredentials();
|
|
const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH;
|
|
const privacyPath = process.env.E2E_TENANT_PRIVACY_PATH ?? derivePrivacyPath(dashboardPath);
|
|
|
|
test.describe("privacy self-service mobile a11y", () => {
|
|
test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true });
|
|
|
|
test.beforeEach(() => {
|
|
skipOrFailWhenE2eInputsMissing(
|
|
["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"],
|
|
"Tenant privacy self-service E2E inputs not configured"
|
|
);
|
|
if (!privacyPath) {
|
|
skipOrFailWhenE2eFixtureMissing("Tenant privacy path could not be derived; set E2E_TENANT_PRIVACY_PATH");
|
|
}
|
|
});
|
|
|
|
test("renders export and deletion controls without mobile overflow or critical a11y violations", async ({ page }) => {
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(privacyPath!, { waitUntil: "domcontentloaded" });
|
|
await skipIfUnavailable(page, response, `Tenant privacy path ${privacyPath}`);
|
|
|
|
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(privacyPath!)}(?:[?#].*)?$`, "u"));
|
|
await expect(page.locator('[data-ui-id="ui.settings.privacy.page"]').first()).toBeVisible();
|
|
await expect(page.locator('[data-ui-id="ui.settings.privacy.export.form"]').first()).toBeVisible();
|
|
|
|
const deleteForm = page.locator('[data-ui-id="ui.settings.privacy.delete.form"]').first();
|
|
const reactivateForm = page.locator('[data-ui-id="ui.settings.privacy.reactivate.form"]').first();
|
|
await expect.poll(async () => (await deleteForm.count()) + (await reactivateForm.count())).toBeGreaterThan(0);
|
|
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
});
|
|
|
|
test("submits export request with intent and csrf without mutating data", async ({ page }) => {
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(privacyPath!, { waitUntil: "domcontentloaded" });
|
|
await skipIfUnavailable(page, response, `Tenant privacy path ${privacyPath}`);
|
|
|
|
const exportForm = page.locator('[data-ui-id="ui.settings.privacy.export.form"]').first();
|
|
await expect(exportForm).toBeVisible();
|
|
const csrf = exportForm.locator('input[name="csrf"]').first();
|
|
if ((await csrf.count()) > 0) {
|
|
await expect(csrf).not.toHaveValue("");
|
|
}
|
|
|
|
const submitted = await interceptCurrentRoutePost(page, { status: 204 });
|
|
await exportForm.locator('button[type="submit"]').first().click();
|
|
|
|
await expect.poll(() => submitted.value).not.toBeNull();
|
|
expect(postDataIncludesField(submitted.value, "intent", /^export$/u)).toBe(true);
|
|
if ((await csrf.count()) > 0) {
|
|
expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true);
|
|
}
|
|
});
|
|
|
|
test("submits deletion request with confirmation, intent and csrf without mutating data", async ({ page }) => {
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const response = await page.goto(privacyPath!, { waitUntil: "domcontentloaded" });
|
|
await skipIfUnavailable(page, response, `Tenant privacy path ${privacyPath}`);
|
|
|
|
const deleteForm = page.locator('[data-ui-id="ui.settings.privacy.delete.form"]').first();
|
|
if ((await deleteForm.count()) === 0) {
|
|
skipOrFailWhenE2eFixtureMissing("Privacy delete form is not visible because the user is already pending deletion");
|
|
}
|
|
await expect(deleteForm).toBeVisible();
|
|
|
|
const csrf = deleteForm.locator('input[name="csrf"]').first();
|
|
if ((await csrf.count()) > 0) {
|
|
await expect(csrf).not.toHaveValue("");
|
|
}
|
|
|
|
await deleteForm.locator('input[name="confirmation"]').fill("DELETE");
|
|
const submitted = await interceptCurrentRoutePost(page, { status: 204 });
|
|
await deleteForm.locator('button[type="submit"]').first().click();
|
|
|
|
await expect.poll(() => submitted.value).not.toBeNull();
|
|
expect(postDataIncludesField(submitted.value, "intent", /^delete$/u)).toBe(true);
|
|
expect(postDataIncludesField(submitted.value, "confirmation", /^DELETE$/u)).toBe(true);
|
|
if ((await csrf.count()) > 0) {
|
|
expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true);
|
|
}
|
|
});
|
|
});
|
|
|
|
function derivePrivacyPath(path: string | undefined): string | undefined {
|
|
if (!path) return undefined;
|
|
const normalized = path.startsWith("/") ? path : `/${path}`;
|
|
return normalized.endsWith("/dashboard") ? normalized.replace(/\/dashboard$/u, "/settings/profile/data") : undefined;
|
|
}
|