11import { render , screen , fireEvent } from '@testing-library/react' ;
2+ import { createTheme , ThemeProvider } from '@mui/material/styles' ;
23import React from 'react' ;
34import FileTreeContent from '../../../../../src/components/LeftPane/FileTreeContent/FileTreeContent' ;
45
@@ -16,6 +17,25 @@ describe('FileTreeContent', () => {
1617 { 'folder1' : [ { path : 'file1.md' , status : ' ' } , { 'subfolder' : [ { path : 'folder1/subfolder/file2.txt' , status : ' ' } ] } ] } ,
1718 { path : 'file3.js' , status : ' ' } ,
1819 ] ;
20+ const statusFileTree = [
21+ { path : 'modified.md' , status : 'M' } ,
22+ { path : 'untracked.md' , status : '?' } ,
23+ { path : 'added.md' , status : 'A' } ,
24+ { path : 'deleted.md' , status : 'D' } ,
25+ { path : 'renamed.md' , status : 'R' } ,
26+ { path : 'copied.md' , status : 'C' } ,
27+ { path : 'unknown.md' , status : 'X' } ,
28+ ] ;
29+ const theme = createTheme ( {
30+ palette : {
31+ info : { main : 'rgb(1, 2, 3)' } ,
32+ success : { main : 'rgb(4, 5, 6)' } ,
33+ error : { main : 'rgb(7, 8, 9)' } ,
34+ warning : { main : 'rgb(10, 11, 12)' } ,
35+ secondary : { main : 'rgb(13, 14, 15)' } ,
36+ text : { primary : 'rgb(16, 17, 18)' } ,
37+ } ,
38+ } ) ;
1939
2040 test ( 'renders loading spinner when loading is true' , ( ) => {
2141 render (
@@ -61,6 +81,48 @@ describe('FileTreeContent', () => {
6181 expect ( screen . getByText ( 'file3.js' ) ) . toBeInTheDocument ( ) ;
6282 } ) ;
6383
84+ test ( 'renders existing tree while loading when filtered tree already has content' , ( ) => {
85+ render (
86+ < FileTreeContent
87+ filteredFileTree = { mockFileTree }
88+ loading = { true }
89+ error = { null }
90+ expandedNodes = { [ 'folder1' ] }
91+ onFileSelect = { jest . fn ( ) }
92+ onExpandedItemsChange = { jest . fn ( ) }
93+ />
94+ ) ;
95+ expect ( screen . queryByRole ( 'progressbar' ) ) . not . toBeInTheDocument ( ) ;
96+ expect ( screen . getByText ( 'folder1' ) ) . toBeInTheDocument ( ) ;
97+ } ) ;
98+
99+ test ( 'applies theme colors for each git status' , ( ) => {
100+ render (
101+ < ThemeProvider theme = { theme } >
102+ < FileTreeContent
103+ filteredFileTree = { statusFileTree }
104+ loading = { false }
105+ error = { null }
106+ expandedNodes = { [ ] }
107+ onFileSelect = { jest . fn ( ) }
108+ onExpandedItemsChange = { jest . fn ( ) }
109+ />
110+ </ ThemeProvider >
111+ ) ;
112+
113+ [
114+ [ 'modified.md' , 'rgb(1, 2, 3)' ] ,
115+ [ 'untracked.md' , 'rgb(4, 5, 6)' ] ,
116+ [ 'added.md' , 'rgb(4, 5, 6)' ] ,
117+ [ 'deleted.md' , 'rgb(7, 8, 9)' ] ,
118+ [ 'renamed.md' , 'rgb(10, 11, 12)' ] ,
119+ [ 'copied.md' , 'rgb(13, 14, 15)' ] ,
120+ [ 'unknown.md' , 'rgb(16, 17, 18)' ] ,
121+ ] . forEach ( ( [ fileName , color ] ) => {
122+ expect ( screen . getByText ( fileName ) ) . toHaveStyle ( { color } ) ;
123+ } ) ;
124+ } ) ;
125+
64126 test ( 'calls onFileSelect when a file is clicked' , ( ) => {
65127 const onFileSelectMock = jest . fn ( ) ;
66128 render (
0 commit comments