@@ -9,6 +9,7 @@ import { Markdown } from './Markdown';
99const mocks = vi . hoisted ( ( ) => ( {
1010 getCurrentWorkspacePath : vi . fn ( ) ,
1111 revealInExplorer : vi . fn ( ) ,
12+ readFileContent : vi . fn ( ) ,
1213 openExternal : vi . fn ( ) ,
1314 renderMath : vi . fn ( ) ,
1415} ) ) ;
@@ -19,7 +20,7 @@ vi.mock('../../../infrastructure/api', () => ({
1920 } ,
2021 workspaceAPI : {
2122 revealInExplorer : ( ...args : unknown [ ] ) => mocks . revealInExplorer ( ...args ) ,
22- readFileContent : vi . fn ( ) ,
23+ readFileContent : ( ... args : unknown [ ] ) => mocks . readFileContent ( ... args ) ,
2324 } ,
2425 systemAPI : {
2526 openExternal : ( ...args : unknown [ ] ) => mocks . openExternal ( ...args ) ,
@@ -98,9 +99,11 @@ describe('Markdown file links', () => {
9899 onFileViewRequest = vi . fn ( ) ;
99100 mocks . getCurrentWorkspacePath . mockReset ( ) ;
100101 mocks . revealInExplorer . mockReset ( ) ;
102+ mocks . readFileContent . mockReset ( ) ;
101103 mocks . openExternal . mockReset ( ) ;
102104 mocks . renderMath . mockReset ( ) ;
103105 mocks . getCurrentWorkspacePath . mockResolvedValue ( EXAMPLE_WORKSPACE ) ;
106+ mocks . readFileContent . mockResolvedValue ( 'cmVsdS1wbmc=' ) ;
104107 } ) ;
105108
106109 afterEach ( ( ) => {
@@ -228,4 +231,24 @@ describe('Markdown file links', () => {
228231 expect ( container . querySelector ( '[data-testid="markdown-math-renderer"]' ) ) . not . toBeNull ( ) ;
229232 expect ( mocks . renderMath ) . toHaveBeenCalledWith ( 'Formula: $x + y$' ) ;
230233 } ) ;
234+
235+ it ( 'loads relative markdown images from the provided base path' , async ( ) => {
236+ await act ( async ( ) => {
237+ root . render (
238+ < Markdown
239+ content = { '' }
240+ basePath = { EXAMPLE_WORKSPACE }
241+ onFileViewRequest = { onFileViewRequest }
242+ /> ,
243+ ) ;
244+ await Promise . resolve ( ) ;
245+ await Promise . resolve ( ) ;
246+ } ) ;
247+
248+ const image = container . querySelector < HTMLImageElement > ( 'img[alt="ReLU 图像"]' ) ;
249+ expect ( image ) . not . toBeNull ( ) ;
250+ expect ( mocks . readFileContent ) . toHaveBeenCalledWith ( `${ EXAMPLE_WORKSPACE } /relu.png` ) ;
251+ expect ( image ?. src ) . toBe ( 'data:image/png;base64,cmVsdS1wbmc=' ) ;
252+ expect ( mocks . getCurrentWorkspacePath ) . not . toHaveBeenCalled ( ) ;
253+ } ) ;
231254} ) ;
0 commit comments