Skip to content

Commit 80dcd72

Browse files
committed
test(ui): make session hovercard timing deterministic
1 parent 327d805 commit 80dcd72

1 file changed

Lines changed: 33 additions & 13 deletions

File tree

‎ui/src/e2e/session-progress-hovercard.e2e.test.ts‎

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
controlUiSessionUrl,
1212
createChatFlowE2eSuite,
1313
installMockGateway,
14+
pauseVirtualClock,
1415
} from "./chat-flow.test-support.ts";
1516

1617
const proofDir = path.join(
@@ -536,6 +537,8 @@ suite.define(() => {
536537
viewport: { height: 900, width: 1280 },
537538
},
538539
async ({ page }) => {
540+
// Browser RPC time must not consume the hover-delay assertion windows.
541+
await page.clock.install();
539542
await installMockGateway(page, {
540543
featureMethods: ["chat.metadata", "chat.startup", "progressCard.get"],
541544
methodResponses: {
@@ -559,6 +562,7 @@ suite.define(() => {
559562
() => customElements.get("openclaw-session-progress-hovercard-provider") === undefined,
560563
),
561564
).toBe(true);
565+
await pauseVirtualClock(page);
562566

563567
const pointer = async (
564568
locator: typeof first,
@@ -574,9 +578,11 @@ suite.define(() => {
574578
});
575579

576580
await first.hover();
581+
await expect.poll(() => first.getAttribute("aria-haspopup")).toBe("dialog");
577582
expect(await card.count()).toBe(0);
578-
await page.waitForTimeout(300);
583+
await page.clock.runFor(449);
579584
expect(await card.count()).toBe(0);
585+
await page.clock.runFor(1);
580586
await card.waitFor({ state: "visible" });
581587
const firstBounds = await first.boundingBox();
582588
expect(firstBounds).not.toBeNull();
@@ -586,50 +592,64 @@ suite.define(() => {
586592
clientX: (firstBounds?.x ?? 0) + (firstBounds?.width ?? 0),
587593
clientY: (firstBounds?.y ?? 0) + (firstBounds?.height ?? 0) / 2,
588594
});
589-
await page.waitForTimeout(150);
595+
await page.clock.runFor(219);
590596
expect(await card.count()).toBe(1);
591597
await page.mouse.move(
592598
(cardBounds?.x ?? 0) + (cardBounds?.width ?? 0) / 2,
593599
(cardBounds?.y ?? 0) + (cardBounds?.height ?? 0) / 2,
594600
);
601+
await page.clock.runFor(1);
595602
expect(await card.count()).toBe(1);
596603
await page.mouse.move(900, 800);
597-
await page.waitForTimeout(50);
604+
await page.clock.runFor(99);
598605
expect(await card.count()).toBe(1);
599-
await expect.poll(() => card.count()).toBe(0);
600-
await page.waitForTimeout(300);
606+
await page.clock.runFor(1);
607+
expect(
608+
await card.evaluateAll((cards) =>
609+
cards.every((element) => element.getAttribute("data-open") === "false"),
610+
),
611+
).toBe(true);
612+
await page.clock.runFor(300);
613+
expect(await card.count()).toBe(0);
601614

602615
await first.hover();
603616
await first.locator("a.sidebar-recent-session__link").focus();
617+
await page.clock.runFor(1);
604618
await card.waitFor({ state: "visible" });
605619
await expect
606620
.poll(() => card.locator(".session-hovercard__title").textContent())
607621
.toBe("First timing row");
608622
await page.keyboard.press("Escape");
609623
await expect.poll(() => card.count()).toBe(0);
610624
await page.mouse.move(900, 800);
611-
await page.waitForTimeout(300);
625+
await page.clock.runFor(300);
612626

613627
await first.hover();
614628
expect(await card.count()).toBe(0);
629+
await page.clock.runFor(449);
630+
expect(await card.count()).toBe(0);
631+
await page.clock.runFor(1);
615632
await card.waitFor({ state: "visible" });
616633

617634
await second.hover();
618-
await page.waitForTimeout(40);
635+
await page.clock.runFor(79);
619636
expect(await card.locator(".session-hovercard__title").textContent()).toBe(
620637
"First timing row",
621638
);
622-
await expect
623-
.poll(() => card.locator(".session-hovercard__title").textContent())
624-
.toBe("Second timing row");
639+
await page.clock.runFor(1);
640+
expect(await card.locator(".session-hovercard__title").textContent()).toBe(
641+
"Second timing row",
642+
);
625643

626644
await card.hover();
627645
expect(await card.count()).toBe(1);
628646
await page.mouse.move(900, 800);
629-
await expect.poll(() => card.count()).toBe(0);
630-
await page.waitForTimeout(300);
647+
await page.clock.runFor(100);
648+
await page.clock.runFor(300);
649+
expect(await card.count()).toBe(0);
631650

632651
await first.hover();
652+
await page.clock.runFor(450);
633653
await card.waitFor({ state: "visible" });
634654
await first
635655
.getByRole("button", { name: "Open session menu: First timing row" })
@@ -639,7 +659,7 @@ suite.define(() => {
639659
.poll(() => page.locator("openclaw-session-menu").getByRole("menuitem").count())
640660
.toBeGreaterThan(0);
641661
await second.dispatchEvent("pointerover", { pointerType: "mouse" });
642-
await page.waitForTimeout(500);
662+
await page.clock.runFor(500);
643663
expect(await card.count()).toBe(0);
644664
},
645665
);

0 commit comments

Comments
 (0)