206 lines
9.0 KiB
TypeScript
206 lines
9.0 KiB
TypeScript
import { expect, test, type Locator, type Page } from "./utils/test";
|
|
import { expectNoCriticalA11yViolations } from "./utils/axe";
|
|
import { getTenantCredentials, loginAsTenantUser } from "./utils/auth";
|
|
import { expectNoHorizontalOverflow, narrowMobileViewport } from "./utils/mobile";
|
|
import { escapeRegExp, failOnStripeNetworkRequests, skipIfUnavailable } from "./utils/navigation";
|
|
import { skipOrFailWhenE2eFixtureMissing, skipOrFailWhenE2eInputsMissing } from "./utils/readiness";
|
|
|
|
const credentials = getTenantCredentials();
|
|
const dashboardPath = process.env.E2E_TENANT_DASHBOARD_PATH;
|
|
const subscriptionPath = process.env.E2E_TENANT_SUBSCRIPTION_PATH;
|
|
const pluginSettingsPath = process.env.E2E_PLUGIN_SETTINGS_PATH;
|
|
const workflowBuilderPath = process.env.E2E_WORKFLOW_BUILDER_PATH;
|
|
const workflowRunManualPath = process.env.E2E_WORKFLOW_RUN_MANUAL_PATH;
|
|
|
|
test.describe("readiness golden path mobile a11y", () => {
|
|
test.use({ viewport: narrowMobileViewport, isMobile: true, hasTouch: true });
|
|
|
|
test.beforeEach(async ({ page }) => {
|
|
await failOnStripeNetworkRequests(page);
|
|
});
|
|
|
|
test("navigates authenticated mobile readiness surfaces without mutations", async ({ page }) => {
|
|
skipOrFailWhenE2eInputsMissing(
|
|
[
|
|
"E2E_TENANT_EMAIL",
|
|
"E2E_TENANT_PASSWORD",
|
|
"E2E_TENANT_DASHBOARD_PATH",
|
|
"E2E_TENANT_SUBSCRIPTION_PATH",
|
|
"E2E_PLUGIN_SETTINGS_PATH",
|
|
"E2E_WORKFLOW_BUILDER_PATH",
|
|
"E2E_WORKFLOW_RUN_MANUAL_PATH",
|
|
],
|
|
"Readiness golden path inputs not configured"
|
|
);
|
|
|
|
await loginAsTenantUser(page, credentials!);
|
|
|
|
const dashboardResponse = await page.goto(dashboardPath!, { waitUntil: "domcontentloaded" });
|
|
await skipIfUnavailable(page, dashboardResponse, `Tenant dashboard path ${dashboardPath}`);
|
|
await expect(page).toHaveURL(pathPattern(dashboardPath!));
|
|
await expect(page.locator('[data-ui-id="ui.action.shell.sidebarTrigger"]').first()).toBeVisible();
|
|
await expectReadinessPage(page);
|
|
|
|
const mobileSidebar = page.locator('[data-ui-id="ui.surface.app.sidebar.mobile"], [data-mobile="true"]').first();
|
|
await expect(mobileSidebar).toBeHidden();
|
|
await page.locator('[data-ui-id="ui.action.shell.sidebarTrigger"]').first().click();
|
|
await expect(mobileSidebar).toBeVisible();
|
|
|
|
await clickAndExpectPath(mobileSidebar.locator('[data-ui-id="ui.nav.app.settings"]').first(), page, /\/settings\/profile(?:[?#].*)?$/u);
|
|
await expect(mobileSidebar).toBeHidden();
|
|
await expectReadinessPage(page);
|
|
|
|
await clickVisibleLinkToPath(page, subscriptionPath!, "Subscription settings link");
|
|
await expect(page.locator('[data-ui-id="ui.subscription.page"]').first()).toBeVisible({ timeout: 10_000 });
|
|
await expectReadinessPage(page);
|
|
|
|
const checkoutLink = page.locator('[data-ui-id="ui.subscription.checkout.link"]').first();
|
|
if (!(await isVisible(checkoutLink))) {
|
|
skipOrFailWhenE2eFixtureMissing("No checkout catalog link rendered for this fixture");
|
|
}
|
|
await clickAndExpectPath(checkoutLink, page, /\/subscribe\/[^/?#]+(?:[?#].*)?$/u);
|
|
await expect(page.locator('[data-ui-id="ui.subscription.checkout.page"]').first()).toBeVisible({ timeout: 10_000 });
|
|
await expectReadinessPage(page);
|
|
|
|
await clickVisibleLinkToPath(page, subscriptionPath!, "Checkout back-to-subscription link");
|
|
await expect(page.locator('[data-ui-id="ui.subscription.page"]').first()).toBeVisible({ timeout: 10_000 });
|
|
|
|
await clickVisibleLinkToPath(page, pluginSettingsPath!, "Plugin settings link");
|
|
await expect(page.locator('[data-ui-id="ui.plugins.page"]').first()).toBeVisible({ timeout: 10_000 });
|
|
await expectReadinessPage(page);
|
|
|
|
await page.locator('[data-ui-id="ui.action.shell.sidebarTrigger"]').first().click();
|
|
await expect(mobileSidebar).toBeVisible();
|
|
await clickAndExpectPath(mobileSidebar.locator('[data-ui-id="ui.nav.app.workflowEngine"]').first(), page, /\/workflow-engine(?:[?#].*)?$/u);
|
|
await expect(mobileSidebar).toBeHidden();
|
|
|
|
await clickVisibleLinkToPath(page, workflowListPathFromBuilderPath(workflowBuilderPath!), "Workflow list link");
|
|
await clickVisibleLinkToPath(page, workflowBuilderPath!, "Workflow builder link");
|
|
await expect(page.locator('[data-ui-id="ui.workflows.builder.canvas"]').first()).toBeVisible({ timeout: 10_000 });
|
|
await expectReadinessPage(page);
|
|
|
|
const runTrigger = page.locator('[data-ui-id="ui.workflows.run.dropdown.trigger"]').first();
|
|
if (!(await isVisible(runTrigger))) {
|
|
skipOrFailWhenE2eFixtureMissing("Workflow builder did not render a run dropdown trigger");
|
|
}
|
|
const runTriggerButton = runTrigger.locator("xpath=ancestor::button[1]");
|
|
if (!(await runTriggerButton.isEnabled())) {
|
|
skipOrFailWhenE2eFixtureMissing("Workflow run dropdown is disabled; provide a live deterministic workflow path");
|
|
}
|
|
await runTrigger.click();
|
|
|
|
const manualRunOption = page.locator('[data-ui-id="ui.workflows.run.dropdown.manual"]').first();
|
|
await expect(manualRunOption).toBeVisible();
|
|
await clickAndExpectPath(manualRunOption, page, pathPattern(workflowRunManualPath!));
|
|
await expect(page.locator('[data-ui-id="ui.workflows.run.manual.form"]').first()).toBeVisible({ timeout: 10_000 });
|
|
await expectReadinessPage(page);
|
|
});
|
|
});
|
|
|
|
async function expectReadinessPage(page: Page): Promise<void> {
|
|
await expectNoHorizontalOverflow(page);
|
|
await expectNoCriticalA11yViolations(page);
|
|
}
|
|
|
|
async function clickVisibleLinkToPath(page: Page, path: string, label: string): Promise<void> {
|
|
if (await tryClickVisibleLinkToPath(page, path)) {
|
|
return;
|
|
}
|
|
// On mobile the account/settings shortcuts (e.g. the subscription link) collapse
|
|
// into the shell "more" overflow popover, which mounts its links in a portal on
|
|
// open. Open it and retry before declaring the link missing.
|
|
const moreMenu = page.locator('[data-ui-id="ui.action.shell.more"]').first();
|
|
if (await isVisible(moreMenu)) {
|
|
await moreMenu.click();
|
|
await page
|
|
.locator(`a[href="${path}"]`)
|
|
.first()
|
|
.waitFor({ state: "visible", timeout: 3000 })
|
|
.catch(() => undefined);
|
|
if (await tryClickVisibleLinkToPath(page, path)) {
|
|
return;
|
|
}
|
|
await page.keyboard.press("Escape").catch(() => undefined);
|
|
}
|
|
// On mobile the settings sub-nav (Profile/Subscription/Plugins/…) collapses into a
|
|
// section <Select> combobox that navigates on choose; the desktop <a> links are
|
|
// display:hidden. Drive the combobox by the target section's label.
|
|
if (await trySelectSettingsTabToPath(page, path)) {
|
|
return;
|
|
}
|
|
skipOrFailWhenE2eFixtureMissing(`${label} was not rendered for ${path}`);
|
|
}
|
|
|
|
async function trySelectSettingsTabToPath(page: Page, path: string): Promise<boolean> {
|
|
const combobox = page.getByRole("combobox", { name: "Select..." }).first();
|
|
if (!(await isVisible(combobox))) {
|
|
return false;
|
|
}
|
|
const segment = path.split("?")[0].replace(/\/+$/u, "").split("/").pop() ?? "";
|
|
if (!segment) {
|
|
return false;
|
|
}
|
|
const optionName = segment
|
|
.split("-")
|
|
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
.join(" ");
|
|
await combobox.click();
|
|
const option = page.getByRole("option", { name: optionName, exact: true }).first();
|
|
if (!(await isVisible(option))) {
|
|
await page.keyboard.press("Escape").catch(() => undefined);
|
|
return false;
|
|
}
|
|
await Promise.all([page.waitForURL(pathPattern(path)), option.click()]);
|
|
return true;
|
|
}
|
|
|
|
async function tryClickVisibleLinkToPath(page: Page, path: string): Promise<boolean> {
|
|
const links = page.locator("a[href]");
|
|
// Snapshot every href in a single evaluateAll so a streaming surface (e.g. the
|
|
// workflow-engine SSE list) re-rendering mid-scan can't make per-node
|
|
// getAttribute calls hang on a detached node.
|
|
const hrefs = await links.evaluateAll((els) => els.map((el) => el.getAttribute("href")));
|
|
for (let index = 0; index < hrefs.length; index += 1) {
|
|
if (!hrefMatchesPath(hrefs[index], path)) {
|
|
continue;
|
|
}
|
|
const link = links.nth(index);
|
|
if (await link.isVisible()) {
|
|
await clickAndExpectPath(link, page, pathPattern(path));
|
|
return true;
|
|
}
|
|
}
|
|
return false;
|
|
}
|
|
|
|
async function clickAndExpectPath(locator: Locator, page: Page, expectedUrl: RegExp): Promise<void> {
|
|
await expect(locator).toBeVisible();
|
|
await Promise.all([page.waitForURL(expectedUrl), locator.click()]);
|
|
}
|
|
|
|
async function isVisible(locator: Locator): Promise<boolean> {
|
|
return (await locator.count()) > 0 && (await locator.isVisible());
|
|
}
|
|
|
|
function hrefMatchesPath(href: string | null, path: string): boolean {
|
|
if (!href) return false;
|
|
if (href === path) return true;
|
|
try {
|
|
const url = new URL(href, "http://e2e.local");
|
|
return `${url.pathname}${url.search}` === path || url.pathname === path;
|
|
} catch {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
function pathPattern(path: string): RegExp {
|
|
return new RegExp(`${escapeRegExp(path)}(?:[?#].*)?$`, "u");
|
|
}
|
|
|
|
function workflowListPathFromBuilderPath(path: string): string {
|
|
const marker = "/workflow-engine/workflows/";
|
|
const index = path.indexOf(marker);
|
|
if (index === -1) return path;
|
|
return `${path.slice(0, index)}${marker.slice(0, -1)}`;
|
|
}
|