@@ -55,7 +55,7 @@ describe("fileTreeFolder", () => {
5555 expect ( screen . getByText ( "index.ts" ) ) . toBeInTheDocument ( ) ;
5656 } ) ;
5757
58- it ( "toggles expansion on click" , async ( ) => {
58+ it ( "toggles expansion on chevron click" , async ( ) => {
5959 const user = userEvent . setup ( ) ;
6060 render (
6161 < FileTree >
@@ -68,13 +68,32 @@ describe("fileTreeFolder", () => {
6868 // Initially collapsed
6969 expect ( screen . queryByText ( "index.ts" ) ) . not . toBeInTheDocument ( ) ;
7070
71- // Click to expand
72- const folderButton = screen . getByRole ( "button" ) ;
73- await user . click ( folderButton ) ;
71+ // Click chevron to expand
72+ const [ chevronButton ] = screen . getAllByRole ( "button" ) ;
73+ await user . click ( chevronButton ) ;
7474
7575 expect ( screen . getByText ( "index.ts" ) ) . toBeInTheDocument ( ) ;
7676 } ) ;
7777
78+ it ( "selects folder without toggling expansion" , async ( ) => {
79+ const onSelect = vi . fn ( ) ;
80+ const user = userEvent . setup ( ) ;
81+ render (
82+ < FileTree onSelect = { onSelect } >
83+ < FileTreeFolder name = "src" path = "src" >
84+ < FileTreeFile name = "index.ts" path = "src/index.ts" />
85+ </ FileTreeFolder >
86+ </ FileTree >
87+ ) ;
88+
89+ // Click folder name to select (not chevron)
90+ await user . click ( screen . getByText ( "src" ) ) ;
91+
92+ expect ( onSelect ) . toHaveBeenCalledWith ( "src" ) ;
93+ // Should NOT expand
94+ expect ( screen . queryByText ( "index.ts" ) ) . not . toBeInTheDocument ( ) ;
95+ } ) ;
96+
7897 it ( "calls onExpandedChange when toggling" , async ( ) => {
7998 const onExpandedChange = vi . fn ( ) ;
8099 const user = userEvent . setup ( ) ;
@@ -87,8 +106,8 @@ describe("fileTreeFolder", () => {
87106 </ FileTree >
88107 ) ;
89108
90- const folderButton = screen . getByRole ( "button" ) ;
91- await user . click ( folderButton ) ;
109+ const [ chevronButton ] = screen . getAllByRole ( "button" ) ;
110+ await user . click ( chevronButton ) ;
92111
93112 expect ( onExpandedChange ) . toHaveBeenCalledWith ( new Set ( [ "src" ] ) ) ;
94113 } ) ;
@@ -158,13 +177,13 @@ describe("composability", () => {
158177
159178 expect ( screen . getByText ( "components" ) ) . toBeInTheDocument ( ) ;
160179
161- // Expand nested folder
162- const componentsFolderButton = screen
163- . getByText ( "components" )
164- . closest ( "button" ) ;
180+ // Click folder name to find its sibling chevron, then expand
181+ const componentsText = screen . getByText ( "components" ) ;
182+ const componentsRow = componentsText . closest ( "div" ) ;
183+ const chevronButton = componentsRow ?. querySelector ( "button:first-child " ) ;
165184 // oxlint-disable-next-line eslint-plugin-jest(no-conditional-in-test)
166- if ( componentsFolderButton ) {
167- await user . click ( componentsFolderButton ) ;
185+ if ( chevronButton ) {
186+ await user . click ( chevronButton ) ;
168187 }
169188
170189 expect ( screen . getByText ( "Button.tsx" ) ) . toBeInTheDocument ( ) ;
0 commit comments