import { describe, expect, it } from "vitest"; import { getTerminalScrollbackLimit, isCurrentWebSocket, shouldRetryWebSocketClose, shouldCopyTerminalSelection, } from "./terminal.tsx"; describe("getTerminalScrollbackLimit", () => { it("retains normal-buffer history for custom mobile swipe scrolling", () => { expect(getTerminalScrollbackLimit(true)).toBe(10_000); }); it("keeps desktop scrollback disabled to prevent stale-frame wheel scrolling", () => { expect(getTerminalScrollbackLimit(false)).toBe(0); }); it("rejects stale WebSocket callbacks after a replacement connection", () => { const current = {} as WebSocket; const stale = {} as WebSocket; expect(isCurrentWebSocket(current, current)).toBe(true); expect(isCurrentWebSocket(current, stale)).toBe(false); }); it("retries a heartbeat timeout but not a server socket replacement", () => { expect(shouldRetryWebSocketClose(4000, "Heartbeat timeout")).toBe(true); expect(shouldRetryWebSocketClose(4000, "New connection established")).toBe( false, ); }); }); describe("shouldCopyTerminalSelection", () => { it("copies a selected terminal region with Ctrl+Shift+C", () => { expect( shouldCopyTerminalSelection( { ctrlKey: true, shiftKey: true, key: "c" }, true, ), ).toBe(true); }); it("keeps Ctrl+C as a terminal interrupt", () => { expect( shouldCopyTerminalSelection( { ctrlKey: true, shiftKey: false, key: "c" }, true, ), ).toBe(false); }); it("does not copy without a selection", () => { expect( shouldCopyTerminalSelection( { ctrlKey: true, shiftKey: true, key: "c" }, false, ), ).toBe(false); }); });