Skip to content

Commit 15553b6

Browse files
committed
fix(ui): wait for restored draft before clearing
1 parent 596df18 commit 15553b6

2 files changed

Lines changed: 97 additions & 79 deletions

File tree

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
import { expect, it } from "vitest";
2+
import type { ChatPaneElement } from "../pages/chat/route-draft-focus-handoff.ts";
3+
import { waitForControlUiRoute } from "../test-helpers/control-ui-e2e.ts";
4+
import {
5+
captureUiProof,
6+
controlUiSessionPath,
7+
controlUiSessionUrl,
8+
createSessionManagementE2eSuite,
9+
installMockGateway,
10+
sessionRow,
11+
sessionsListResponse,
12+
} from "./session-management.test-support.ts";
13+
import { waitForSettledFormControls } from "./settle.test-support.ts";
14+
15+
const suite = createSessionManagementE2eSuite();
16+
17+
suite.define(() => {
18+
it("keeps the browser-local draft pencil visible on active Home beside activity", async () => {
19+
const mainKey = "agent:main:main";
20+
const secondKey = "agent:main:draft-second";
21+
const context = await suite.browser.newContext({
22+
colorScheme: "dark",
23+
locale: "en-US",
24+
serviceWorkers: "block",
25+
viewport: { height: 900, width: 1280 },
26+
});
27+
const page = await context.newPage();
28+
await installMockGateway(page, {
29+
methodResponses: {
30+
"sessions.list": sessionsListResponse([
31+
sessionRow(mainKey, "Main", 2, {
32+
hasActiveRun: true,
33+
startedAt: 1,
34+
status: "running",
35+
}),
36+
sessionRow(secondKey, "Draft second", 1),
37+
]),
38+
},
39+
sessionKey: mainKey,
40+
});
41+
42+
try {
43+
await page.goto(controlUiSessionUrl(suite.server.baseUrl, mainKey));
44+
const homeRow = page.locator(".nav-item--home");
45+
const secondRow = page.locator(`[data-session-key="${secondKey}"]`);
46+
const composer = page.locator(
47+
'openclaw-chat-pane[aria-hidden="false"] .agent-chat__composer-combobox > textarea',
48+
);
49+
await homeRow.waitFor({ state: "visible", timeout: 10_000 });
50+
await secondRow.waitFor({ state: "visible" });
51+
await composer.waitFor({ state: "visible" });
52+
await captureUiProof(page, "draft-indicator-before.png");
53+
54+
await composer.fill("Keep this unsent");
55+
const activity = homeRow.getByRole("img", { name: "Active run" });
56+
const draft = homeRow.getByRole("img", { name: "Unsent draft" });
57+
await activity.waitFor();
58+
await draft.waitFor();
59+
const activityBox = await activity.boundingBox();
60+
const draftBox = await draft.boundingBox();
61+
if (!activityBox || !draftBox) {
62+
throw new Error("expected activity and draft icon bounds");
63+
}
64+
expect(draftBox.x).toBeGreaterThanOrEqual(activityBox.x + activityBox.width);
65+
await captureUiProof(page, "draft-indicator-active.png");
66+
67+
await secondRow.getByRole("link").click();
68+
await expect.poll(() => new URL(page.url()).pathname).toBe(controlUiSessionPath(secondKey));
69+
await draft.waitFor();
70+
71+
await homeRow.click();
72+
await waitForControlUiRoute(page, {
73+
pathname: controlUiSessionPath(mainKey),
74+
routeId: "chat",
75+
});
76+
await draft.waitFor();
77+
const presentedPanes = page.locator('openclaw-chat-pane[aria-hidden="false"]');
78+
await expect
79+
.poll(() =>
80+
presentedPanes.evaluateAll((panes) =>
81+
panes.map((pane) => (pane as ChatPaneElement).sessionKey),
82+
),
83+
)
84+
.toEqual([mainKey]);
85+
86+
await waitForSettledFormControls(page, [{ locator: composer, value: "Keep this unsent" }]);
87+
await composer.fill("");
88+
await waitForSettledFormControls(page, [{ locator: composer, value: "" }]);
89+
await expect.poll(() => draft.count()).toBe(0);
90+
await secondRow.getByRole("link").click();
91+
await expect.poll(() => new URL(page.url()).pathname).toBe(controlUiSessionPath(secondKey));
92+
await expect.poll(() => draft.count()).toBe(0);
93+
} finally {
94+
await context.close();
95+
}
96+
});
97+
});

