11import { afterAll , beforeAll , expect , it , suite , vi } from "vitest" ;
22import { filterTermLine , formatTermTimestamp , sanitizeTermLine } from "./liveConsoleUtils" ;
3+ import type { TimestampMode } from "./xtermOptions" ;
34
4- suite . skip ( 'filterTermLine' , ( ) => {
5+ suite ( 'filterTermLine' , ( ) => {
56 // Mocking the global window object for the test environment
67 beforeAll ( ( ) => vi . stubGlobal ( 'window' , { txBrowserHour12 : false } ) ) ;
78 afterAll ( ( ) => vi . unstubAllGlobals ( ) ) ;
89
9- const fnc : typeof filterTermLine = ( input , copyTimestamp , copyTag ) => filterTermLine ( sanitizeTermLine ( input ) , copyTimestamp , copyTag ) ;
10- const baseOpts = { } ; //FIXME: this entire thing changed
10+ // Wrapper that sanitizes input before filtering (simulating real usage)
11+ const fnc = ( input : string , copyTimestamp : boolean , copyTag : boolean ) =>
12+ filterTermLine ( sanitizeTermLine ( input ) , copyTimestamp , copyTag ) ;
1113
1214 const exampleLines = {
1315 empty : '' ,
@@ -21,91 +23,87 @@ suite.skip('filterTermLine', () => {
2123
2224 suite ( 'timestamp formats' , ( ) => {
2325 it ( 'should handle 24-hour format when timestampForceHour12 is false' , ( ) => {
24- const opts = { ... baseOpts , timestampForceHour12 : false } ;
26+ const tsMode : TimestampMode = 'FORCE24H' ;
2527 const ts = 14 * 3600 ; // 14:00:00
26- const input = formatTermTimestamp ( ts , opts ) + exampleLines . normal ;
27- expect ( fnc ( input , opts ) ) . toEqual ( sanitizeTermLine ( input ) ) ;
28+ const input = formatTermTimestamp ( ts , tsMode ) + exampleLines . normal ;
29+ expect ( fnc ( input , true , true ) ) . toEqual ( sanitizeTermLine ( input ) ) ;
2830 } ) ;
2931
3032 it ( 'should handle 12-hour format when timestampForceHour12 is true' , ( ) => {
31- const opts = { ... baseOpts , timestampForceHour12 : true } ;
33+ const tsMode : TimestampMode = 'FORCE12H' ;
3234 const ts = 14 * 3600 ; // 2:00:00 PM
33- const input = formatTermTimestamp ( ts , opts ) + exampleLines . normal ;
34- expect ( fnc ( input , opts ) ) . toEqual ( sanitizeTermLine ( input ) ) ;
35+ const input = formatTermTimestamp ( ts , tsMode ) + exampleLines . normal ;
36+ expect ( fnc ( input , true , true ) ) . toEqual ( sanitizeTermLine ( input ) ) ;
3537 } ) ;
3638 } ) ;
3739
3840 suite ( 'copyTimestamp and copyTag options' , ( ) => {
3941 it ( 'should return full line when copyTimestamp and copyTag are true' , ( ) => {
40- const opts = { ... baseOpts , copyTimestamp : true , copyTag : true } ;
41- const ts = 10 * 3600 ; // 10:00:00 AM
42- const input = formatTermTimestamp ( ts , opts ) + exampleLines . input ;
43- expect ( fnc ( input , opts ) ) . toEqual ( sanitizeTermLine ( input ) ) ; // Corrected expectation
42+ const tsMode : TimestampMode = 'FORCE24H' ;
43+ const ts = 10 * 3600 ; // 10:00:00
44+ const input = formatTermTimestamp ( ts , tsMode ) + exampleLines . input ;
45+ expect ( fnc ( input , true , true ) ) . toEqual ( sanitizeTermLine ( input ) ) ;
4446 } ) ;
4547
4648 it ( 'should remove timestamp when copyTimestamp is false' , ( ) => {
47- const opts = { ... baseOpts , copyTimestamp : false , copyTag : true } ;
48- const ts = 10 * 3600 ; // 10:00:00 AM
49- const input = formatTermTimestamp ( ts , baseOpts ) + exampleLines . input ;
49+ const tsMode : TimestampMode = 'FORCE24H' ;
50+ const ts = 10 * 3600 ; // 10:00:00
51+ const input = formatTermTimestamp ( ts , tsMode ) + exampleLines . input ;
5052 const expected = exampleLines . input . trimEnd ( ) ;
51- expect ( fnc ( input , opts ) ) . toEqual ( expected ) ; // Corrected expectation
53+ expect ( fnc ( input , false , true ) ) . toEqual ( expected ) ;
5254 } ) ;
5355
5456 it ( 'should remove tag when copyTag is false' , ( ) => {
55- const opts = { ... baseOpts , copyTimestamp : true , copyTag : false } ;
57+ const tsMode : TimestampMode = 'FORCE24H' ;
5658 const ts = 0 ;
57- const input = formatTermTimestamp ( ts , opts ) + exampleLines . input ;
58- const timestamp = formatTermTimestamp ( ts , opts ) ;
59+ const input = formatTermTimestamp ( ts , tsMode ) + exampleLines . input ;
60+ const timestamp = sanitizeTermLine ( formatTermTimestamp ( ts , tsMode ) ) ;
5961 const expected = timestamp + 'dd' ;
60- expect ( fnc ( input , opts ) ) . toEqual ( sanitizeTermLine ( expected ) ) ;
62+ expect ( fnc ( input , true , false ) ) . toEqual ( expected ) ;
6163 } ) ;
6264
6365 it ( 'should remove both timestamp and tag when both copyTimestamp and copyTag are false' , ( ) => {
64- const opts = { ... baseOpts , copyTimestamp : false , copyTag : false } ;
66+ const tsMode : TimestampMode = 'FORCE24H' ;
6567 const ts = 0 ;
6668 const content = 'whatever' ;
67- const input = formatTermTimestamp ( ts , baseOpts ) + content ;
68- expect ( fnc ( input , opts ) ) . toEqual ( content ) ;
69+ const input = formatTermTimestamp ( ts , tsMode ) + content ;
70+ expect ( fnc ( input , false , false ) ) . toEqual ( content ) ;
6971 } ) ;
7072 } ) ;
7173
7274 suite ( 'handling empty and various lines' , ( ) => {
7375 it ( 'should handle empty line' , ( ) => {
74- const opts = { ...baseOpts } ;
75- const input = '' ;
76- expect ( fnc ( input , opts ) ) . toEqual ( '' ) ;
76+ expect ( fnc ( '' , true , true ) ) . toEqual ( '' ) ;
7777 } ) ;
7878
7979 it ( 'should handle line without timestamp' , ( ) => {
80- const opts = { ...baseOpts } ;
8180 const input = exampleLines . normal ;
82- expect ( fnc ( input , opts ) ) . toEqual ( exampleLines . normal ) ;
81+ expect ( fnc ( input , true , true ) ) . toEqual ( exampleLines . normal ) ;
8382 } ) ;
8483 } ) ;
8584
8685 suite ( 'AM/PM formatting' , ( ) => {
8786 it ( 'should correctly filter AM time when copyTimestamp is true' , ( ) => {
88- const opts = { ... baseOpts , timestampForceHour12 : true , copyTimestamp : true , copyTag : true } ;
87+ const tsMode : TimestampMode = 'FORCE12H' ;
8988 const ts = 5 * 3600 ; // 5:00:00 AM
90- const input = formatTermTimestamp ( ts , opts ) + exampleLines . normal ;
91- expect ( fnc ( input , opts ) ) . toEqual ( sanitizeTermLine ( input ) ) ; // Ensures full line is returned
89+ const input = formatTermTimestamp ( ts , tsMode ) + exampleLines . normal ;
90+ expect ( fnc ( input , true , true ) ) . toEqual ( sanitizeTermLine ( input ) ) ;
9291 } ) ;
9392
9493 it ( 'should correctly filter PM time when copyTimestamp is false' , ( ) => {
95- const opts = { ... baseOpts , timestampForceHour12 : true , copyTimestamp : false , copyTag : true } ;
94+ const tsMode : TimestampMode = 'FORCE12H' ;
9695 const ts = 17 * 3600 ; // 5:00:00 PM
97- const input = formatTermTimestamp ( ts , opts ) + exampleLines . normal ;
96+ const input = formatTermTimestamp ( ts , tsMode ) + exampleLines . normal ;
9897 const expected = exampleLines . normal ;
99- expect ( fnc ( input , opts ) ) . toEqual ( expected ) ; // Ensures timestamp is removed
98+ expect ( fnc ( input , false , true ) ) . toEqual ( expected ) ;
10099 } ) ;
101100 } ) ;
102101
103102 suite ( 'comprehensive example tests' , ( ) => {
104- it ( 'should handle all example lines with base options' , ( ) => {
105- const opts = { ...baseOpts } ;
106- for ( const [ key , input ] of Object . entries ( exampleLines ) ) {
103+ it ( 'should handle all example lines with base options (copyTimestamp: true, copyTag: true)' , ( ) => {
104+ for ( const [ _key , input ] of Object . entries ( exampleLines ) ) {
107105 const sanitized = sanitizeTermLine ( input ) ;
108- expect ( fnc ( input , opts ) ) . toEqual ( sanitized ) ;
106+ expect ( fnc ( input , true , true ) ) . toEqual ( sanitized ) ;
109107 }
110108 } ) ;
111109 } ) ;
0 commit comments