@@ -746,10 +746,9 @@ describe('FileBrowser', () => {
746746 } ) ;
747747 } ) ;
748748
749- it ( 'pushes loaded preview state updates for externally hosted change previews ' , async ( ) => {
749+ it ( 'does not start local preview fetches when using an external preview host ' , async ( ) => {
750750 const { ws, respond, sendMsg } = makeWsFactory ( ) ;
751751 const onPreviewFile = vi . fn ( ) ;
752- const onPreviewStateChange = vi . fn ( ) ;
753752 render (
754753 < FileBrowser
755754 ws = { ws }
@@ -758,7 +757,6 @@ describe('FileBrowser', () => {
758757 initialPath = "/home/user"
759758 changesRootPath = "/home/user"
760759 onPreviewFile = { onPreviewFile }
761- onPreviewStateChange = { onPreviewStateChange }
762760 onConfirm = { vi . fn ( ) }
763761 /> ,
764762 ) ;
@@ -781,28 +779,13 @@ describe('FileBrowser', () => {
781779 const changeItem = document . querySelector ( '.fb-changes-item' ) as HTMLElement ;
782780 await act ( async ( ) => { fireEvent . click ( changeItem ) ; } ) ;
783781
784- expect ( ( ws . fsReadFile as any ) . mock . calls ) . toHaveLength ( 1 ) ;
785- expect ( ( ws . fsGitDiff as any ) . mock . calls ) . toHaveLength ( 1 ) ;
782+ expect ( ( ws . fsReadFile as any ) . mock . calls ) . toHaveLength ( 0 ) ;
783+ expect ( ( ws . fsGitDiff as any ) . mock . calls ) . toHaveLength ( 0 ) ;
786784 expect ( onPreviewFile ) . toHaveBeenLastCalledWith ( {
787785 path : '/home/user/foo.ts' ,
788786 preferDiff : true ,
789787 preview : { status : 'loading' , path : '/home/user/foo.ts' } ,
790788 } ) ;
791-
792- await act ( async ( ) => {
793- sendMsg ( { type : 'fs.read_response' , requestId : 'mock-read-id' , path : '/home/user/foo.ts' , status : 'ok' , content : 'const x = 1;' } ) ;
794- sendMsg ( { type : 'fs.git_diff_response' , requestId : 'mock-git-diff-id' , path : '/home/user/foo.ts' , status : 'ok' , diff : '+const x = 1;' } ) ;
795- } ) ;
796-
797- expect ( onPreviewStateChange ) . toHaveBeenCalledWith ( expect . objectContaining ( {
798- path : '/home/user/foo.ts' ,
799- preferDiff : true ,
800- preview : expect . objectContaining ( {
801- status : 'ok' ,
802- path : '/home/user/foo.ts' ,
803- content : 'const x = 1;' ,
804- } ) ,
805- } ) ) ;
806789 } ) ;
807790
808791 it ( 'does not render an inline preview when an external preview host is provided' , async ( ) => {
@@ -837,10 +820,6 @@ describe('FileBrowser', () => {
837820
838821 const changeItem = document . querySelector ( '.fb-changes-item' ) as HTMLElement ;
839822 await act ( async ( ) => { fireEvent . click ( changeItem ) ; } ) ;
840- await act ( async ( ) => {
841- sendMsg ( { type : 'fs.read_response' , requestId : 'mock-read-id' , path : '/home/user/foo.ts' , status : 'ok' , content : 'const x = 1;' } ) ;
842- sendMsg ( { type : 'fs.git_diff_response' , requestId : 'mock-git-diff-id' , path : '/home/user/foo.ts' , status : 'ok' , diff : '+const x = 1;' } ) ;
843- } ) ;
844823
845824 expect ( onPreviewFile ) . toHaveBeenCalled ( ) ;
846825 expect ( document . querySelector ( '.fb-preview' ) ) . toBeNull ( ) ;
@@ -900,6 +879,27 @@ describe('FileBrowser', () => {
900879 expect ( ( ws . fsGitDiff as any ) . mock . calls ) . toHaveLength ( 0 ) ;
901880 } ) ;
902881
882+ it ( 'fetches preview data when a floating preview is hydrated with a loading state' , ( ) => {
883+ const { ws } = makeWsFactory ( ) ;
884+ render (
885+ < FileBrowser
886+ ws = { ws }
887+ mode = "file-single"
888+ layout = "panel"
889+ initialPath = "/home/user"
890+ initialPreview = { { status : 'loading' , path : '/home/user/foo.ts' } }
891+ autoPreviewPath = "/home/user/foo.ts"
892+ autoPreviewPreferDiff
893+ onConfirm = { vi . fn ( ) }
894+ /> ,
895+ ) ;
896+
897+ expect ( ( ws . fsReadFile as any ) . mock . calls ) . toHaveLength ( 1 ) ;
898+ expect ( ( ws . fsGitDiff as any ) . mock . calls ) . toHaveLength ( 1 ) ;
899+ expect ( ( ws . fsReadFile as any ) . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( '/home/user/foo.ts' ) ;
900+ expect ( ( ws . fsGitDiff as any ) . mock . calls [ 0 ] ?. [ 0 ] ) . toBe ( '/home/user/foo.ts' ) ;
901+ } ) ;
902+
903903 it ( 'does not immediately reopen an auto-preview after the preview close button is pressed' , async ( ) => {
904904 const { ws } = makeWsFactory ( ) ;
905905 const onClose = vi . fn ( ) ;
0 commit comments