@@ -497,3 +497,61 @@ describe("maintenance windows (L9)", () => {
497497 expect ( maintenanceLines ( undefined , "Lab" ) [ 0 ] ) . toContain ( "not available" )
498498 } )
499499} )
500+
501+ describe ( "top tabs and scrollable dialogs" , ( ) => {
502+ const core = require ( "./core" )
503+ const TABS = [
504+ { label : "Workspace" , short : "Work" } ,
505+ { label : "Projects" , short : "Proj" } ,
506+ { label : "Campaigns" , short : "Camp" } ,
507+ { label : "Findings" , short : "Find" } ,
508+ { label : "Plan" , short : "Plan" } ,
509+ { label : "Attack paths" , short : "Paths" } ,
510+ { label : "Reports" , short : "Docs" } ,
511+ ]
512+ test ( "80 columns: every tab shows a label and the bar leaves room for the status" , ( ) => {
513+ for ( const w of [ 80 , 90 , 99 ] ) {
514+ const bar = core . topTabs ( TABS , w , 2 )
515+ expect ( bar . mode ) . toBe ( "narrow" )
516+ expect ( bar . tabs . map ( ( t ) => t . text ) ) . toEqual ( [ "1 Work" , "2 Proj" , "3 Camp" , "4 Find" , "5 Plan" , "6 Path" , "7 Docs" ] )
517+ expect ( bar . tabs . filter ( ( t ) => t . active ) . map ( ( t ) => t . text ) ) . toEqual ( [ "3 Camp" ] )
518+ // DARKMOON + gaps + paddings = 17 cells, the status keeps at least 10
519+ expect ( 17 + bar . total + 10 ) . toBeLessThanOrEqual ( 80 )
520+ }
521+ } )
522+ test ( "120 and 160 columns keep the short and full labels" , ( ) => {
523+ const b120 = core . topTabs ( TABS , 120 , 0 )
524+ expect ( b120 . mode ) . toBe ( "short" )
525+ expect ( b120 . tabs . map ( ( t ) => t . text ) ) . toEqual ( [ "1 Work" , "2 Proj" , "3 Camp" , "4 Find" , "5 Plan" , "6 Paths" , "7 Docs" ] )
526+ expect ( b120 . tabs . every ( ( t ) => t . padL === 1 && t . padR === 1 ) ) . toBe ( true )
527+ const b160 = core . topTabs ( TABS , 160 , 0 )
528+ expect ( b160 . mode ) . toBe ( "full" )
529+ expect ( b160 . tabs [ 5 ] . text ) . toBe ( "6 Attack paths" )
530+ expect ( core . topTabs ( TABS , 79 , 0 ) ) . toEqual ( { tabs : [ ] , total : 0 , mode : "none" } )
531+ } )
532+ test ( "wrapDialogLines keeps blank lines and indents continuations" , ( ) => {
533+ const out = core . wrapDialogLines ( [ "A" , "" , " aaa bbb ccc ddd" ] , 10 )
534+ expect ( out ) . toEqual ( [ "A" , "" , " aaa bbb" , " ccc ddd" ] )
535+ expect ( out . every ( ( l ) => l . length <= 10 ) ) . toBe ( true )
536+ expect ( core . wrapDialogLines ( [ "x" . repeat ( 30 ) ] , 10 ) ) . toEqual ( [ "xxxxxxxxx…" ] )
537+ } )
538+ test ( "scroll window and keys: clamped, page = height - 1, home/end" , ( ) => {
539+ expect ( core . scrollWindow ( 30 , 10 , 0 ) ) . toEqual ( { offset : 0 , max : 20 , above : 0 , below : 20 } )
540+ expect ( core . scrollWindow ( 30 , 10 , 99 ) ) . toEqual ( { offset : 20 , max : 20 , above : 20 , below : 0 } )
541+ expect ( core . scrollWindow ( 5 , 10 , 3 ) ) . toEqual ( { offset : 0 , max : 0 , above : 0 , below : 0 } )
542+ expect ( core . scrollKey ( "down" , 30 , 10 , 0 ) ) . toBe ( 1 )
543+ expect ( core . scrollKey ( "up" , 30 , 10 , 0 ) ) . toBe ( 0 )
544+ expect ( core . scrollKey ( "pagedown" , 30 , 10 , 0 ) ) . toBe ( 9 )
545+ expect ( core . scrollKey ( "pagedown" , 30 , 10 , 15 ) ) . toBe ( 20 )
546+ expect ( core . scrollKey ( "pageup" , 30 , 10 , 5 ) ) . toBe ( 0 )
547+ expect ( core . scrollKey ( "end" , 30 , 10 , 0 ) ) . toBe ( 20 )
548+ expect ( core . scrollKey ( "home" , 30 , 10 , 20 ) ) . toBe ( 0 )
549+ expect ( core . scrollKey ( "x" , 30 , 10 , 0 ) ) . toBeUndefined ( )
550+ } )
551+ test ( "the full legend scrolls in a short terminal instead of being cut" , ( ) => {
552+ const rows = core . wrapDialogLines ( core . legendLines ( undefined ) , 56 )
553+ const win = core . scrollWindow ( rows . length , 8 , 0 )
554+ expect ( win . below ) . toBeGreaterThan ( 0 )
555+ expect ( rows . slice ( core . scrollKey ( "end" , rows . length , 8 , 0 ) ! ) . join ( "\n" ) ) . toContain ( "CYBER SCORE" )
556+ } )
557+ } )
0 commit comments