@@ -15,6 +15,7 @@ vi.mock(import("~/state/assets"), async (original) => {
1515 return AsyncResult . success ( {
1616 relativeUrl : `data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7#${ assetQuery . mints } ` ,
1717 expiresAt : Number . MAX_SAFE_INTEGER ,
18+ fileRevision : String ( assetQuery . mints ) ,
1819 } ) ;
1920 } ) . pipe ( Atom . keepAlive ) ,
2021 ) ;
@@ -60,37 +61,59 @@ function setup() {
6061}
6162
6263describe ( "ChatMarkdownAssetImage" , ( ) => {
63- it ( "refreshes repeated local images together after a new chat revision" , async ( ) => {
64- setup ( ) ;
65- const images = ( revision : string ) => (
66- < WorkspaceMutationIdContext value = { revision } >
67- { [ "first" , "second" ] . map ( ( alt ) => (
68- < ChatMarkdownAssetImage
69- key = { alt }
70- environmentId = { EnvironmentId . make ( "environment-1" ) }
71- resource = { {
72- _tag : "media-file" ,
73- threadId : ThreadId . make ( "thread-1" ) ,
74- path : "/tmp/render.png" ,
75- } }
76- alt = { alt }
77- />
78- ) ) }
79- </ WorkspaceMutationIdContext >
80- ) ;
81- await using screen = await render ( images ( "message-1" ) ) ;
82- using errors = vi . spyOn ( console , "error" ) ;
83- await vi . waitFor ( ( ) => expect ( assetQuery . mints ) . toBe ( 2 ) ) ;
84- const previousSrc = screen . getByRole ( "img" , { name : "first" } ) . element ( ) . getAttribute ( "src" ) ;
64+ it . each ( [ "image" , "video" ] as const ) (
65+ "refreshes repeated local %s embeds together after a new chat revision" ,
66+ async ( kind ) => {
67+ setup ( ) ;
68+ const images = ( revision : string ) => (
69+ < WorkspaceMutationIdContext value = { revision } >
70+ { [ "first" , "second" ] . map ( ( alt ) => (
71+ < ChatMarkdownAssetImage
72+ key = { alt }
73+ kind = { kind }
74+ environmentId = { EnvironmentId . make ( "environment-1" ) }
75+ resource = { {
76+ _tag : "media-file" ,
77+ threadId : ThreadId . make ( "thread-1" ) ,
78+ path : `/tmp/render.${ kind === "video" ? "mp4" : "png" } ` ,
79+ } }
80+ alt = { alt }
81+ />
82+ ) ) }
83+ </ WorkspaceMutationIdContext >
84+ ) ;
85+ await using screen = await render ( images ( "message-1" ) ) ;
86+ using errors = vi . spyOn ( console , "error" ) ;
87+ await vi . waitFor ( ( ) => expect ( assetQuery . mints ) . toBe ( 2 ) ) ;
88+ const previousSrc = (
89+ kind === "image"
90+ ? screen . getByRole ( "img" , { name : "first" } )
91+ : screen . getByLabelText ( "first" , { exact : true } )
92+ )
93+ . element ( )
94+ . getAttribute ( "src" ) ;
8595
86- await screen . rerender ( images ( "message-2" ) ) ;
87- await vi . waitFor ( ( ) => expect ( assetQuery . mints ) . toBe ( 3 ) ) ;
88- const first = screen . getByRole ( "img" , { name : "first" } ) ;
89- const second = screen . getByRole ( "img" , { name : "second" } ) ;
90- await expect . element ( first ) . not . toHaveAttribute ( "src" , previousSrc ) ;
91- await expect . element ( second ) . toHaveAttribute ( "src" , first . element ( ) . getAttribute ( "src" ) ) ;
92- expect ( errors ) . not . toHaveBeenCalled ( ) ;
93- } ) ;
96+ if ( kind === "video" ) {
97+ for ( const video of document . querySelectorAll ( "video" ) ) {
98+ video . dispatchEvent ( new Event ( "loadedmetadata" ) ) ;
99+ }
100+ }
101+
102+ await screen . rerender ( images ( "message-2" ) ) ;
103+ await vi . waitFor ( ( ) => expect ( assetQuery . mints ) . toBe ( 3 ) ) ;
104+ const first =
105+ kind === "image"
106+ ? screen . getByRole ( "img" , { name : "first" } )
107+ : screen . getByLabelText ( "first" , { exact : true } ) ;
108+ const second =
109+ kind === "image"
110+ ? screen . getByRole ( "img" , { name : "second" } )
111+ : screen . getByLabelText ( "second" , { exact : true } ) ;
112+ await expect . element ( first ) . not . toHaveAttribute ( "src" , previousSrc ) ;
113+ await expect . element ( second ) . toHaveAttribute ( "src" , first . element ( ) . getAttribute ( "src" ) ) ;
114+ expect ( errors ) . not . toHaveBeenCalled ( ) ;
115+ } ,
116+ ) ;
94117
95118 it ( "does not re-mint an unchanged workspace image's URL on remount" , async ( ) => {
96119 setup ( ) ;
0 commit comments