|
| 1 | +import { expect, it } from "vitest"; |
| 2 | +import { createChatFlowE2eSuite, installMockGateway } from "./chat-flow.test-support.ts"; |
| 3 | + |
| 4 | +const suite = createChatFlowE2eSuite(); |
| 5 | + |
| 6 | +const QUEUED = ["review the migration", "then update the docs", "finally run the smoke"] as const; |
| 7 | + |
| 8 | +/** Vertical centre of each control on the composer's input row, in page pixels. */ |
| 9 | +const COMPOSER_ROW_CONTROLS = [ |
| 10 | + ".agent-chat__input-btn--attach", |
| 11 | + ".agent-chat__composer-edit", |
| 12 | + ".agent-chat__composer-combobox textarea", |
| 13 | + ".agent-chat__composer-actions", |
| 14 | +] as const; |
| 15 | + |
| 16 | +suite.define(() => { |
| 17 | + it("edits a queued message in the composer and returns it to its place", async () => { |
| 18 | + const context = await suite.newBrowserContext({ |
| 19 | + locale: "en-US", |
| 20 | + serviceWorkers: "block", |
| 21 | + viewport: { height: 900, width: 1280 }, |
| 22 | + }); |
| 23 | + const page = await context.newPage(); |
| 24 | + const gateway = await installMockGateway(page); |
| 25 | + |
| 26 | + try { |
| 27 | + await page.goto(`${suite.server.baseUrl}chat`); |
| 28 | + const composer = page.locator(".agent-chat__composer-combobox textarea"); |
| 29 | + await composer.waitFor({ state: "visible", timeout: 15_000 }); |
| 30 | + |
| 31 | + // Offline holds the queue still, so the round-trip stays observable. |
| 32 | + await gateway.setOnline(false); |
| 33 | + await gateway.closeLatest(); |
| 34 | + for (const message of QUEUED) { |
| 35 | + await composer.fill(message); |
| 36 | + await composer.press("Enter"); |
| 37 | + await page.locator(".chat-queue__item", { hasText: message }).waitFor({ timeout: 10_000 }); |
| 38 | + } |
| 39 | + const queueText = () => page.locator(".chat-queue__item .chat-queue__text").allTextContents(); |
| 40 | + expect(await queueText()).toEqual([...QUEUED]); |
| 41 | + |
| 42 | + // Double-click is the shortcut; the pencil on the row is the visible path. |
| 43 | + await page.locator(".chat-queue__item").nth(1).dblclick(); |
| 44 | + |
| 45 | + await expect.poll(() => composer.inputValue(), { timeout: 10_000 }).toBe(QUEUED[1]); |
| 46 | + await page.locator(".agent-chat__composer-edit").waitFor({ timeout: 10_000 }); |
| 47 | + // The row stays where it is, marked as the one being edited. |
| 48 | + expect(await queueText()).toEqual([...QUEUED]); |
| 49 | + expect(await page.locator(".chat-queue__item--editing").count()).toBe(1); |
| 50 | + expect( |
| 51 | + await page.locator(".chat-queue__item").nth(1).locator(".chat-queue__badge").textContent(), |
| 52 | + ).toBe("Editing"); |
| 53 | + |
| 54 | + // The marker is a new child of a bottom-aligned row, so prove the row still |
| 55 | + // resolves to one axis instead of trusting that it looks right. |
| 56 | + const centres = await page.evaluate( |
| 57 | + (selectors) => { |
| 58 | + const row = document.querySelector(".agent-chat__composer-input-row"); |
| 59 | + return selectors.map((selector) => { |
| 60 | + const box = row?.querySelector(selector)?.getBoundingClientRect(); |
| 61 | + return box ? box.top + box.height / 2 : Number.NaN; |
| 62 | + }); |
| 63 | + }, |
| 64 | + COMPOSER_ROW_CONTROLS as unknown as string[], |
| 65 | + ); |
| 66 | + expect(centres.some(Number.isNaN)).toBe(false); |
| 67 | + expect(Math.max(...centres) - Math.min(...centres)).toBeLessThanOrEqual(1); |
| 68 | + |
| 69 | + await composer.fill("then update the docs and the changelog"); |
| 70 | + await composer.press("Enter"); |
| 71 | + |
| 72 | + await expect |
| 73 | + .poll(queueText, { timeout: 10_000 }) |
| 74 | + .toEqual([QUEUED[0], "then update the docs and the changelog", QUEUED[2]]); |
| 75 | + expect(await page.locator(".agent-chat__composer-edit").count()).toBe(0); |
| 76 | + } finally { |
| 77 | + await suite.closeBrowserContext(context); |
| 78 | + } |
| 79 | + }); |
| 80 | + |
| 81 | + it("puts the row back untouched when the edit is cancelled", async () => { |
| 82 | + const context = await suite.newBrowserContext({ |
| 83 | + locale: "en-US", |
| 84 | + serviceWorkers: "block", |
| 85 | + viewport: { height: 900, width: 1280 }, |
| 86 | + }); |
| 87 | + const page = await context.newPage(); |
| 88 | + const gateway = await installMockGateway(page); |
| 89 | + |
| 90 | + try { |
| 91 | + await page.goto(`${suite.server.baseUrl}chat`); |
| 92 | + const composer = page.locator(".agent-chat__composer-combobox textarea"); |
| 93 | + await composer.waitFor({ state: "visible", timeout: 15_000 }); |
| 94 | + await gateway.setOnline(false); |
| 95 | + await gateway.closeLatest(); |
| 96 | + for (const message of QUEUED) { |
| 97 | + await composer.fill(message); |
| 98 | + await composer.press("Enter"); |
| 99 | + await page.locator(".chat-queue__item", { hasText: message }).waitFor({ timeout: 10_000 }); |
| 100 | + } |
| 101 | + |
| 102 | + const row = page.locator(".chat-queue__item").nth(1); |
| 103 | + await row.locator(".chat-queue__edit").click(); |
| 104 | + await page.locator(".agent-chat__composer-edit").waitFor({ timeout: 10_000 }); |
| 105 | + await composer.fill("a replacement the operator abandons"); |
| 106 | + |
| 107 | + await page.locator(".agent-chat__composer-edit-cancel").click(); |
| 108 | + |
| 109 | + await expect |
| 110 | + .poll(() => page.locator(".chat-queue__item .chat-queue__text").allTextContents(), { |
| 111 | + timeout: 10_000, |
| 112 | + }) |
| 113 | + .toEqual([...QUEUED]); |
| 114 | + expect(await composer.inputValue()).toBe(""); |
| 115 | + } finally { |
| 116 | + await suite.closeBrowserContext(context); |
| 117 | + } |
| 118 | + }); |
| 119 | +}); |
0 commit comments