1+ import "../../index.css" ;
2+
13import { EnvironmentId , type ProjectEntry } from "@t3tools/contracts" ;
24import { act , type ReactNode } from "react" ;
35import { createRoot , type Root } from "react-dom/client" ;
@@ -7,6 +9,8 @@ import FileBrowserPanel from "./FileBrowserPanel";
79
810const files = vi . hoisted ( ( ) => ( {
911 directoryEntries : [ ] as ProjectEntry [ ] ,
12+ directoryReady : true ,
13+ directoryPending : false ,
1014 searchEntries : [ ] as ProjectEntry [ ] ,
1115 searchPending : false ,
1216 searchError : null as string | null ,
@@ -21,9 +25,9 @@ vi.mock("./useDirectoryEntries", () => ({
2125 loadingDirectories : files . loadingDirectories ,
2226 load : files . load ,
2327 refresh : files . refresh ,
24- ready : true ,
28+ ready : files . directoryReady ,
2529 error : null ,
26- isPending : false ,
30+ isPending : files . directoryPending ,
2731 } ) ,
2832} ) ) ;
2933vi . mock ( "~/state/queries" , ( ) => ( {
@@ -101,13 +105,34 @@ describe("Files panel search", () => {
101105 ) ;
102106 }
103107
108+ function expectVisibleLoadingStatus ( ) {
109+ const status = container ! . querySelector < HTMLElement > ( '[role="status"]' ) ;
110+ expect ( status ?. textContent ) . toBe ( "Loading files…" ) ;
111+ expect ( status ! . checkVisibility ( ) ) . toBe ( true ) ;
112+ const bounds = status ! . getBoundingClientRect ( ) ;
113+ expect ( bounds . width ) . toBeGreaterThan ( 1 ) ;
114+ expect ( bounds . height ) . toBeGreaterThan ( 1 ) ;
115+ }
116+
117+ function rowTop ( path : string ) {
118+ const row = container !
119+ . querySelector ( "file-tree-container" )
120+ ?. shadowRoot ! . querySelector ( `[data-item-path="${ CSS . escape ( path ) } "]` ) ;
121+ expect ( row , `visible row ${ path } ` ) . not . toBeNull ( ) ;
122+ const bounds = row ! . getBoundingClientRect ( ) ;
123+ expect ( bounds . height ) . toBeGreaterThan ( 0 ) ;
124+ return bounds . top ;
125+ }
126+
104127 beforeEach ( ( ) => {
105128 vi . stubGlobal ( "IS_REACT_ACT_ENVIRONMENT" , true ) ;
106129 files . directoryEntries = [
107130 { path : "src" , kind : "directory" } ,
108131 { path : "src/app.ts" , kind : "file" } ,
109132 { path : "package.json" , kind : "file" } ,
110133 ] ;
134+ files . directoryReady = true ;
135+ files . directoryPending = false ;
111136 files . searchEntries = [ ] ;
112137 files . searchPending = false ;
113138 files . searchError = null ;
@@ -121,6 +146,41 @@ describe("Files panel search", () => {
121146 vi . unstubAllGlobals ( ) ;
122147 } ) ;
123148
149+ it ( "keeps visible rows stationary during loading while showing initial loading status" , async ( ) => {
150+ const entries = files . directoryEntries ;
151+ files . directoryEntries = [ ] ;
152+ files . directoryReady = false ;
153+ files . directoryPending = true ;
154+ await render ( ) ;
155+ expect ( visiblePaths ( ) ) . toEqual ( [ ] ) ;
156+ expectVisibleLoadingStatus ( ) ;
157+
158+ files . directoryEntries = entries ;
159+ files . directoryReady = true ;
160+ files . directoryPending = false ;
161+ await render ( ) ;
162+ expect ( visiblePaths ( ) ) . toEqual ( [ "src/" , "package.json" ] ) ;
163+ const initialTop = rowTop ( "package.json" ) ;
164+
165+ files . directoryPending = true ;
166+ await render ( ) ;
167+ expect ( rowTop ( "package.json" ) ) . toBe ( initialTop ) ;
168+
169+ files . directoryPending = false ;
170+ await search ( "pack" ) ;
171+ expect ( visiblePaths ( ) ) . toEqual ( [ "package.json" ] ) ;
172+ const filteredTop = rowTop ( "package.json" ) ;
173+
174+ files . searchPending = true ;
175+ await search ( "package" ) ;
176+ expect ( visiblePaths ( ) ) . toEqual ( [ "package.json" ] ) ;
177+ expect ( rowTop ( "package.json" ) ) . toBe ( filteredTop ) ;
178+
179+ files . searchPending = false ;
180+ await render ( ) ;
181+ expect ( rowTop ( "package.json" ) ) . toBe ( filteredTop ) ;
182+ } ) ;
183+
124184 it ( "shows no matching files instead of the full tree when a filename is absent" , async ( ) => {
125185 await render ( ) ;
126186 expect ( visiblePaths ( ) ) . toEqual ( [ "src/" , "package.json" ] ) ;
@@ -150,7 +210,7 @@ describe("Files panel search", () => {
150210 files . searchPending = true ;
151211 await search ( "settings.ts" ) ;
152212 expect ( visiblePaths ( ) ) . toEqual ( [ ] ) ;
153- expect ( hasMessage ( "Loading files…" ) ) . toBe ( true ) ;
213+ expectVisibleLoadingStatus ( ) ;
154214 expect ( hasMessage ( "No matching files." ) ) . toBe ( false ) ;
155215
156216 files . searchEntries = [ { path : "config/settings.ts" , kind : "file" } ] ;
0 commit comments