@@ -19,6 +19,7 @@ import { mockServers } from "../utils/mock-server"
1919import { fixture , mockStressTimeline } from "../utils/session-fixture"
2020import { fileNode , mockWorkspace , openSession } from "../utils/workspace"
2121import { expectSessionTitle } from "../utils/waits"
22+ import { openWithDirection } from "../utils/direction"
2223
2324const a = { id : "ses_tab_a" , title : "Tab A session" }
2425
@@ -242,6 +243,87 @@ test("the browser title names the open session and resets after leaving it", asy
242243 await expect ( page ) . toHaveTitle ( "OpenCode" )
243244} )
244245
246+ for ( const [ tabLayout , direction , label ] of [
247+ [ "horizontal" , "ltr" , "Close tabs to the right" ] ,
248+ [ "horizontal" , "rtl" , "Close tabs to the left" ] ,
249+ [ "vertical" , "ltr" , "Close tabs below" ] ,
250+ ] as const ) {
251+ test ( `${ tabLayout } ${ direction } tab menus bulk close in visible order and reopen sessions` , async ( { page } ) => {
252+ await mockWorkspace ( page , {
253+ name : "Tabs" ,
254+ sessions : [ a , b , c ] ,
255+ seed : {
256+ tabs : [ a . id , { draft : "draft_bulk_close" , directory : "C:/OpenCode/Tabs" } , b . id , c . id ] ,
257+ settings : { appearance : { tabLayout } } ,
258+ } ,
259+ } )
260+ await openWithDirection ( page , sessionHref ( c . id ) , direction )
261+
262+ const titles = page . locator ( "[data-titlebar-tab-slot] [data-titlebar-tab-title]" )
263+
264+ const draft = page . locator ( `a[data-titlebar-tab-link][href="${ draftHref ( "draft_bulk_close" ) } "]` )
265+
266+ const tabB = page . locator ( `a[data-titlebar-tab-link][href="${ sessionHref ( b . id ) } "]` )
267+
268+ const menu = page . getByRole ( "menu" )
269+
270+ const active = page . locator ( '[data-titlebar-tab-slot][data-active="true"] [data-titlebar-tab-title]' )
271+
272+ const modifier = await page . evaluate ( ( ) => ( / M a c / . test ( navigator . platform ) ? "Meta" : "Control" ) )
273+
274+ await expect ( titles ) . toHaveText ( [ a . title , "Session" , b . title , c . title ] )
275+ await draft . click ( { button : "right" } )
276+ await expect ( active ) . toHaveText ( c . title )
277+ await expect ( menu . getByRole ( "menuitem" ) ) . toHaveText ( [ "Close tab" , "Close other tabs" , label ] )
278+ await menu . getByRole ( "menuitem" , { name : label , exact : true } ) . click ( )
279+ await expect ( titles ) . toHaveText ( [ a . title , "Session" ] )
280+ await expect ( active ) . toHaveText ( "Session" )
281+
282+ for ( const expected of [
283+ [ a . title , "Session" , b . title ] ,
284+ [ a . title , "Session" , b . title , c . title ] ,
285+ ] ) {
286+ await page . keyboard . press ( `${ modifier } +Shift+t` )
287+ await expect ( titles ) . toHaveText ( expected )
288+ }
289+
290+ await page . locator ( `a[data-titlebar-tab-link][href="${ sessionHref ( a . id ) } "]` ) . click ( )
291+ await expect ( active ) . toHaveText ( a . title )
292+ await tabB . click ( { button : "right" } )
293+ await menu . getByRole ( "menuitem" , { name : label , exact : true } ) . click ( )
294+ await expect ( titles ) . toHaveText ( [ a . title , "Session" , b . title ] )
295+ await expect ( active ) . toHaveText ( a . title )
296+ await page . keyboard . press ( `${ modifier } +Shift+t` )
297+ await expect ( titles ) . toHaveText ( [ a . title , "Session" , b . title , c . title ] )
298+
299+ await tabB . click ( { button : "right" } )
300+ await expect ( menu . getByRole ( "menuitem" ) ) . toHaveText ( [
301+ "Rename" ,
302+ "Close tab" ,
303+ "Close other tabs" ,
304+ label ,
305+ "Delete session…" ,
306+ ] )
307+ await menu . getByRole ( "menuitem" , { name : "Close other tabs" , exact : true } ) . click ( )
308+ await expect ( titles ) . toHaveText ( [ b . title ] )
309+ await expect ( active ) . toHaveText ( b . title )
310+ await tabB . click ( { button : "right" } )
311+ await expect ( menu . getByRole ( "menuitem" , { name : "Close other tabs" , exact : true } ) ) . toBeDisabled ( )
312+ await expect ( menu . getByRole ( "menuitem" , { name : label , exact : true } ) ) . toBeDisabled ( )
313+ await page . keyboard . press ( "Escape" )
314+
315+ for ( const expected of [
316+ [ a . title , b . title ] ,
317+ [ a . title , b . title , c . title ] ,
318+ ] ) {
319+ await page . keyboard . press ( `${ modifier } +Shift+t` )
320+ await expect ( titles ) . toHaveText ( expected )
321+ }
322+
323+ await expect ( draft ) . toHaveCount ( 0 )
324+ } )
325+ }
326+
245327for ( const tabLayout of [ "horizontal" , "vertical" ] as const ) {
246328 test ( `a ${ tabLayout } tab can be renamed again while its previous rename is still saving` , async ( { page } ) => {
247329 await mockWorkspace ( page , { name : "Tabs" , sessions : [ a , b ] , seed : { settings : { appearance : { tabLayout } } } } )
0 commit comments