68 lines
3.7 KiB
TypeScript
68 lines
3.7 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 preference = page.locator('[data-ui-id="ui.settings.notifications.preference.team.email"]').first();
|
|
await expect(preference).toBeVisible();
|
|
const toggle = preference.getByRole("switch");
|
|
await expect(toggle).toBeVisible();
|
|
const initialState = (await toggle.getAttribute("aria-checked")) === "true";
|
|
|
|
const submitted = await interceptCurrentRoutePost(page, { status: 204 });
|
|
await toggle.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", new RegExp(`^${String(!initialState)}$`, "u"))).toBe(true);
|
|
expect(postDataIncludesField(submitted.value, "csrf", /.+/u)).toBe(true);
|
|
});
|
|
});
|