fix(webui): keep Dock taps working after touch drags
This commit is contained in:
1 parent
e981e97f10
commit
02c364428a
2 files changed
+66
-1
No files matched your search
@@ -484,6 +484,59 @@ test("follows the mouse before release and snaps without double toggling", async
|
||||
|
||||
test.describe("touch task drawer", () => {
|
||||
test.use({ hasTouch: true, isMobile: true, viewport: { width: 390, height: 844 } });
|
||||
test("keeps native taps working after a fast handle drag", async ({ page }) => {
|
||||
await page.goto("/browser/fixture.html?case=subagent-dock");
|
||||
await page.getByRole("button", { name: "增加任务", exact: true }).click();
|
||||
const trigger = page.getByTestId("subagent-task-dock-trigger");
|
||||
const tree = page.getByTestId("subagent-task-tree");
|
||||
const events = await trigger.evaluateHandle(node => {
|
||||
const records: { type: string; prevented: boolean }[] = [];
|
||||
for (const type of ["touchstart", "touchmove", "click"]) {
|
||||
node.addEventListener(type, event => records.push({ type, prevented: event.defaultPrevented }));
|
||||
}
|
||||
return records;
|
||||
});
|
||||
const cdp = await page.context().newCDPSession(page);
|
||||
try {
|
||||
const closed = (await trigger.boundingBox())!;
|
||||
const x = closed.x + closed.width / 2;
|
||||
const y = closed.y + closed.height / 2;
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", touchPoints: [{ x, y }] });
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchMove", touchPoints: [{ x: x + 2, y: y + 2 }] });
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", touchPoints: [] });
|
||||
await expect(tree.locator("[data-subagent-id]")).toHaveCount(23);
|
||||
expect((await events.jsonValue()).filter(event => event.type === "click")).toHaveLength(1);
|
||||
await settledMotion(page.getByTestId("subagent-task-dock"));
|
||||
await events.evaluate(records => { records.length = 0; });
|
||||
|
||||
const bounds = (await trigger.boundingBox())!;
|
||||
const dragX = bounds.x + bounds.width / 2;
|
||||
const dragY = bounds.y + bounds.height / 2;
|
||||
// Define a fast release independently of CDP round-trip and screenshot timing.
|
||||
const timestamp = (Date.now() - 35) / 1000;
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchStart", timestamp, touchPoints: [{ x: dragX, y: dragY }] });
|
||||
for (let step = 1; step <= 6; step++) {
|
||||
await cdp.send("Input.dispatchTouchEvent", {
|
||||
type: "touchMove", timestamp: timestamp + step * 0.005,
|
||||
touchPoints: [{ x: dragX, y: dragY + step * 10 }],
|
||||
});
|
||||
}
|
||||
await cdp.send("Input.dispatchTouchEvent", { type: "touchEnd", timestamp: timestamp + 0.035, touchPoints: [] });
|
||||
await expect(tree).toHaveCount(0);
|
||||
await trigger.tap();
|
||||
await expect(tree.locator("[data-subagent-id]")).toHaveCount(23);
|
||||
const records = await events.jsonValue();
|
||||
expect(records.filter(event => event.type === "click")).toHaveLength(1);
|
||||
expect(records.filter(event => event.type === "touchstart").every(event => !event.prevented)).toBe(true);
|
||||
const moves = records.filter(event => event.type === "touchmove");
|
||||
expect(moves.length).toBeGreaterThan(0);
|
||||
expect(moves.every(event => event.prevented)).toBe(true);
|
||||
} finally {
|
||||
await events.dispose();
|
||||
await cdp.detach();
|
||||
}
|
||||
});
|
||||
|
||||
test("follows touch movement, restores a cancelled drag, and keeps list scrolling independent", async ({ page }, info) => {
|
||||
await page.goto("/browser/fixture.html?case=subagent-dock");
|
||||
const trigger = page.getByTestId("subagent-task-dock-trigger");
|
||||
|
||||
Reference in new issue
Block a user