111 lines
5.7 KiB
TypeScript
111 lines
5.7 KiB
TypeScript
import { expect, test, type Page } from "./utils/test";
|
|
import { expectNoCriticalA11yViolations } from "./utils/axe";
|
|
import { loginAsAdminUser } from "./utils/auth";
|
|
import { expectNoHorizontalOverflow, narrowMobileViewport } from "./utils/mobile";
|
|
import { escapeRegExp, interceptCurrentRoutePost, postDataIncludesField, skipIfUnavailable } from "./utils/navigation";
|
|
import { skipOrFailWhenE2eFixtureMissing, skipOrFailWhenE2eInputsMissing } from "./utils/readiness";
|
|
|
|
// Admin-host pages use the canonical local platform admin. The shared tenant
|
|
// user must not be an operator (it would redirect to the admin host and break
|
|
// tenant-app login flows), so the seed emits the identities separately.
|
|
const adminCredentials =
|
|
process.env.E2E_ADMIN_EMAIL && process.env.E2E_ADMIN_PASSWORD
|
|
? { email: process.env.E2E_ADMIN_EMAIL, password: process.env.E2E_ADMIN_PASSWORD }
|
|
: null;
|
|
const adminEmailSequencesPath = process.env.E2E_ADMIN_EMAIL_SEQUENCES_PATH;
|
|
const readinessSequenceName = "E2E Customer Welcome Sequence";
|
|
const readinessSequenceId = "seq_e2e_customer_welcome";
|
|
|
|
test.describe("admin email sequences mobile a11y", () => {
|
|
test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true });
|
|
|
|
test.beforeEach(() => {
|
|
skipOrFailWhenE2eInputsMissing(
|
|
["E2E_ADMIN_EMAIL", "E2E_ADMIN_PASSWORD", "E2E_ADMIN_EMAIL_SEQUENCES_PATH"],
|
|
"Admin email sequence mobile a11y inputs not configured"
|
|
);
|
|
});
|
|
|
|
test("renders seeded sequence list, detail, and stats surfaces on mobile", async ({ page }) => {
|
|
await openAdminEmailSequences(page);
|
|
|
|
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(adminEmailSequencesPath!)}(?:[?#].*)?$`, "u"));
|
|
await expect(page.getByRole("heading", { name: /email sequences|e-mail-sequenzen/i }).first()).toBeVisible();
|
|
const sequenceLink = seededSequenceLink(page);
|
|
if (!(await isVisible(sequenceLink))) {
|
|
skipOrFailWhenE2eFixtureMissing("Admin email sequence fixture is missing the seeded customer welcome sequence");
|
|
}
|
|
await expect(page.locator("table").first()).toContainText("lead.converted_to_customer");
|
|
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
|
|
await sequenceLink.click();
|
|
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(adminEmailSequencesPath!)}/${readinessSequenceId}(?:[?#].*)?$`, "u"));
|
|
await expect(page.getByRole("heading", { name: readinessSequenceName })).toBeVisible();
|
|
await expect(page.locator('input[name="name"]')).toHaveValue(readinessSequenceName);
|
|
await expect(page.locator('input[name="triggerEvent"]')).toHaveValue("lead.converted_to_customer");
|
|
await expect(page.locator('textarea[name="stepsJson"]')).toContainText("E2E Readiness customer setup");
|
|
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
|
|
const statsLink = page.getByRole("link", { name: /stats|statistiken/i }).first();
|
|
await expect(statsLink).toBeVisible();
|
|
await statsLink.click();
|
|
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(adminEmailSequencesPath!)}/${readinessSequenceId}/stats(?:[?#].*)?$`, "u"));
|
|
await expect(page.getByRole("heading", { name: readinessSequenceName })).toBeVisible();
|
|
await expect(page.locator("table").first()).toContainText("E2E Readiness customer setup");
|
|
await expect(page.getByRole("link", { name: /edit sequence|sequenz bearbeiten/i }).first()).toHaveAttribute(
|
|
"href",
|
|
new RegExp(`${escapeRegExp(adminEmailSequencesPath!)}/${readinessSequenceId}(?:[?#].*)?$`, "u")
|
|
);
|
|
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
});
|
|
|
|
test("toggle lifecycle form posts intent without mutating the seeded sequence", async ({ page }) => {
|
|
await openAdminEmailSequences(page);
|
|
const sequenceLink = seededSequenceLink(page);
|
|
if (!(await isVisible(sequenceLink))) {
|
|
skipOrFailWhenE2eFixtureMissing("Admin email sequence fixture is missing the seeded customer welcome sequence");
|
|
}
|
|
|
|
await sequenceLink.click();
|
|
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(adminEmailSequencesPath!)}/${readinessSequenceId}(?:[?#].*)?$`, "u"));
|
|
const toggleForm = page.locator('form:has(input[name="intent"][value="toggle"])').first();
|
|
if (!(await isVisible(toggleForm))) {
|
|
skipOrFailWhenE2eFixtureMissing("Admin email sequence detail fixture has no toggle lifecycle form");
|
|
}
|
|
await expect(toggleForm.locator('input[name="intent"]')).toHaveValue("toggle");
|
|
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
|
|
const submittedPostData = await interceptCurrentRoutePost(page);
|
|
const toggleButton = toggleForm.locator('button[type="submit"]').first();
|
|
await toggleButton.focus();
|
|
await expect(toggleButton).toBeFocused();
|
|
await page.keyboard.press("Enter");
|
|
|
|
await expect.poll(() => submittedPostData.value, { message: "email sequence toggle POST payload was captured" }).not.toBeNull();
|
|
expect(postDataIncludesField(submittedPostData.value, "intent", /^toggle$/u)).toBe(true);
|
|
await expect(page).toHaveURL(new RegExp(`${escapeRegExp(adminEmailSequencesPath!)}/${readinessSequenceId}(?:[?#].*)?$`, "u"));
|
|
});
|
|
});
|
|
|
|
async function openAdminEmailSequences(page: Page): Promise<void> {
|
|
await loginAsAdminUser(page, adminCredentials!);
|
|
const response = await page.goto(adminEmailSequencesPath!, { waitUntil: "domcontentloaded" });
|
|
await skipIfUnavailable(page, response, "Admin email sequence path is not reachable in this environment");
|
|
}
|
|
|
|
function seededSequenceLink(page: Page) {
|
|
return page.getByRole("link", { name: readinessSequenceName }).first();
|
|
}
|
|
|
|
async function isVisible(locator: ReturnType<Page["locator"]>): Promise<boolean> {
|
|
return (await locator.count()) > 0 && (await locator.isVisible());
|
|
}
|