1+ // @vitest -environment jsdom
2+
13import {
24 ApprovalRequestId ,
35 CheckpointRef ,
46 EnvironmentId ,
57 MessageId ,
8+ ProjectId ,
69 RunId ,
710 ThreadId ,
811} from "@t3tools/contracts" ;
@@ -15,6 +18,7 @@ import {
1518 type ReactElement ,
1619} from "react" ;
1720import { renderToStaticMarkup } from "react-dom/server" ;
21+ import { createRoot } from "react-dom/client" ;
1822import { create , type ReactTestRenderer } from "react-test-renderer" ;
1923import { shouldUseRestingComposerLayout } from "../composerFooterLayout" ;
2024import { useComposerFocusState } from "./useComposerFocusState" ;
@@ -227,6 +231,7 @@ function stubDomGlobals() {
227231 } ;
228232
229233 vi . stubGlobal ( "Element" , ElementStub ) ;
234+ vi . stubGlobal ( "getComputedStyle" , undefined ) ;
230235 vi . stubGlobal ( "localStorage" , {
231236 getItem : ( ) => null ,
232237 setItem : ( ) => { } ,
@@ -256,13 +261,131 @@ function stubDomGlobals() {
256261
257262beforeEach ( stubDomGlobals ) ;
258263beforeAll ( async ( ) => {
259- stubDomGlobals ( ) ;
264+ Object . defineProperty ( window , "matchMedia" , { value : matchMedia , configurable : true } ) ;
260265 ( { MessagesTimeline, resolvePreviewAnnotationImage } = await import ( "./MessagesTimeline" ) ) ;
261266} , 30_000 ) ;
262267
263268const ACTIVE_THREAD_ENVIRONMENT_ID = EnvironmentId . make ( "environment-local" ) ;
264269const MESSAGE_CREATED_AT = "2026-03-17T19:12:28.000Z" ;
265270
271+ describe ( "timeline tooltip scroll dismissal" , ( ) => {
272+ it . each ( [
273+ "hover" ,
274+ "delayed hover" ,
275+ "focus" ,
276+ "hover then focus" ,
277+ "outside timeline" ,
278+ "wheel without scroll" ,
279+ "pr hover" ,
280+ "pr delayed hover" ,
281+ "pr focus" ,
282+ "pr hover then focus" ,
283+ ] ) ( "handles %s through the real tooltip interactions" , async ( scenario ) => {
284+ const isPullRequest = scenario . startsWith ( "pr " ) ;
285+ const interaction = isPullRequest ? scenario . slice ( 3 ) : scenario ;
286+ vi . unstubAllGlobals ( ) ;
287+ vi . stubGlobal ( "IS_REACT_ACT_ENVIRONMENT" , true ) ;
288+ vi . useFakeTimers ( ) ;
289+ const { Tooltip, TooltipTrigger, TooltipPopup, TooltipScrollDismissArea } =
290+ await vi . importActual < typeof import ( "../ui/tooltip" ) > ( "../ui/tooltip" ) ;
291+ const container = document . createElement ( "div" ) ;
292+ document . body . append ( container ) ;
293+ const root = createRoot ( container ) ;
294+ const onMouseEnter = vi . fn ( ) ;
295+ const query = await import ( "~/state/query" ) ;
296+ const querySpy = isPullRequest
297+ ? vi . spyOn ( query , "useEnvironmentQuery" ) . mockReturnValue ( {
298+ data : null ,
299+ dataUpdatedAt : 0 ,
300+ error : "Pull request not found" ,
301+ failure : null ,
302+ isPending : false ,
303+ isSuccess : false ,
304+ refresh : vi . fn ( ) ,
305+ } )
306+ : null ;
307+ const { PullRequestLinkPreview } = await import ( "../pullRequest/PullRequestLinkPreview" ) ;
308+ const tooltip = isPullRequest ? (
309+ < PullRequestLinkPreview
310+ link = { < button onMouseEnter = { onMouseEnter } > message link</ button > }
311+ originalUrl = "https://example.com"
312+ target = { {
313+ environmentId : ACTIVE_THREAD_ENVIRONMENT_ID ,
314+ input : {
315+ projectId : ProjectId . make ( "project-1" ) ,
316+ repository : "pingdotgg/t3code" ,
317+ number : 1 ,
318+ } ,
319+ } }
320+ />
321+ ) : (
322+ < Tooltip >
323+ < TooltipTrigger delay = { 50 } onMouseEnter = { onMouseEnter } >
324+ message link
325+ </ TooltipTrigger >
326+ < TooltipPopup > https://example.com</ TooltipPopup >
327+ </ Tooltip >
328+ ) ;
329+ try {
330+ await act ( async ( ) => {
331+ root . render (
332+ < >
333+ < TooltipScrollDismissArea >
334+ < div data-testid = "scrollable" >
335+ { interaction === "outside timeline" ? null : tooltip }
336+ </ div >
337+ </ TooltipScrollDismissArea >
338+ { interaction === "outside timeline" ? tooltip : null }
339+ </ > ,
340+ ) ;
341+ } ) ;
342+ const trigger = container . querySelector < HTMLButtonElement > ( "button" ) ! ;
343+ const scrollable = container . querySelector < HTMLElement > ( '[data-testid="scrollable"]' ) ! ;
344+ await act ( async ( ) => {
345+ if ( interaction !== "focus" ) {
346+ trigger . dispatchEvent ( new MouseEvent ( "mouseover" , { bubbles : true } ) ) ;
347+ trigger . dispatchEvent ( new MouseEvent ( "mouseenter" ) ) ;
348+ trigger . dispatchEvent ( new MouseEvent ( "mousemove" , { bubbles : true } ) ) ;
349+ }
350+ if ( interaction === "focus" || interaction === "hover then focus" ) {
351+ document . dispatchEvent ( new KeyboardEvent ( "keydown" , { key : "Tab" } ) ) ;
352+ trigger . focus ( ) ;
353+ }
354+ if ( interaction !== "delayed hover" ) {
355+ await vi . advanceTimersByTimeAsync ( isPullRequest ? 400 : 60 ) ;
356+ }
357+ } ) ;
358+ expect ( onMouseEnter ) . toHaveBeenCalledTimes ( interaction === "focus" ? 0 : 1 ) ;
359+ expect (
360+ document . querySelector ( '[data-slot="tooltip-popup"][data-open]' ) ?. textContent ?? null ,
361+ ) . toBe ( interaction === "delayed hover" ? null : "https://example.com" ) ;
362+
363+ await act ( async ( ) => {
364+ scrollable . dispatchEvent (
365+ interaction === "wheel without scroll"
366+ ? new WheelEvent ( "wheel" , { bubbles : true , deltaY : 100 } )
367+ : new Event ( "scroll" ) ,
368+ ) ;
369+ await vi . advanceTimersByTimeAsync ( isPullRequest ? 1000 : 100 ) ;
370+ } ) ;
371+ expect (
372+ document . querySelector ( '[data-slot="tooltip-popup"][data-open]' ) ?. textContent ?? null ,
373+ ) . toBe (
374+ interaction === "hover" || interaction === "delayed hover" ? null : "https://example.com" ,
375+ ) ;
376+ if ( interaction === "focus" || interaction === "hover then focus" ) {
377+ expect ( document . activeElement ) . toBe ( trigger ) ;
378+ }
379+ } finally {
380+ await act ( async ( ) => root . unmount ( ) ) ;
381+ querySpy ?. mockRestore ( ) ;
382+ container . remove ( ) ;
383+ vi . useRealTimers ( ) ;
384+ vi . unstubAllGlobals ( ) ;
385+ }
386+ } ) ;
387+ } ) ;
388+
266389function buildProps ( ) {
267390 return {
268391 isWorking : false ,
0 commit comments