|
| 1 | +import { expect, it } from "vitest"; |
| 2 | +import { installMockGateway } from "../test-helpers/control-ui-e2e.ts"; |
| 3 | +import { createControlUiE2eSuite } from "./control-ui-e2e-suite.test-support.ts"; |
| 4 | + |
| 5 | +const suite = createControlUiE2eSuite({ |
| 6 | + name: "Control UI cron saved descriptions E2E", |
| 7 | + unavailableMessage: (executablePath) => |
| 8 | + `Playwright Chromium is not installed or cannot start at ${executablePath}.`, |
| 9 | +}); |
| 10 | + |
| 11 | +function cronJob(id: string, name: string) { |
| 12 | + return { |
| 13 | + id, |
| 14 | + name, |
| 15 | + enabled: true, |
| 16 | + createdAtMs: Date.parse("2026-05-29T08:00:00.000Z"), |
| 17 | + updatedAtMs: Date.parse("2026-05-29T08:05:00.000Z"), |
| 18 | + schedule: { kind: "every", everyMs: 60_000 }, |
| 19 | + sessionTarget: "main", |
| 20 | + wakeMode: "next-heartbeat", |
| 21 | + payload: { kind: "systemEvent", text: `${name} fired` }, |
| 22 | + state: {}, |
| 23 | + }; |
| 24 | +} |
| 25 | + |
| 26 | +suite.define(() => { |
| 27 | + it("shows saved descriptions in compact rows and task details for every payload kind", async () => { |
| 28 | + const jobs = [ |
| 29 | + { |
| 30 | + ...cronJob("described-event", "System reminder"), |
| 31 | + description: " Explain the system reminder without opening advanced settings ", |
| 32 | + payload: { kind: "systemEvent", text: "Run the system reminder" }, |
| 33 | + }, |
| 34 | + { |
| 35 | + ...cronJob("described-agent", "Agent digest"), |
| 36 | + description: "Summarize the overnight activity", |
| 37 | + payload: { kind: "agentTurn", message: "List overnight deployment activity" }, |
| 38 | + }, |
| 39 | + { |
| 40 | + ...cronJob("described-command", "Command check"), |
| 41 | + description: "Run the infrastructure health check", |
| 42 | + payload: { kind: "command", argv: ["echo", "healthy"] }, |
| 43 | + }, |
| 44 | + { |
| 45 | + ...cronJob("described-script", "Script check"), |
| 46 | + description: "Inspect the scripted health check", |
| 47 | + payload: { kind: "script", script: "return 'healthy'" }, |
| 48 | + }, |
| 49 | + { |
| 50 | + ...cronJob("described-heartbeat", "Heartbeat check"), |
| 51 | + description: "Explain the system-owned heartbeat", |
| 52 | + payload: { kind: "heartbeat" }, |
| 53 | + }, |
| 54 | + ] as const; |
| 55 | + const undescribedJob = cronJob("without-description", "Plain task"); |
| 56 | + const context = await suite.newBrowserContext({ |
| 57 | + locale: "en-US", |
| 58 | + serviceWorkers: "block", |
| 59 | + viewport: { height: 900, width: 1_280 }, |
| 60 | + }); |
| 61 | + const page = await context.newPage(); |
| 62 | + await installMockGateway(page, { |
| 63 | + methodResponses: { |
| 64 | + "cron.list": { |
| 65 | + jobs: [...jobs, undescribedJob], |
| 66 | + total: jobs.length + 1, |
| 67 | + offset: 0, |
| 68 | + limit: 50, |
| 69 | + hasMore: false, |
| 70 | + nextOffset: null, |
| 71 | + }, |
| 72 | + "cron.runs": { entries: [], total: 0, offset: 0, hasMore: false }, |
| 73 | + "cron.status": { enabled: true, jobs: jobs.length + 1, nextWakeAtMs: null }, |
| 74 | + }, |
| 75 | + }); |
| 76 | + |
| 77 | + try { |
| 78 | + await page.goto(`${suite.server.baseUrl}cron`); |
| 79 | + await page.locator(`[data-test-id="cron-row-${jobs[0].id}"]`).waitFor({ timeout: 10_000 }); |
| 80 | + |
| 81 | + for (const job of jobs) { |
| 82 | + const description = page.locator(`[data-test-id="cron-row-description-${job.id}"]`); |
| 83 | + expect((await description.textContent())?.trim()).toBe(`· ${job.description.trim()}`); |
| 84 | + expect(await description.getAttribute("title")).toBe( |
| 85 | + `Description: ${job.description.trim()}`, |
| 86 | + ); |
| 87 | + } |
| 88 | + expect( |
| 89 | + await page.locator(`[data-test-id="cron-row-description-${undescribedJob.id}"]`).count(), |
| 90 | + ).toBe(0); |
| 91 | + |
| 92 | + const describedRow = await page |
| 93 | + .locator(`[data-test-id="cron-row-${jobs[1].id}"]`) |
| 94 | + .boundingBox(); |
| 95 | + const undescribedRow = await page |
| 96 | + .locator(`[data-test-id="cron-row-${undescribedJob.id}"]`) |
| 97 | + .boundingBox(); |
| 98 | + expect(describedRow?.height).toBe(undescribedRow?.height); |
| 99 | + |
| 100 | + for (const job of jobs) { |
| 101 | + const row = page.locator(`[data-test-id="cron-row-${job.id}"]`); |
| 102 | + await row.locator(".cron-table__name-text").click(); |
| 103 | + const detailDescription = page.locator('[data-test-id="cron-detail-description"]'); |
| 104 | + await detailDescription.waitFor({ state: "visible" }); |
| 105 | + expect((await detailDescription.textContent())?.replace(/\s+/g, " ").trim()).toBe( |
| 106 | + `Description: ${job.description.trim()}`, |
| 107 | + ); |
| 108 | + |
| 109 | + await page.locator('[data-test-id="cron-detail-tab-history"]').click(); |
| 110 | + expect((await detailDescription.textContent())?.replace(/\s+/g, " ").trim()).toBe( |
| 111 | + `Description: ${job.description.trim()}`, |
| 112 | + ); |
| 113 | + await page.locator('[data-test-id="cron-back"]').click(); |
| 114 | + await row.waitFor({ timeout: 10_000 }); |
| 115 | + } |
| 116 | + } finally { |
| 117 | + await suite.closeBrowserContext(context); |
| 118 | + } |
| 119 | + }); |
| 120 | +}); |
0 commit comments