@@ -6,7 +6,7 @@ import { page, userEvent } from "vite-plus/test/browser";
66
77import type { RightPanelSurface } from "~/rightPanelStore" ;
88import { render , stubGlobal } from "../../test/render" ;
9- import { createWorkspaceFocusController } from "~/lib/workspaceFocus" ;
9+ import { startWorkspaceFocus , workspaceAreaProps } from "~/lib/workspaceFocus" ;
1010import { HistorySwipeNavigation } from "./HistorySwipeNavigation" ;
1111import { RightPanelTabs } from "./RightPanelTabs" ;
1212
@@ -143,37 +143,44 @@ describe("RightPanelTabs", () => {
143143
144144 expect ( navigateHistory ) . toHaveBeenCalledExactlyOnceWith ( "back" ) ;
145145 } ) ;
146- it ( "a surface picked from the add menu keeps the focus it takes; dismissing the menu returns to +" , async ( ) => {
147- const focus = createWorkspaceFocusController ( document ) ;
148- using _focus = { [ Symbol . dispose ] : focus . dispose } ;
146+ it ( "a surface picked from the add menu takes focus, even when already open; dismissing the menu returns to +" , async ( ) => {
147+ using _focus = {
148+ [ Symbol . dispose ] : startWorkspaceFocus ( { subscribe : ( ) => ( ) => { } } as never ) ,
149+ } ;
149150 function Panel ( ) {
150151 const [ activeSurfaceId , setActiveSurfaceId ] = useState ( "terminal:0" ) ;
151152 return (
152- < Tabs
153- activeSurfaceId = { activeSurfaceId }
154- filesAvailable
155- onAddFiles = { ( ) => {
156- setActiveSurfaceId ( "terminal:1" ) ;
157- focus . request ( { area : "panel" } ) ;
158- } }
159- >
160- < input
161- key = { activeSurfaceId }
162- aria-label = { `Content of ${ activeSurfaceId } ` }
163- data-workspace-focus-default
164- />
165- </ Tabs >
153+ < >
154+ < div { ...workspaceAreaProps ( "composer" , 2 , "Composer" ) } >
155+ < textarea aria-label = "Message" />
156+ </ div >
157+ < Tabs
158+ activeSurfaceId = { activeSurfaceId }
159+ filesAvailable
160+ onAddFiles = { ( ) => setActiveSurfaceId ( "terminal:1" ) }
161+ >
162+ < input
163+ key = { activeSurfaceId }
164+ aria-label = { `Content of ${ activeSurfaceId } ` }
165+ data-workspace-focus-default
166+ />
167+ </ Tabs >
168+ </ >
166169 ) ;
167170 }
168171 await using _screen = await render ( < Panel /> ) ;
169172 const add = page . getByRole ( "button" , { name : "Add panel surface" } ) ;
173+ const content = page . getByRole ( "textbox" , { name : "Content of terminal:1" } ) ;
170174
171- await userEvent . click ( add ) ;
172- await userEvent . keyboard ( "f" ) ;
173- await expect . element ( page . getByRole ( "menu" ) ) . not . toBeInTheDocument ( ) ;
174- await expect
175- . element ( page . getByRole ( "textbox" , { name : "Content of terminal:1" } ) )
176- . toHaveFocus ( ) ;
175+ for ( let pick = 0 ; pick < 2 ; pick ++ ) {
176+ await userEvent . click ( add ) ;
177+ await vi . waitFor ( ( ) =>
178+ expect ( document . activeElement ?. closest ( '[role="menu"]' ) ) . not . toBeNull ( ) ,
179+ ) ;
180+ await userEvent . keyboard ( "f" ) ;
181+ await expect . element ( page . getByRole ( "menu" ) ) . not . toBeInTheDocument ( ) ;
182+ await expect . element ( content ) . toHaveFocus ( ) ;
183+ }
177184
178185 await userEvent . click ( add ) ;
179186 await userEvent . keyboard ( "{Escape}" ) ;
0 commit comments