@@ -317,21 +317,49 @@ func manyRows(n int) []StackRow {
317317 return rows
318318}
319319
320- func TestView_InlineHeightIsBounded (t * testing.T ) {
321- // A long list on a tall terminal must not take over the screen: it shows at
322- // most maxVisibleRows rows plus a little chrome, and offers a scroll hint.
323- m := drive (New (manyRows (30 )), tea.WindowSizeMsg {Width : 90 , Height : 50 })
320+ func TestBodyHeight_UsesAvailableTerminalSpace (t * testing.T ) {
321+ tests := []struct {
322+ name string
323+ rows int
324+ height int
325+ searching bool
326+ want int
327+ }{
328+ {name : "unknown terminal size uses fallback" , rows : 30 , want : initialVisibleRows },
329+ {name : "small list stays compact" , rows : 3 , height : 50 , want : 3 },
330+ {name : "tall terminal expands past fallback" , rows : 100 , height : 50 , want : 44 },
331+ {name : "short terminal shrinks" , rows : 30 , height : 12 , want : 6 },
332+ {name : "search reserves another line" , rows : 100 , height : 50 , searching : true , want : 43 },
333+ {name : "empty list reserves one row" , height : 50 , want : 1 },
334+ {name : "tiny terminal reserves one row" , rows : 30 , height : 3 , want : 1 },
335+ }
336+
337+ for _ , tt := range tests {
338+ t .Run (tt .name , func (t * testing.T ) {
339+ m := New (manyRows (tt .rows ))
340+ m .height = tt .height
341+ m .searching = tt .searching
342+ assert .Equal (t , tt .want , m .bodyHeight ())
343+ })
344+ }
345+ }
346+
347+ func TestView_ExpandsToAvailableTerminalHeight (t * testing.T ) {
348+ const terminalHeight = 50
349+ m := drive (New (manyRows (100 )), tea.WindowSizeMsg {Width : 90 , Height : terminalHeight })
350+
351+ assert .Greater (t , m .bodyHeight (), initialVisibleRows )
352+ assert .Equal (t , terminalHeight - m .chromeHeight (), m .bodyHeight ())
324353 lines := len (strings .Split (m .View (), "\n " ))
325- assert .LessOrEqual (t , lines , maxVisibleRows + 6 , "picker must not fill a tall terminal" )
326- assert .GreaterOrEqual (t , lines , maxVisibleRows , "shows up to maxVisibleRows rows" )
327- assert .Contains (t , stripANSI (m .View ()), "of 30" , "shows a scroll position indicator" )
354+ assert .Equal (t , terminalHeight - 1 , lines , "picker keeps one safety row free" )
355+ assert .Contains (t , stripANSI (m .View ()), "of 100" , "shows a scroll position indicator" )
328356}
329357
330358func TestView_ShrinksToShortTerminal (t * testing.T ) {
331359 m := drive (New (manyRows (30 )), tea.WindowSizeMsg {Width : 90 , Height : 12 })
332360 lines := len (strings .Split (m .View (), "\n " ))
361+ assert .Equal (t , 12 - m .chromeHeight (), m .bodyHeight ())
333362 assert .LessOrEqual (t , lines , 12 , "must fit within a short terminal" )
334- assert .Less (t , lines , maxVisibleRows + 6 )
335363}
336364
337365func TestView_ClearsOnExit (t * testing.T ) {
0 commit comments