diff --git a/tests/runner-e2e/plan-revision-flow.test.ts b/tests/runner-e2e/plan-revision-flow.test.ts index 57d55a59897..39322920453 100644 --- a/tests/runner-e2e/plan-revision-flow.test.ts +++ b/tests/runner-e2e/plan-revision-flow.test.ts @@ -1,6 +1,6 @@ import { expect, it, vi } from "vitest"; import type { Page } from "@playwright/test"; -import { runPlanRevisionAcceptance } from "./plan-revision-flow.js"; +import { planPreviewLabel, runPlanRevisionAcceptance } from "./plan-revision-flow.js"; const state = { currentIssue: { status: "in_progress" }, @@ -36,3 +36,11 @@ it("lets deployment callers reject a binding failure without another observation expect(load).toHaveBeenCalledOnce(); expect(get).not.toHaveBeenCalled(); }); + +it("accepts the classic and Coordinator Plan preview names for the exact revision only", () => { + expect(planPreviewLabel(1).test("Open Plan revision 1")).toBe(true); + expect(planPreviewLabel(1).test("Open Plan revision 1 in task sidebar")).toBe(true); + expect(planPreviewLabel(1).test("Open Plan revision 12 in task sidebar")).toBe(false); + expect(planPreviewLabel(2).test("Open Plan revision 1 in task sidebar")).toBe(false); + expect(planPreviewLabel(1).test("Open Plan in task sidebar")).toBe(false); +}); diff --git a/tests/runner-e2e/plan-revision-flow.ts b/tests/runner-e2e/plan-revision-flow.ts index e8d7bd84a7b..553926580bb 100644 --- a/tests/runner-e2e/plan-revision-flow.ts +++ b/tests/runner-e2e/plan-revision-flow.ts @@ -19,11 +19,15 @@ export function isPendingPlanConfirmation(interaction: PlanInteraction) { && typeof interaction.payload.target.revisionId === "string"; } export function normalizePlanMarkdown(body: string | null | undefined) { return (body ?? "").replaceAll("\\_", "_"); } +export function planPreviewLabel(revision: number): RegExp { + return new RegExp(`^Open Plan revision ${revision}(?: in task sidebar)?$`); +} + export async function expectPlanStageVisible(page: Page, options: { native: boolean; revision: number | null }) { const root = options.native ? page.locator('[data-testid="task-chat-turn"][data-settled="true"]') : page.locator("body"); const preview = root.getByTestId("task-chat-plan-preview").last(); await expect(preview).toBeVisible({ timeout: 30_000 }); - if (options.revision !== null) await expect(preview).toHaveAttribute("aria-label", `Open Plan revision ${options.revision}`); + if (options.revision !== null) await expect(preview).toHaveAttribute("aria-label", planPreviewLabel(options.revision)); } /** The classic matrix and deployment-targeted journeys share this exact user story. */ diff --git a/tests/runner-e2e/product-journeys/contracts.test.ts b/tests/runner-e2e/product-journeys/contracts.test.ts index a702406ee61..219fff80f32 100644 --- a/tests/runner-e2e/product-journeys/contracts.test.ts +++ b/tests/runner-e2e/product-journeys/contracts.test.ts @@ -17,7 +17,11 @@ import { journeyRequiredChecks } from "./success-contract.js"; import type { OnboardingConnectEvidence } from "./onboarding-connect.js"; vi.mock("@playwright/test", () => ({ expect: Object.assign( - (locator: { textContent(): Promise }) => ({ async toContainText(value: string) { expect(await locator.textContent()).toContain(value); } }), + (locator: { textContent(): Promise; isVisible?(): Promise }) => ({ + async toContainText(value: string) { expect(await locator.textContent()).toContain(value); }, + async toBeVisible() { expect(await locator.isVisible?.()).toBe(true); }, + async toBeInViewport() {}, + }), { poll: (read: () => Promise) => ({ async toBe(value: unknown) { expect(await read()).toBe(value); } }) }, ), })); @@ -189,10 +193,23 @@ describe("deployment journey contracts", () => { await fixtures.resolve(["backlog-task"]); api.post.mockImplementation(async () => { throw Error("task creation inside measured story"); }); let assigned = false; - const locator = { filter: vi.fn(), first: vi.fn(), locator: vi.fn(), getByRole: vi.fn(), click: vi.fn(), isVisible: vi.fn(async () => false), textContent: vi.fn(async () => assigned ? "You" : "Unassigned") }; - for (const method of [locator.filter, locator.first, locator.locator, locator.getByRole]) method.mockReturnValue(locator); + let panelOpen = false; + let propertiesSelected = false; + const chain = (target: T) => Object.assign(target, { filter: vi.fn(() => target), first: vi.fn(() => target) }); + const hidden = chain({ isVisible: vi.fn(async () => false), click: vi.fn() }); + const link = chain({ click: vi.fn() }); + const opener = chain({ isVisible: vi.fn(async () => !panelOpen), click: vi.fn(async () => { panelOpen = true; }) }); + const propertiesOption = chain({ isVisible: vi.fn(async () => panelOpen && !propertiesSelected), click: vi.fn(async () => { propertiesSelected = true; }) }); + const valueButton = chain({ click: vi.fn() }); + const value = chain({ getByRole: vi.fn(() => valueButton), textContent: vi.fn(async () => assigned ? "You" : "Unassigned") }); + const assignee = chain({ isVisible: vi.fn(async () => propertiesSelected), locator: vi.fn(() => value), + scrollIntoViewIfNeeded: vi.fn() }); + const locator = link; const assign = { click: vi.fn(async () => { assigned = true; }) }; - const page = { goto: vi.fn(), reload: vi.fn(), locator: vi.fn(() => locator), getByRole: vi.fn((_role: string, options?: { name?: unknown }) => options?.name === "Assign to me" ? assign : locator) }; + const page = { goto: vi.fn(), reload: vi.fn(async () => { panelOpen = false; propertiesSelected = false; }), locator: vi.fn(() => assignee), + getByRole: vi.fn((role: string, options?: { name?: unknown }) => options?.name === "Assign to me" ? assign + : role === "link" ? link : role === "option" ? propertiesOption : role === "tab" ? hidden + : options?.name === "Open a new tab" || options?.name === "Toggle side panel" ? hidden : opener) }; const get = vi.fn(async (route: string) => route.endsWith("/runs") ? [] : { assigneeUserId: assigned ? context.user.id : null, assigneeAgentId: null, status: "backlog" }); Object.assign(context.api, { get }); context.page = page as unknown as JourneyContext["page"]; @@ -202,6 +219,8 @@ describe("deployment journey contracts", () => { expect(session.own).toHaveBeenCalledTimes(2); expect(page.goto).toHaveBeenCalledExactlyOnceWith("https://qa.example.test/QA/issues"); expect(locator.filter).toHaveBeenCalledWith({ hasText: "Journey QA campaign-1" }); + expect(opener.click).toHaveBeenCalledTimes(2); + expect(propertiesOption.click).toHaveBeenCalledTimes(2); expect(assign.click).toHaveBeenCalledOnce(); expect(page.reload).toHaveBeenCalledOnce(); expect(get.mock.calls.map(([route]) => route)).toEqual(["/api/issues/task-1", "/api/issues/task-1", "/api/issues/task-1/runs"]); diff --git a/tests/runner-e2e/product-journeys/inbox-triage-flow.ts b/tests/runner-e2e/product-journeys/inbox-triage-flow.ts index baca8ab7ef8..c93acb94219 100644 --- a/tests/runner-e2e/product-journeys/inbox-triage-flow.ts +++ b/tests/runner-e2e/product-journeys/inbox-triage-flow.ts @@ -68,7 +68,15 @@ export async function inboxTriage(context: JourneyContext, session: TargetSessio await inboxStep("inbox_unread_projection_failed", () => expect.poll(async () => (await read()).isUnreadForMe).toBe(true)); await openPersonalInbox(context, "unread"); await inboxStep("inbox_unread_row_missing", () => expect(row).toBeVisible()); - await inboxStep("inbox_mark_read_failed", () => row.getByRole("button", { name: "Mark as read", exact: true }).click()); + await inboxStep("inbox_mark_read_failed", async () => { + const markRead = row.getByRole("button", { name: "Mark as read", exact: true }); + if (await markRead.isVisible()) return await markRead.click(); + await openPersonalInbox(context, "mine"); + await expect(row).toBeVisible(); + await page.getByPlaceholder(/^Search (?:inbox|tasks)(?:…|\.\.\.)$/i).blur(); + await row.hover(); + await page.keyboard.press("r"); + }); await inboxStep("inbox_read_projection_failed", () => expect.poll(async () => (await read()).isUnreadForMe).toBe(false)); await inboxStep("inbox_unread_reload_failed", () => page.reload()); await openPersonalInbox(context, "unread"); diff --git a/tests/runner-e2e/product-journeys/project-context-readback.ts b/tests/runner-e2e/product-journeys/project-context-readback.ts index 498e9c7a5f3..854dea3bdd8 100644 --- a/tests/runner-e2e/product-journeys/project-context-readback.ts +++ b/tests/runner-e2e/product-journeys/project-context-readback.ts @@ -1,4 +1,5 @@ import { expect, type Page } from "@playwright/test"; +import { showPropertyRow } from "./task-panel.js"; import { JourneyError } from "./types.js"; type BrowserStage = "project_list" | "project_open" | "project_task_open" | "project_property"; @@ -39,9 +40,7 @@ export async function openProjectTaskThroughList(input: { page: Page; origin: st await expect(main.getByText(prompt, { exact: true }).filter({ visible: true }).first()).toBeVisible(); }); await browserStep("project_property", async () => { - const properties = page.getByRole("button", { name: /^(Show properties|Properties)$/ }).filter({ visible: true }).first(); - if (await properties.isVisible()) await properties.click(); - const projectProperty = page.locator("[data-property-row]").filter({ has: page.locator('[data-property-label="Project"]') }).filter({ visible: true }); + const projectProperty = await showPropertyRow(page, "Project"); await expect(projectProperty).toHaveCount(1); await expect(projectProperty.locator("[data-property-value]")).toContainText(projectName); }); diff --git a/tests/runner-e2e/product-journeys/task-dependency-resume.test.ts b/tests/runner-e2e/product-journeys/task-dependency-resume.test.ts index fa694af7d1d..b6a4397a988 100644 --- a/tests/runner-e2e/product-journeys/task-dependency-resume.test.ts +++ b/tests/runner-e2e/product-journeys/task-dependency-resume.test.ts @@ -59,6 +59,7 @@ async function fixture(premature = false, options: FixtureOptions = {}) { if (key.includes("data-property-row")) return panelOpen && !options.missingProperty; if (key === "Toggle side panel") return !panelOpen && options.closedPanel === "toggle"; if (key.includes("Show properties")) return !panelOpen && options.closedPanel === "properties"; + if (key === "Open a new tab" || key === "/^Properties/") return false; return true; }, async scrollIntoViewIfNeeded() { actions.push(`scroll:${key}`); }, diff --git a/tests/runner-e2e/product-journeys/task-dependency-resume.ts b/tests/runner-e2e/product-journeys/task-dependency-resume.ts index ed13e309878..98bc71e6a88 100644 --- a/tests/runner-e2e/product-journeys/task-dependency-resume.ts +++ b/tests/runner-e2e/product-journeys/task-dependency-resume.ts @@ -1,4 +1,5 @@ import { randomBytes } from "node:crypto"; +import { showPropertyRow } from "./task-panel.js"; import { mkdir, writeFile } from "node:fs/promises"; import path from "node:path"; import { expect } from "@playwright/test"; @@ -29,20 +30,7 @@ const documentSnapshot = (row: Row) => Object.fromEntries(["id", "companyId", "i "documentId", "createdByAgentId", "createdByUserId", "createdByRunId"].map(key => [key, row[key]])); async function properties(context: JourneyContext, label: string) { - const { page } = context; - const row = page.locator('[data-property-row]:not([inert] *):not([aria-hidden="true"] *)') - .filter({ has: page.locator(`[data-property-label="${label}"]`) }).filter({ visible: true }); - const toggle = page.getByRole("button", { name: "Toggle side panel", exact: true, pressed: false }).filter({ visible: true }); - const propertiesButton = page.getByRole("button", { name: /^(Show properties|Properties)$/ }).filter({ visible: true }); - await expect.poll(async () => await row.isVisible() || await toggle.isVisible() || await propertiesButton.isVisible()).toBe(true); - if (!await row.isVisible()) { - if (await toggle.isVisible()) await toggle.click(); - else await propertiesButton.click(); - } - await expect(row).toBeVisible(); - await row.scrollIntoViewIfNeeded(); - await expect(row).toBeInViewport(); - return row; + return await showPropertyRow(context.page, label); } async function setStatus(context: JourneyContext, label: string) { const { page } = context; diff --git a/tests/runner-e2e/product-journeys/task-document-flow.test.ts b/tests/runner-e2e/product-journeys/task-document-flow.test.ts index 21b546778ee..cd353db0565 100644 --- a/tests/runner-e2e/product-journeys/task-document-flow.test.ts +++ b/tests/runner-e2e/product-journeys/task-document-flow.test.ts @@ -25,7 +25,7 @@ describe("task document reopen navigation", () => { expect(hasText).toBe(issue.title); return { first: () => ({ click }) }; } } - : { isVisible: async () => true, first: () => ({ isVisible: async () => true }) }, + : (() => { const visible = { isVisible: async () => true, filter: () => visible, first: () => visible }; return visible; })(), }, } as unknown as JourneyContext; await reopenTaskDocument(context, issue); diff --git a/tests/runner-e2e/product-journeys/task-document-flow.ts b/tests/runner-e2e/product-journeys/task-document-flow.ts index 32dd89d69c5..b48c98d30a1 100644 --- a/tests/runner-e2e/product-journeys/task-document-flow.ts +++ b/tests/runner-e2e/product-journeys/task-document-flow.ts @@ -1,26 +1,10 @@ import { expect } from "@playwright/test"; +import { openTaskPanelTab } from "./task-panel.js"; import { taskDocumentHistoryPasses, taskDocumentMatches, type TaskDocumentExpectation, type TaskDocumentRevision, type TaskDocumentSnapshot } from "./task-document-evidence.js"; import { JourneyError, type JourneyContext, type JourneyEvidence, type TargetSession } from "./types.js"; export async function openDocumentAuthoring({ page }: JourneyContext) { - const create = page.getByRole("button", { name: "New document", exact: true }); - const properties = page.getByRole("button", { name: /^(Show properties|Properties)$/ }).first(); - const artifacts = page.getByRole("tab", { name: /^Artifacts/ }).first(); - const addTab = page.getByRole("button", { name: "Open a new tab", exact: true }); - const panelReady = async () => await create.isVisible() || await artifacts.isVisible() || await addTab.isVisible(); - await expect.poll(async () => await properties.isVisible() || await panelReady()).toBe(true); - if (await create.isVisible()) return; - if (await properties.isVisible()) { - await properties.click(); - await expect.poll(panelReady).toBe(true); - if (await create.isVisible()) return; - } - if (await artifacts.isVisible()) await artifacts.click(); - else { - await addTab.click(); - await page.getByRole("option", { name: /^Artifacts/ }).click(); - } - await expect(create).toBeVisible(); + await openTaskPanelTab(page, "Artifacts", page.getByRole("button", { name: "New document", exact: true })); } export async function reopenTaskDocument(context: JourneyContext, issue: { title: string }) { diff --git a/tests/runner-e2e/product-journeys/task-lifecycle.ts b/tests/runner-e2e/product-journeys/task-lifecycle.ts index b2086f890cb..c25068b1555 100644 --- a/tests/runner-e2e/product-journeys/task-lifecycle.ts +++ b/tests/runner-e2e/product-journeys/task-lifecycle.ts @@ -3,6 +3,7 @@ import path from "node:path"; import { expect } from "@playwright/test"; import { createTaskThroughUi, withBrowserEvent } from "../user-actions.js"; import { createObservedReader } from "./observation-read.js"; +import { showPropertyRow } from "./task-panel.js"; import { taskLifecycleEvidence, taskLifecycleLabelName, type LifecycleExpectation, type LifecycleLabel, type LifecycleObservation, type LifecycleTask } from "./task-lifecycle-evidence.js"; import { JourneyError, type JourneyContext, type JourneyEvidence, type TargetSession } from "./types.js"; @@ -17,22 +18,7 @@ const emptyObservation = (): LifecycleObservation => ({ task: null, runCount: nu titleVisible: false, descriptionVisible: false, statusVisible: false, labelVisible: false }); async function properties(context: JourneyContext) { - const { page } = context; - // Closed panes keep their rows mounted. Their geometry alone does not make - // an inert or accessibility-hidden panel available for interaction. - const row = page.locator('[data-property-row]:not([inert] *):not([aria-hidden="true"] *)') - .filter({ has: page.locator('[data-property-label="Labels"]') }).filter({ visible: true }); - const toggle = page.getByRole("button", { name: "Toggle side panel", exact: true, pressed: false }).filter({ visible: true }); - const propertiesButton = page.getByRole("button", { name: /^(Show properties|Properties)$/ }).filter({ visible: true }); - await expect.poll(async () => await row.isVisible() || await toggle.isVisible() || await propertiesButton.isVisible()).toBe(true); - if (!await row.isVisible()) { - if (await toggle.isVisible()) await toggle.click(); - else await propertiesButton.click(); - } - await expect(row).toBeVisible(); - await row.scrollIntoViewIfNeeded(); - await expect(row).toBeInViewport(); - return row; + return await showPropertyRow(context.page, "Labels"); } async function setStatus(context: JourneyContext, label: string) { diff --git a/tests/runner-e2e/product-journeys/task-panel.ts b/tests/runner-e2e/product-journeys/task-panel.ts new file mode 100644 index 00000000000..7285dc2d47a --- /dev/null +++ b/tests/runner-e2e/product-journeys/task-panel.ts @@ -0,0 +1,37 @@ +import { expect, type Locator, type Page } from "@playwright/test"; + +export function visiblePropertyRow(page: Page, label: string): Locator { + return page.locator('[data-property-row]:not([inert] *):not([aria-hidden="true"] *)') + .filter({ has: page.locator(`[data-property-label="${label}"]`) }).filter({ visible: true }); +} + +export async function openTaskPanelTab(page: Page, tabName: "Properties" | "Artifacts", ready: Locator): Promise { + const name = new RegExp(`^${tabName}`); + const tab = page.getByRole("tab", { name }).filter({ visible: true }).first(); + const option = page.getByRole("option", { name }).filter({ visible: true }).first(); + const newTab = page.getByRole("button", { name: "Open a new tab", exact: true }).filter({ visible: true }).first(); + const opener = page.getByRole("button", { name: /^(Show properties|Properties)$/ }).filter({ visible: true }).first(); + const toggle = page.getByRole("button", { name: "Toggle side panel", exact: true, pressed: false }).filter({ visible: true }).first(); + const anyVisible = async (...locators: Locator[]) => { + for (const locator of locators) if (await locator.isVisible()) return true; + return false; + }; + for (let step = 0; step < 4; step++) { + await expect.poll(() => anyVisible(ready, tab, option, newTab, toggle, opener)).toBe(true); + if (await ready.isVisible()) return; + if (await option.isVisible()) await option.click(); + else if (await tab.isVisible()) await tab.click(); + else if (await newTab.isVisible()) await newTab.click(); + else if (await toggle.isVisible()) await toggle.click(); + else await opener.click(); + } + await expect(ready).toBeVisible(); +} + +export async function showPropertyRow(page: Page, label: string): Promise { + const row = visiblePropertyRow(page, label); + await openTaskPanelTab(page, "Properties", row); + await row.scrollIntoViewIfNeeded(); + await expect(row).toBeInViewport(); + return row; +} diff --git a/tests/runner-e2e/product-journeys/task-properties.ts b/tests/runner-e2e/product-journeys/task-properties.ts index ca836af1c8b..be0d0a513c6 100644 --- a/tests/runner-e2e/product-journeys/task-properties.ts +++ b/tests/runner-e2e/product-journeys/task-properties.ts @@ -1,4 +1,5 @@ import { expect } from "@playwright/test"; +import { showPropertyRow, visiblePropertyRow } from "./task-panel.js"; import { JourneyError, type JourneyContext, type JourneyEvidence, type TargetSession } from "./types.js"; export async function taskProperties(context: JourneyContext, _session: TargetSession, _campaignId: string, evidence: JourneyEvidence) { @@ -11,13 +12,14 @@ export async function taskProperties(context: JourneyContext, _session: TargetSe // The declared starting point is the task list. Navigation to the task is a user action. await page.goto(`${api.origin}/${company.issuePrefix}/issues`); await page.getByRole("link").filter({ hasText: issue.title }).first().click(); - const properties = page.getByRole("button", { name: /^(Show properties|Properties)$/ }).first(); - if (await properties.isVisible()) await properties.click(); - const assignee = page.locator("[data-property-row]").filter({ has: page.locator('[data-property-label="Assignee"]') }); + const assignee = visiblePropertyRow(page, "Assignee"); + const showAssignee = () => showPropertyRow(page, "Assignee"); + await showAssignee(); await assignee.locator("[data-property-value]").getByRole("button").first().click(); await page.getByRole("button", { name: "Assign to me", exact: true }).click(); await expect.poll(async () => (await api.get<{ assigneeUserId: string }>(`/api/issues/${issue.id}`)).assigneeUserId).toBe(user.id); await page.reload(); + await showAssignee(); await expect(assignee.locator("[data-property-value]")).toContainText("You"); const persisted = await api.get<{ assigneeUserId: string; assigneeAgentId: string | null; status: string }>(`/api/issues/${issue.id}`); if (persisted.assigneeUserId !== user.id || persisted.assigneeAgentId !== null || persisted.status !== "backlog") throw new JourneyError("failed", "assignment_persistence_mismatch");