fix(webui): retain history touch gestures across message replacement
This commit is contained in:
1 parent
927eba89ea
commit
b07b3eac24
2 files changed
+178
-11
No files matched your search
@@ -421,6 +421,136 @@ test("touch reveals a static partial ready header, arms only on release, and ret
|
||||
} finally { await context.close(); }
|
||||
});
|
||||
|
||||
for (const replacement of ["before move", "before release", "before cancel"] as const) {
|
||||
test(`history touch continues when the touched message is replaced ${replacement}`, async ({ browser, baseURL }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true, baseURL });
|
||||
const page = await context.newPage();
|
||||
const history = await installHistory(page);
|
||||
let allowRenderer = () => {};
|
||||
let rendererRequested = () => {};
|
||||
const rendererGate = new Promise<void>((resolve) => { allowRenderer = resolve; });
|
||||
const requested = new Promise<void>((resolve) => { rendererRequested = resolve; });
|
||||
await page.route("**/src/components/MarkdownTextRenderer.tsx*", async (route) => {
|
||||
rendererRequested();
|
||||
await rendererGate;
|
||||
await route.continue();
|
||||
});
|
||||
try {
|
||||
const { body, header } = await openSettledHistory(page);
|
||||
await positionAtTop(body);
|
||||
await stableLayout(body);
|
||||
await requested;
|
||||
const fallback = body.locator('[data-assistant-selectable="true"] > .whitespace-pre-wrap:visible').first();
|
||||
await expect(fallback).toBeVisible();
|
||||
await expect(fallback).toContainText("Historical answer.");
|
||||
const target = await fallback.elementHandle();
|
||||
const box = await target?.boundingBox();
|
||||
if (!target || !box) throw new Error("The Markdown fallback must be visible before the touch gesture");
|
||||
const x = box.x + Math.min(50, box.width / 2), y = box.y + Math.min(10, box.height / 2);
|
||||
expect(await target.evaluate((node, point) => document.elementFromPoint(point.x, point.y) === node, { x, y })).toBe(true);
|
||||
const cdp = await context.newCDPSession(page);
|
||||
const touch = (type: "touchStart" | "touchMove" | "touchEnd" | "touchCancel", touchY = y) => cdp.send("Input.dispatchTouchEvent", {
|
||||
type, touchPoints: type === "touchEnd" || type === "touchCancel" ? [] : [{ x, y: touchY, id: 1 }],
|
||||
});
|
||||
await touch("touchStart");
|
||||
if (replacement !== "before move") {
|
||||
await touch("touchMove", y + (replacement === "before cancel" ? 200 : 40));
|
||||
if (replacement === "before cancel") expect(await displacement(body)).toBeGreaterThanOrEqual(56);
|
||||
else expect(await displacement(body)).toBeGreaterThan(0);
|
||||
expect(history.reads).toHaveLength(0);
|
||||
}
|
||||
allowRenderer();
|
||||
await expect.poll(() => target.evaluate((node) => node?.isConnected)).toBe(false);
|
||||
if (replacement === "before move") {
|
||||
await touch("touchMove", y + 200);
|
||||
expect(await displacement(body)).toBeGreaterThanOrEqual(56);
|
||||
expect(history.reads).toHaveLength(0);
|
||||
}
|
||||
await touch(replacement === "before cancel" ? "touchCancel" : "touchEnd");
|
||||
if (replacement !== "before move") {
|
||||
await expect.poll(() => displacement(body)).toBe(0);
|
||||
await expect(header).not.toBeInViewport();
|
||||
expect(history.reads).toHaveLength(0);
|
||||
}
|
||||
if (replacement === "before cancel") {
|
||||
// Cancellation must not leave a stale gesture that prevents the next pull.
|
||||
await touch("touchStart");
|
||||
await touch("touchMove", y + 200);
|
||||
expect(await displacement(body)).toBeGreaterThanOrEqual(56);
|
||||
expect(history.reads).toHaveLength(0);
|
||||
await touch("touchEnd");
|
||||
}
|
||||
if (replacement !== "before release") {
|
||||
await expect.poll(() => history.reads.length).toBe(1);
|
||||
await expect(header).toHaveAttribute("data-state", "loading");
|
||||
history.complete();
|
||||
}
|
||||
await target.dispose();
|
||||
} finally {
|
||||
allowRenderer();
|
||||
await context.close();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
test("a second finger cancels an active history pull without loading", async ({ browser, baseURL }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true, baseURL });
|
||||
const page = await context.newPage();
|
||||
const history = await installHistory(page);
|
||||
try {
|
||||
const { body, header } = await openSettledHistory(page);
|
||||
await positionAtTop(body);
|
||||
const cdp = await context.newCDPSession(page);
|
||||
const dispatch = (type: "touchStart" | "touchMove" | "touchEnd", touchPoints: { id: number; x: number; y: number }[]) =>
|
||||
cdp.send("Input.dispatchTouchEvent", { type, touchPoints });
|
||||
await dispatch("touchStart", [{ id: 1, x: 180, y: 200 }]);
|
||||
await dispatch("touchMove", [{ id: 1, x: 180, y: 240 }]);
|
||||
expect(await displacement(body)).toBeGreaterThan(0);
|
||||
await dispatch("touchStart", [{ id: 1, x: 180, y: 240 }, { id: 2, x: 220, y: 240 }]);
|
||||
await expect.poll(() => displacement(body)).toBe(0);
|
||||
await expect(header).not.toBeInViewport();
|
||||
expect(history.reads).toHaveLength(0);
|
||||
await dispatch("touchEnd", []);
|
||||
await dispatch("touchStart", [{ id: 1, x: 180, y: 200 }]);
|
||||
await dispatch("touchMove", [{ id: 1, x: 180, y: 400 }]);
|
||||
expect(await displacement(body)).toBeGreaterThanOrEqual(56);
|
||||
await dispatch("touchEnd", []);
|
||||
await expect.poll(() => history.reads.length).toBe(1);
|
||||
history.complete();
|
||||
} finally { await context.close(); }
|
||||
});
|
||||
|
||||
test("switching conversations cancels an in-progress history pull", async ({ browser, baseURL }) => {
|
||||
const context = await browser.newContext({ viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true, baseURL });
|
||||
const page = await context.newPage();
|
||||
const history = await installHistory(page);
|
||||
try {
|
||||
const { body } = await openSettledHistory(page);
|
||||
await positionAtTop(body);
|
||||
const cdp = await context.newCDPSession(page);
|
||||
const touch = (type: "touchStart" | "touchMove" | "touchEnd", y = 200) => cdp.send("Input.dispatchTouchEvent", {
|
||||
type, touchPoints: type === "touchEnd" ? [] : [{ id: 1, x: 180, y }],
|
||||
});
|
||||
await touch("touchStart");
|
||||
await touch("touchMove", 240);
|
||||
expect(await displacement(body)).toBeGreaterThan(0);
|
||||
await page.getByRole("button", { name: "Switch conversation" }).click();
|
||||
await expect(body.getByText("Question 1", { exact: true })).toBeVisible();
|
||||
await touch("touchEnd");
|
||||
await expect.poll(() => displacement(body)).toBe(0);
|
||||
expect(history.reads).toHaveLength(0);
|
||||
await page.getByRole("button", { name: "Switch conversation" }).click();
|
||||
await expect(body.getByText("Question 40", { exact: true })).toBeVisible();
|
||||
await positionAtTop(body);
|
||||
await touch("touchStart");
|
||||
await touch("touchMove", 400);
|
||||
expect(await displacement(body)).toBeGreaterThanOrEqual(56);
|
||||
await touch("touchEnd");
|
||||
await expect.poll(() => history.reads.length).toBe(1);
|
||||
history.complete();
|
||||
} finally { await context.close(); }
|
||||
});
|
||||
|
||||
test("reduced-motion failure keeps its functional 48px slot and retry until naturally scrolled away", async ({ page }) => {
|
||||
await page.emulateMedia({ reducedMotion: "reduce", colorScheme: "dark" });
|
||||
const history = await installHistory(page);
|
||||
|
||||
Reference in new issue
Block a user