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

74 lines
3.8 KiB
TypeScript

import { expect, test } from "./utils/test";
import { expectNoCriticalA11yViolations } from "./utils/axe";
import { getTenantCredentials, loginAsTenantUser, tenantSettingsNotificationsPath } 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 notificationsPath =
process.env.E2E_TENANT_NOTIFICATIONS_PATH ?? (dashboardPath ? tenantSettingsNotificationsPath(dashboardPath) : undefined);
test.describe("tenant notification settings mobile a11y", () => {
test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true });
test.beforeEach(() => {
skipOrFailWhenE2eInputsMissing(
["E2E_TENANT_EMAIL", "E2E_TENANT_PASSWORD", "E2E_TENANT_DASHBOARD_PATH"],
"Tenant notification settings E2E inputs not configured"
);
if (!notificationsPath) {
skipOrFailWhenE2eFixtureMissing("Tenant notification settings path could not be derived; set E2E_TENANT_NOTIFICATIONS_PATH");
}
});
test("renders notification categories without mobile overflow or critical a11y violations", async ({ page }) => {
await loginAsTenantUser(page, credentials!);
const response = await page.goto(notificationsPath!, { waitUntil: "domcontentloaded" });
await skipIfUnavailable(page, response, `Tenant notification settings path ${notificationsPath}`);
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(notificationsPath!)}(?:[?#].*)?$`, "u"));
await expect(page.locator('[data-ui-id="ui.settings.notifications.page"]').first()).toBeVisible();
for (const category of ["default", "billing", "team"]) {
await expect(page.locator(`[data-ui-id="ui.settings.notifications.category.${category}"]`).first()).toBeVisible();
await expect(page.locator(`[data-ui-id="ui.settings.notifications.preference.${category}.in_app"]`).first()).toBeVisible();
await expect(page.locator(`[data-ui-id="ui.settings.notifications.preference.${category}.email"]`).first()).toBeVisible();
}
await expectNoHorizontalOverflow(page);
await expectNoCriticalA11yViolations(page);
});
test("submits preference update contract with csrf without mutating data", async ({ page }) => {
await loginAsTenantUser(page, credentials!);
const response = await page.goto(notificationsPath!, { waitUntil: "domcontentloaded" });
await skipIfUnavailable(page, response, `Tenant notification settings path ${notificationsPath}`);
const form = page.locator('[data-ui-id="ui.settings.notifications.preference.team.email"]').first();
await expect(form).toBeVisible();
const checkbox = form.locator('input[name="enabled"]').first();
await checkbox.setChecked(true);
const csrf = form.locator('input[name="csrf"]').first();
if ((await csrf.count()) > 0) {
await expect(csrf).not.toHaveValue("");
}
const submitted = await interceptCurrentRoutePost(page, { status: 204 });
await form.locator('button[type="submit"]').first().click();
await expect.poll(() => submitted.value).not.toBeNull();
expect(postDataIncludesField(submitted.value, "action", /^update-preference$/u)).toBe(true);
expect(postDataIncludesField(submitted.value, "category", /^team$/u)).toBe(true);
expect(postDataIncludesField(submitted.value, "channel", /^EMAIL$/u)).toBe(true);
expect(postDataIncludesField(submitted.value, "enabled", /^(on|true)$/u)).toBe(true);
if ((await csrf.count()) > 0) {
expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true);
}
});
});