55 HOME_VERTICAL_RESERVE ,
66 MEDIUM_MIN_HEIGHT ,
77 MEDIUM_MIN_WIDTH ,
8- PANEL_HORIZONTAL_PADDING ,
98 SESSION_VERTICAL_RESERVE ,
9+ homeAvailable ,
10+ sessionAvailable ,
1011 welcomePanelVariant ,
1112} from "../../src/component/welcome-panel-utils"
1213
@@ -16,10 +17,25 @@ import {
1617const TALL = FULL_MIN_HEIGHT + 10
1718const WIDE = FULL_MIN_WIDTH + 20
1819
19- // Map a terminal size to the AVAILABLE size each route feeds the pure function.
20- const home = ( w : number , h : number ) => welcomePanelVariant ( w - PANEL_HORIZONTAL_PADDING , h - HOME_VERTICAL_RESERVE )
21- const session = ( w : number , h : number , sidebar : boolean ) =>
22- welcomePanelVariant ( w - ( sidebar ? 42 : 0 ) - PANEL_HORIZONTAL_PADDING , h - SESSION_VERTICAL_RESERVE )
20+ // Map a terminal size to a variant THROUGH the exact functions the routes call
21+ // (homeAvailable / sessionAvailable), so these tests exercise the real call-site
22+ // arithmetic rather than a private copy of it. `sidebarVisible` is the route's
23+ // sidebarVisible() — the content column narrows whenever the sidebar is open.
24+ const home = ( w : number , h : number ) => {
25+ const a = homeAvailable ( w , h )
26+ return welcomePanelVariant ( a . width , a . height )
27+ }
28+ const session = ( w : number , h : number , sidebarVisible : boolean ) => {
29+ const a = sessionAvailable ( w , h , sidebarVisible )
30+ return welcomePanelVariant ( a . width , a . height )
31+ }
32+
33+ test ( "reserves stay pinned to the counted chrome" , ( ) => {
34+ // If someone changes the reserve to a wrong literal, this fails. The values are
35+ // derived sums of the documented per-route chrome (see welcome-panel-utils.ts).
36+ expect ( HOME_VERTICAL_RESERVE ) . toBe ( 15 )
37+ expect ( SESSION_VERTICAL_RESERVE ) . toBe ( 9 )
38+ } )
2339
2440test ( "full requires BOTH width and height to clear the full floor" , ( ) => {
2541 expect ( welcomePanelVariant ( WIDE , TALL ) ) . toBe ( "full" )
@@ -51,37 +67,56 @@ test("compact→medium boundary is exact (at the floor is medium)", () => {
5167test ( "everyday terminals get medium, not the oversized wordmark" , ( ) => {
5268 expect ( home ( 106 , 31 ) ) . toBe ( "medium" )
5369 expect ( home ( 80 , 24 ) ) . toBe ( "medium" )
54- // #1067 session case: a 130-col terminal with the 42-col sidebar leaves ~84
55- // usable cols → medium (was wrongly full when it used the whole terminal width ).
70+ // #1067 session case: a 130-col terminal with the in-flow 42-col sidebar leaves
71+ // ~84 usable cols → medium (was wrongly full when it used the whole terminal).
5672 expect ( session ( 130 , 50 , true ) ) . toBe ( "medium" )
5773} )
5874
59- test ( "the classic 80x24 is medium on both routes, with margin off the compact floor " , ( ) => {
60- // The review flagged 80x24 sitting on the exact medium floor; it now clears it
61- // on both routes (home reserves more chrome , so it's the tighter one) .
75+ test ( "the classic 80x24 is medium on both routes (a real fit, not a fake margin) " , ( ) => {
76+ // 80x24 → home available (76 × 9), session available (76 × 15). Both clear the
77+ // medium floor (60 × 8) — the medium panel is ~8 rows , so this actually fits .
6278 expect ( home ( 80 , 24 ) ) . toBe ( "medium" )
6379 expect ( session ( 80 , 24 , false ) ) . toBe ( "medium" )
6480} )
6581
6682test ( "full engages on a large window; ~one row below the floor stays medium" , ( ) => {
67- expect ( home ( 120 , 44 ) ) . toBe ( "full" ) // FULL_MIN_HEIGHT(34) + HOME_VERTICAL_RESERVE(10)
68- expect ( home ( 120 , 43 ) ) . toBe ( "medium" )
83+ // full needs available height ≥ FULL_MIN_HEIGHT(30); home reserves 15, so the
84+ // terminal must be ≥ 45 rows.
85+ expect ( home ( 120 , 45 ) ) . toBe ( "full" )
86+ expect ( home ( 120 , 44 ) ) . toBe ( "medium" )
6987} )
7088
71- test ( "toggling the session sidebar flips the panel full → medium on a wide window (#1067)" , ( ) => {
72- // The exact regression #1067 reports: on a wide window, opening the 42-col
73- // sidebar must shrink the panel out of `full` — it no longer has ~ 110 usable cols.
89+ test ( "toggling the in-flow session sidebar flips the panel full → medium on a wide window (#1067)" , ( ) => {
90+ // The exact regression #1067 reports: on a wide window the sidebar is in-flow,
91+ // and opening it must shrink the panel out of `full` ( no longer ≥ 110 usable cols) .
7492 expect ( session ( 150 , 50 , false ) ) . toBe ( "full" )
7593 expect ( session ( 150 , 50 , true ) ) . toBe ( "medium" )
7694} )
7795
96+ test ( "the content column narrows whenever the sidebar is open, incl. the overlay (aligned with messages)" , ( ) => {
97+ // On a ≤120-col terminal the sidebar is a dimmed full-area overlay, but the
98+ // content column (messages + panel) still narrows uniformly so they stay
99+ // aligned and both restore when it closes — sizing to the narrowed column, not
100+ // the transient obscured width. 100 cols: open → 54 usable → compact; closed →
101+ // 96 → medium. (Matches session's contentWidth basis; deliberate, per review.)
102+ expect ( session ( 100 , 50 , true ) ) . toBe ( "compact" )
103+ expect ( session ( 100 , 50 , false ) ) . toBe ( "medium" )
104+ } )
105+
78106test ( "a short terminal drops to compact once the route's chrome is reserved (#1067 height)" , ( ) => {
79107 // 120x22: wide, but too few usable rows after the home chrome → compact, where
80108 // the raw terminal height (22) would have picked medium.
81109 expect ( home ( 120 , 22 ) ) . toBe ( "compact" )
82110} )
83111
112+ test ( "negative available height (a tiny terminal) collapses to compact, never throws" , ( ) => {
113+ // 80x5 → home available height 5 - 15 = -10; must resolve, not crash.
114+ expect ( home ( 80 , 5 ) ) . toBe ( "compact" )
115+ expect ( session ( 80 , 5 , false ) ) . toBe ( "compact" )
116+ } )
117+
84118test ( "degenerate sizes collapse to compact" , ( ) => {
85119 expect ( welcomePanelVariant ( 0 , 0 ) ) . toBe ( "compact" )
86120 expect ( welcomePanelVariant ( 1 , 1 ) ) . toBe ( "compact" )
121+ expect ( welcomePanelVariant ( - 5 , - 5 ) ) . toBe ( "compact" )
87122} )
0 commit comments