Skip to content

Commit 22d3cbf

Browse files
committed
feat: additional tests for terminal history navigation
1 parent c1a1bc7 commit 22d3cbf

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

tests/terminal.history.spec.tsx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)