@@ -157,6 +157,9 @@ import { previewRuntimeTabId } from "~/browser/previewRuntimeTabId";
157157import { usePreviewMiniPlayerStore } from "~/previewMiniPlayerStore" ;
158158import { dispatchPreviewAction } from "./previewActionBus" ;
159159import { PreviewView } from "./PreviewView" ;
160+ import { previewBridge } from "./previewBridge" ;
161+ import { RightPanelTabs } from "../RightPanelTabs" ;
162+ import type { RightPanelSurface } from "~/rightPanelStore" ;
160163import { ToastProvider } from "~/components/ui/toast" ;
161164
162165const TEST_THREAD_REF = {
@@ -215,6 +218,100 @@ function setup() {
215218}
216219
217220describe ( "PreviewView" , ( ) => {
221+ it ( "keeps thumb-button navigation inside the active right panel" , async ( ) => {
222+ setup ( ) ;
223+ const browser : RightPanelSurface = {
224+ id : "browser:tab-1" ,
225+ kind : "preview" ,
226+ resourceId : "tab-1" ,
227+ } ;
228+ const diff : RightPanelSurface = { id : "diff" , kind : "diff" } ;
229+ const noop = ( ) => { } ;
230+ const panel = ( activeSurfaceId : string ) => (
231+ < >
232+ < button > Main chat</ button >
233+ < RightPanelTabs
234+ mode = "embedded"
235+ keybindings = { [ ] }
236+ getShortcutContext = { ( ) => ( {
237+ terminalFocus : false ,
238+ terminalOpen : false ,
239+ previewFocus : false ,
240+ previewOpen : true ,
241+ isWeb : true ,
242+ isDesktop : false ,
243+ } ) }
244+ surfaces = { [ browser , diff ] }
245+ environmentId = { TEST_THREAD_REF . environmentId }
246+ activeSurfaceId = { activeSurfaceId }
247+ pendingSurfaceIds = { new Set ( ) }
248+ previewSessions = { { } }
249+ desktopByTabId = { { } }
250+ terminalLabelsById = { new Map ( ) }
251+ onActivate = { noop }
252+ onCloseSurface = { noop }
253+ onCloseOtherSurfaces = { noop }
254+ onCloseSurfacesToRight = { noop }
255+ onCloseAllSurfaces = { noop }
256+ onCopyFilePath = { noop }
257+ onAddBrowser = { noop }
258+ onAddBrowserInProfile = { noop }
259+ onAddTerminal = { noop }
260+ onAddDiff = { noop }
261+ onAddFiles = { noop }
262+ onAddPullRequest = { noop }
263+ onAddPullRequests = { noop }
264+ onAddDevice = { noop }
265+ browserAvailable
266+ terminalAvailable = { false }
267+ diffAvailable
268+ filesAvailable = { false }
269+ pullRequestAvailable = { false }
270+ pullRequestsAvailable = { false }
271+ deviceAvailable = { false }
272+ >
273+ < PreviewView
274+ threadRef = { TEST_THREAD_REF }
275+ tabId = "tab-1"
276+ visible = { activeSurfaceId === browser . id }
277+ />
278+ < PreviewView
279+ threadRef = { { ...TEST_THREAD_REF , environmentId : EnvironmentId . make ( "other" ) } }
280+ tabId = "tab-1"
281+ visible
282+ />
283+ </ RightPanelTabs >
284+ </ >
285+ ) ;
286+ await using screen = await render ( panel ( browser . id ) ) ;
287+ const press = ( target : Element , type : string , button : number ) => {
288+ const event = new MouseEvent ( type , { button, bubbles : true , cancelable : true } ) ;
289+ target . dispatchEvent ( event ) ;
290+ return event . defaultPrevented ;
291+ } ;
292+ const tabbar = screen . container . querySelector ( "[data-right-panel-tabbar]" ) ! ;
293+ const address = screen . getByRole ( "textbox" ) . elements ( ) [ 0 ] ! ;
294+ for ( const target of [ tabbar , address ] ) {
295+ for ( const button of [ 3 , 4 ] ) {
296+ expect ( press ( target , "mouseup" , button ) ) . toBe ( true ) ;
297+ expect ( press ( target , "auxclick" , button ) ) . toBe ( true ) ;
298+ }
299+ }
300+ expect ( previewBridge ! . goBack ) . toHaveBeenCalledTimes ( 2 ) ;
301+ expect ( previewBridge ! . goForward ) . toHaveBeenCalledTimes ( 2 ) ;
302+ expect ( previewBridge ! . goBack ) . toHaveBeenCalledWith ( TEST_RUNTIME_TAB_ID ) ;
303+ expect ( previewBridge ! . goForward ) . toHaveBeenCalledWith ( TEST_RUNTIME_TAB_ID ) ;
304+ for ( const button of [ 0 , 1 , 2 ] ) expect ( press ( tabbar , "mouseup" , button ) ) . toBe ( false ) ;
305+ expect ( press ( screen . getByRole ( "button" , { name : "Main chat" } ) . element ( ) , "mouseup" , 3 ) ) . toBe (
306+ false ,
307+ ) ;
308+
309+ await screen . rerender ( panel ( diff . id ) ) ;
310+ for ( const button of [ 3 , 4 ] ) expect ( press ( tabbar , "mouseup" , button ) ) . toBe ( true ) ;
311+ expect ( previewBridge ! . goBack ) . toHaveBeenCalledTimes ( 2 ) ;
312+ expect ( previewBridge ! . goForward ) . toHaveBeenCalledTimes ( 2 ) ;
313+ } ) ;
314+
218315 it . each ( [ "mailto:[email protected] " , "http://" ] ) ( 219316 "reports rejected address %s without navigating or recording it" ,
220317 async ( address ) => {
0 commit comments