Skip to content

Commit 2627d5d

Browse files
matt2eclaude
andcommitted
test(messages): pin the workflow card's click, focus and patient-click paths
Addresses review of a06c980 on the workflow ⓘ card tests. The click-open check used user.click and findByRole. user.click moves the pointer onto the trigger, which starts the 300 ms preview rest timer, and findByRole polls for a second, so the hover could open the card even if the click did nothing. With user.hover in place of the click, the old check still passed. The test now opens the card with fireEvent.click, which moves no pointer, and finds the card synchronously. The hover test checked that focus was outside the card, which would also pass if a hover open moved focus to the trigger. It now records the focused element before the hover and asserts it is unchanged. The hover test also pins Base UI's patient-click window. A click within 500 ms of a hover open keeps the card open. A click after that toggles it closed. This matches every other openOnHover="preview" popover, so the card keeps the library behaviour rather than overriding it. Each new assertion fails when its behaviour breaks: a blocked Base UI click handler, a focus move during hover, and a click at 499 ms. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Matt Toohey <[email protected]>
1 parent a06c980 commit 2627d5d

1 file changed

Lines changed: 17 additions & 4 deletions

File tree

‎src/features/messages/MessageRow.test.tsx‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2370,9 +2370,10 @@ it("presents automation, links the owner and explains the message without keys",
23702370
await user.keyboard("{Escape}");
23712371
await waitFor(() => expect(screen.queryByRole("dialog")).toBeNull());
23722372
expect(trigger).toHaveFocus();
2373-
await user.click(trigger);
2373+
// fireEvent moves no pointer, so no hover rest timer can open the card.
2374+
fireEvent.click(trigger);
23742375
expect(
2375-
await screen.findByRole("dialog", { name: "Workflow message" }),
2376+
screen.getByRole("dialog", { name: "Workflow message" }),
23762377
).toBeInTheDocument();
23772378
} finally {
23782379
cleanup();
@@ -2383,15 +2384,16 @@ it("opens workflow message details once the pointer rests, without a competing h
23832384
vi.useFakeTimers();
23842385
try {
23852386
const { trigger } = renderWorkflowMessage();
2387+
const focused = document.activeElement;
23862388
fireEvent.mouseEnter(trigger);
23872389
fireEvent.mouseMove(trigger);
23882390
await act(() => vi.advanceTimersByTimeAsync(PREVIEW_REST_MS - 1));
23892391
expect(screen.queryByRole("dialog")).toBeNull();
23902392
await act(() => vi.advanceTimersByTimeAsync(1));
2391-
const card = screen.getByRole("dialog", { name: "Workflow message" });
2393+
screen.getByRole("dialog", { name: "Workflow message" });
23922394
expect(screen.queryByRole("tooltip")).toBeNull();
23932395
// A hover heads-up leaves focus where the reader had it.
2394-
expect(card).not.toContainElement(document.activeElement as HTMLElement);
2396+
expect(document.activeElement).toBe(focused);
23952397
// Clicking the trigger that just opened it keeps it open.
23962398
fireEvent.click(trigger);
23972399
await act(() => vi.advanceTimersByTimeAsync(PREVIEW_REST_MS));
@@ -2403,6 +2405,17 @@ it("opens workflow message details once the pointer rests, without a competing h
24032405
});
24042406
await act(() => vi.advanceTimersByTimeAsync(PREVIEW_REST_MS));
24052407
expect(screen.queryByRole("dialog")).toBeNull();
2408+
// Past Base UI's 500 ms patient-click window, a click toggles a
2409+
// hover-opened card closed, as with every openOnHover="preview" popover.
2410+
fireEvent.mouseLeave(trigger);
2411+
fireEvent.mouseEnter(trigger);
2412+
fireEvent.mouseMove(trigger);
2413+
await act(() => vi.advanceTimersByTimeAsync(PREVIEW_REST_MS));
2414+
screen.getByRole("dialog", { name: "Workflow message" });
2415+
await act(() => vi.advanceTimersByTimeAsync(500));
2416+
fireEvent.click(trigger);
2417+
await act(() => vi.advanceTimersByTimeAsync(PREVIEW_REST_MS));
2418+
expect(screen.queryByRole("dialog")).toBeNull();
24062419
} finally {
24072420
cleanup();
24082421
vi.useRealTimers();

0 commit comments

Comments
 (0)