11import { html , render } from "lit" ;
2- import { afterEach , beforeEach , describe , expect , it } from "vitest" ;
2+ import { afterEach , beforeEach , describe , expect , it , vi } from "vitest" ;
33import { i18n } from "../i18n/index.ts" ;
44import "../styles.css" ;
55import { renderSessionsHubHeader } from "./sessions-hub-header.ts" ;
@@ -11,7 +11,11 @@ async function useViewport(width: number, height = 800) {
1111 await page . viewport ( width , height ) ;
1212}
1313
14- async function mount ( active : "sessions" | "worktrees" , withActions : boolean ) {
14+ async function mount (
15+ active : "sessions" | "worktrees" ,
16+ withActions : boolean ,
17+ onSelect : ( tab : "sessions" | "worktrees" ) => void = ( ) => undefined ,
18+ ) {
1519 const container = document . createElement ( "div" ) ;
1620 container . style . width = "calc(100vw - 32px)" ;
1721 container . style . maxWidth = "1120px" ;
@@ -21,7 +25,7 @@ async function mount(active: "sessions" | "worktrees", withActions: boolean) {
2125 active,
2226 title : "Threads" ,
2327 actions : withActions ? html `< div style ="width: 240px "> Agent selector</ div > ` : undefined ,
24- onSelect : ( ) => undefined ,
28+ onSelect,
2529 } ) ,
2630 container ,
2731 ) ;
@@ -79,10 +83,35 @@ describe.skipIf(!hasBrowserLayout)("Sessions hub header browser layout", () => {
7983 } ,
8084 ) ;
8185
82- it ( "keeps the page header hidden on mobile" , async ( ) => {
86+ it ( "keeps session navigation and operational headers available on mobile" , async ( ) => {
8387 await useViewport ( 414 , 800 ) ;
84- const sessions = await mount ( "sessions" , true ) ;
88+ const onSelect = vi . fn ( ) ;
89+ const sessions = await mount ( "sessions" , true , onSelect ) ;
8590 const header = sessions . querySelector < HTMLElement > ( ".hub-page-header" ) ;
86- expect ( getComputedStyle ( header ! ) . display ) . toBe ( "none" ) ;
91+ const tabs = sessions . querySelector < HTMLElement > ( ".sessions-hub-tabs" ) ;
92+ const actions = sessions . querySelector < HTMLElement > ( ".hub-page-header__actions" ) ;
93+ expect ( getComputedStyle ( header ! ) . display ) . toBe ( "grid" ) ;
94+ expect ( tabs ?. getBoundingClientRect ( ) . width ) . toBeGreaterThan ( 0 ) ;
95+ expect ( actions ?. getBoundingClientRect ( ) . width ) . toBeGreaterThan ( 0 ) ;
96+
97+ const worktreesTab = sessions . querySelector < HTMLElement > ( "#sessions-tab-worktrees" ) ;
98+ expect ( worktreesTab ?. getBoundingClientRect ( ) . width ) . toBeGreaterThan ( 0 ) ;
99+ worktreesTab ?. dispatchEvent ( new MouseEvent ( "click" , { bubbles : true , detail : 1 } ) ) ;
100+ expect ( onSelect ) . toHaveBeenCalledWith ( "worktrees" ) ;
101+
102+ const operationalHeader = document . createElement ( "section" ) ;
103+ operationalHeader . className = "content-header" ;
104+ operationalHeader . innerHTML = '<button type="button">Refresh</button>' ;
105+ document . body . append ( operationalHeader ) ;
106+ expect ( getComputedStyle ( operationalHeader ) . display ) . toBe ( "flex" ) ;
107+ expect (
108+ operationalHeader . querySelector ( "button" ) ?. getBoundingClientRect ( ) . width ,
109+ ) . toBeGreaterThan ( 0 ) ;
110+
111+ const chatContent = document . createElement ( "main" ) ;
112+ chatContent . className = "content content--chat" ;
113+ chatContent . innerHTML = '<section class="content-header"></section>' ;
114+ document . body . append ( chatContent ) ;
115+ expect ( getComputedStyle ( chatContent . querySelector ( ".content-header" ) ! ) . display ) . toBe ( "none" ) ;
87116 } ) ;
88117} ) ;
0 commit comments