‎ui/src/e2e/session-management.sidebar.e2e.test.ts‎

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import path from "node:path";
22
import { expect, it } from "vitest";
3-
import type { ChatPaneElement } from "../pages/chat/route-draft-focus-handoff.ts";
43
import {
54
waitForControlUiGatewayReady,
65
waitForControlUiGatewayReconnecting,
76
} from "../test-helpers/control-ui-e2e-readiness.ts";
8-
import { waitForControlUiRoute } from "../test-helpers/control-ui-e2e.ts";
97
import { expectRequestCountStable } from "./chat-flow.test-support.ts";
108
import {
119
actionOpacity,
@@ -27,83 +25,6 @@ import {
2725
const suite = createSessionManagementE2eSuite();
2826

2927
suite.define(() => {
30-
it("keeps the browser-local draft pencil visible on active Home beside activity", async () => {
31-
const mainKey = "agent:main:main";
32-
const secondKey = "agent:main:draft-second";
33-
const context = await suite.browser.newContext({
34-
colorScheme: "dark",
35-
locale: "en-US",
36-
serviceWorkers: "block",
37-
viewport: { height: 900, width: 1280 },
38-
});
39-
const page = await context.newPage();
40-
await installMockGateway(page, {
41-
methodResponses: {
42-
"sessions.list": sessionsListResponse([
43-
sessionRow(mainKey, "Main", 2, {
44-
hasActiveRun: true,
45-
startedAt: 1,
46-
status: "running",
47-
}),
48-
sessionRow(secondKey, "Draft second", 1),
49-
]),
50-
},
51-
sessionKey: mainKey,
52-
});
53-
54-
try {
55-
await page.goto(controlUiSessionUrl(suite.server.baseUrl, mainKey));
56-
const homeRow = page.locator(".nav-item--home");
57-
const secondRow = page.locator(`[data-session-key="${secondKey}"]`);
58-
const composer = page.locator(
59-
'openclaw-chat-pane[aria-hidden="false"] .agent-chat__composer-combobox > textarea',
60-
);
61-
await homeRow.waitFor({ state: "visible", timeout: 10_000 });
62-
await secondRow.waitFor({ state: "visible" });
63-
await composer.waitFor({ state: "visible" });
64-
await captureUiProof(page, "draft-indicator-before.png");
65-
66-
await composer.fill("Keep this unsent");
67-
const activity = homeRow.getByRole("img", { name: "Active run" });
68-
const draft = homeRow.getByRole("img", { name: "Unsent draft" });
69-
await activity.waitFor();
70-
await draft.waitFor();
71-
const activityBox = await activity.boundingBox();
72-
const draftBox = await draft.boundingBox();
73-
if (!activityBox || !draftBox) {
74-
throw new Error("expected activity and draft icon bounds");
75-
}
76-
expect(draftBox.x).toBeGreaterThanOrEqual(activityBox.x + activityBox.width);
77-
await captureUiProof(page, "draft-indicator-active.png");
78-
79-
await secondRow.getByRole("link").click();
80-
await expect.poll(() => new URL(page.url()).pathname).toBe(controlUiSessionPath(secondKey));
81-
await draft.waitFor();
82-
83-
await homeRow.click();
84-
await waitForControlUiRoute(page, {
85-
pathname: controlUiSessionPath(mainKey),
86-
routeId: "chat",
87-
});
88-
await draft.waitFor();
89-
const presentedPanes = page.locator('openclaw-chat-pane[aria-hidden="false"]');
90-
await expect
91-
.poll(() =>
92-
presentedPanes.evaluateAll((panes) =>
93-
panes.map((pane) => (pane as ChatPaneElement).sessionKey),
94-
),
95-
)
96-
.toEqual([mainKey]);
97-
98-
await composer.fill("");
99-
await secondRow.getByRole("link").click();
100-
await expect.poll(() => new URL(page.url()).pathname).toBe(controlUiSessionPath(secondKey));
101-
await expect.poll(() => draft.count()).toBe(0);
102-
} finally {
103-
await context.close();
104-
}
105-
});
106-
10728
it("expands and manages child sessions inline before opening a child chat", async () => {
10829
const baseTime = Date.parse("2026-07-01T16:00:00.000Z");
10930
const parentKey = "agent:main:release-plan";

0 commit comments

Comments
 (0)