1+ import { useState } from "react" ;
12import type { SnapShotSource } from "@t3tools/contracts" ;
23import { describe , expect , it , vi } from "vite-plus/test" ;
3- import { userEvent } from "vite-plus/test/browser" ;
4+ import { page , userEvent } from "vite-plus/test/browser" ;
45
56import "~/index.css" ;
67import { render } from "../../../test/render" ;
8+ import { MediaActions } from "../media/MediaActions" ;
9+ import { TooltipScrollDismissArea } from "../ui/tooltip" ;
710import { ExpandedImageDialog } from "./ExpandedImageDialog" ;
811
912const PIXEL =
@@ -19,7 +22,75 @@ const snapShotSource: SnapShotSource = {
1922const D2_SVG =
2023 '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1174 920"><rect width="1174" height="920"/></svg>' ;
2124
25+ function ImagePreviewTimeline ( ) {
26+ const [ open , setOpen ] = useState ( false ) ;
27+ const source = {
28+ kind : "image" as const ,
29+ name : "shot.png" ,
30+ src : PIXEL ,
31+ reference : { kind : "file" as const , path : "/work/shot.png" } ,
32+ } ;
33+ return (
34+ < >
35+ < TooltipScrollDismissArea data-testid = "timeline" className = "mt-16 h-80 overflow-y-auto" >
36+ < MediaActions source = { source } >
37+ < img
38+ src = { PIXEL }
39+ alt = "Timeline image"
40+ width = { 200 }
41+ height = { 200 }
42+ role = "button"
43+ tabIndex = { 0 }
44+ aria-label = "Preview Timeline image"
45+ onClick = { ( ) => setOpen ( true ) }
46+ onKeyDown = { ( event ) => {
47+ if ( event . key === "Enter" || event . key === " " ) {
48+ event . preventDefault ( ) ;
49+ event . stopPropagation ( ) ;
50+ setOpen ( true ) ;
51+ }
52+ } }
53+ />
54+ </ MediaActions >
55+ < div className = "h-[600px]" />
56+ </ TooltipScrollDismissArea >
57+ < button type = "button" > Next timeline action</ button >
58+ { open && (
59+ < ExpandedImageDialog
60+ preview = { { images : [ { src : PIXEL , name : "shot.png" , actionsSource : source } ] , index : 0 } }
61+ onClose = { ( ) => setOpen ( false ) }
62+ />
63+ ) }
64+ </ >
65+ ) ;
66+ }
67+
2268describe ( "ExpandedImageDialog" , ( ) => {
69+ it ( "dismisses the image path tooltip on scroll after returning focus from the preview" , async ( ) => {
70+ await using screen = await render ( < ImagePreviewTimeline /> ) ;
71+ const image = screen . getByRole ( "button" , { name : "Preview Timeline image" } ) ;
72+ await userEvent . click ( image ) ;
73+ await expect . element ( page . getByRole ( "button" , { name : "Close image preview" } ) ) . toHaveFocus ( ) ;
74+ await userEvent . keyboard ( "{Escape}" ) ;
75+ await expect . element ( image ) . toHaveFocus ( ) ;
76+ expect ( image . element ( ) . matches ( ":focus-visible" ) ) . toBe ( false ) ;
77+ await expect . element ( page . getByText ( "/work/shot.png" , { exact : true } ) ) . not . toBeInTheDocument ( ) ;
78+ await userEvent . unhover ( image ) ;
79+ await userEvent . hover ( image ) ;
80+ await expect . element ( page . getByText ( "/work/shot.png" , { exact : true } ) ) . toBeVisible ( ) ;
81+ screen . getByTestId ( "timeline" ) . element ( ) . scrollTop = 20 ;
82+ await expect . element ( page . getByText ( "/work/shot.png" , { exact : true } ) ) . not . toBeInTheDocument ( ) ;
83+ await expect . element ( image ) . toHaveFocus ( ) ;
84+ await userEvent . keyboard ( "{Tab}{Shift>}{Tab}{/Shift}" ) ;
85+ await expect . element ( image ) . toHaveFocus ( ) ;
86+ expect ( image . element ( ) . matches ( ":focus-visible" ) ) . toBe ( true ) ;
87+ await userEvent . keyboard ( "{Enter}" ) ;
88+ await expect . element ( page . getByRole ( "button" , { name : "Close image preview" } ) ) . toHaveFocus ( ) ;
89+ await userEvent . keyboard ( "{Escape}" ) ;
90+ await expect . element ( image ) . toHaveFocus ( ) ;
91+ expect ( image . element ( ) . matches ( ":focus-visible" ) ) . toBe ( true ) ;
92+ } ) ;
93+
2394 it . each ( [ "/work/pipeline.svg" , "/work/diagram#v2.svg" , "/work/diagram?v2.svg" ] ) (
2495 "fits a markdown SVG without intrinsic size to the viewer: %s" ,
2596 async ( path ) => {
0 commit comments