@@ -103,3 +103,31 @@ describe("Terminal history persistence", () => {
103103 expect ( input ) . toHaveValue ( "first" ) ;
104104 } ) ;
105105} ) ;
106+
107+ test ( "preserves current input when navigating history and returning back down" , ( ) => {
108+ localStorage . setItem ( "terminal-history" , JSON . stringify ( [ "old1" , "old2" ] ) ) ;
109+
110+ render ( < Terminal onInput = { ( ) => { } } /> ) ;
111+ const input = screen . getByPlaceholderText ( "Terminal Hidden Input" ) ;
112+
113+ fireEvent . change ( input , { target : { value : "new-typing" } } ) ;
114+
115+ fireEvent . keyDown ( input , { key : "ArrowUp" } ) ;
116+ expect ( input ) . toHaveValue ( "old2" ) ;
117+
118+ fireEvent . keyDown ( input , { key : "ArrowDown" } ) ;
119+ expect ( input ) . toHaveValue ( "new-typing" ) ;
120+ } ) ;
121+
122+ test ( "does not clear input when ArrowDown is pressed while at latest history entry" , ( ) => {
123+ localStorage . setItem ( "terminal-history" , JSON . stringify ( [ "cmdA" , "cmdB" ] ) ) ;
124+
125+ render ( < Terminal onInput = { ( ) => { } } /> ) ;
126+ const input = screen . getByPlaceholderText ( "Terminal Hidden Input" ) ;
127+
128+ fireEvent . keyDown ( input , { key : "ArrowUp" } ) ;
129+ expect ( input ) . toHaveValue ( "cmdB" ) ;
130+
131+ fireEvent . keyDown ( input , { key : "ArrowDown" } ) ;
132+ expect ( input ) . toHaveValue ( "" ) ;
133+ } ) ;
0 commit comments