Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadTerminalDrawer.test.ts

92 lines2.9 KB

1import { describe, expect, it } from "vite-plus/test";
2​
3import {
4 resolveTerminalSelectionActionPosition,
5 shouldHandleTerminalExit,
6 shouldHandleTerminalSelectionMouseUp,
7 terminalSelectionActionDelayForClickCount,
8 terminalSelectionLineRange,
9} from "./ThreadTerminalDrawer";
10​
11describe("resolveTerminalSelectionActionPosition", () => {
12 it("prefers the selection rect over the last pointer position", () => {
13 expect(
14 resolveTerminalSelectionActionPosition({
15 bounds: { left: 100, top: 50, width: 500, height: 220 },
16 selectionRect: { right: 260, bottom: 140 },
17 pointer: { x: 520, y: 200 },
18 viewport: { width: 1024, height: 768 },
19 }),
20 ).toEqual({
21 x: 260,
22 y: 144,
23 });
24 });
25​
26 it("falls back to the pointer position when no selection rect is available", () => {
27 expect(
28 resolveTerminalSelectionActionPosition({
29 bounds: { left: 100, top: 50, width: 500, height: 220 },
30 selectionRect: null,
31 pointer: { x: 180, y: 130 },
32 viewport: { width: 1024, height: 768 },
33 }),
34 ).toEqual({
35 x: 180,
36 y: 130,
37 });
38 });
39​
40 it("clamps the pointer fallback into the terminal drawer bounds", () => {
41 expect(
42 resolveTerminalSelectionActionPosition({
43 bounds: { left: 100, top: 50, width: 500, height: 220 },
44 selectionRect: null,
45 pointer: { x: 720, y: 340 },
46 viewport: { width: 1024, height: 768 },
47 }),
48 ).toEqual({
49 x: 600,
50 y: 270,
51 });
52​
53 expect(
54 resolveTerminalSelectionActionPosition({
55 bounds: { left: 100, top: 50, width: 500, height: 220 },
56 selectionRect: null,
57 pointer: { x: 40, y: 20 },
58 viewport: { width: 1024, height: 768 },
59 }),
60 ).toEqual({
61 x: 100,
62 y: 50,
63 });
64 });
65​
66 it("delays multi-click selection actions so triple-click selection can complete", () => {
67 expect(terminalSelectionActionDelayForClickCount(1)).toBe(0);
68 expect(terminalSelectionActionDelayForClickCount(2)).toBe(260);
69 expect(terminalSelectionActionDelayForClickCount(3)).toBe(260);
70 });
71​
72 it("only handles mouseup when the selection gesture started in the terminal", () => {
73 expect(shouldHandleTerminalSelectionMouseUp(true, 0)).toBe(true);
74 expect(shouldHandleTerminalSelectionMouseUp(false, 0)).toBe(false);
75 expect(shouldHandleTerminalSelectionMouseUp(true, 1)).toBe(false);
76 });
77​
78 it("uses Ghostty's physical screen range for visually wrapped selections", () => {
79 expect(
80 terminalSelectionLineRange({
81 start: { y: 4 },
82 end: { y: 6 },
83 }),
84 ).toEqual({ lineStart: 5, lineEnd: 7 });
85 });
86​
87 it("handles an exit that lands while the terminal surface is still loading", () => {
88 expect(shouldHandleTerminalExit("exited", "running", false)).toBe(true);
89 expect(shouldHandleTerminalExit("exited", "exited", false)).toBe(false);
90 expect(shouldHandleTerminalExit("closed", "running", true)).toBe(false);
91 });
92});