Open History to see the last commit
1import { describe, expect, it } from "vite-plus/test";
2
3import {
4 resolveTerminalSelectionActionPosition,
5 shouldHandleTerminalSelectionMouseUp,
6 terminalSelectionActionDelayForClickCount,
7} from "./ThreadTerminalDrawer";
8
9describe("resolveTerminalSelectionActionPosition", () => {
10 it("prefers the selection rect over the last pointer position", () => {
11 expect(
12 resolveTerminalSelectionActionPosition({
13 bounds: { left: 100, top: 50, width: 500, height: 220 },
14 selectionRect: { right: 260, bottom: 140 },
15 pointer: { x: 520, y: 200 },
16 viewport: { width: 1024, height: 768 },
17 }),
18 ).toEqual({
19 x: 260,
20 y: 144,
21 });
22 });
23
24 it("falls back to the pointer position when no selection rect is available", () => {
25 expect(
26 resolveTerminalSelectionActionPosition({
27 bounds: { left: 100, top: 50, width: 500, height: 220 },
28 selectionRect: null,
29 pointer: { x: 180, y: 130 },
30 viewport: { width: 1024, height: 768 },
31 }),
32 ).toEqual({
33 x: 180,
34 y: 130,
35 });
36 });
37
38 it("clamps the pointer fallback into the terminal drawer bounds", () => {
39 expect(
40 resolveTerminalSelectionActionPosition({
41 bounds: { left: 100, top: 50, width: 500, height: 220 },
42 selectionRect: null,
43 pointer: { x: 720, y: 340 },
44 viewport: { width: 1024, height: 768 },
45 }),
46 ).toEqual({
47 x: 600,
48 y: 270,
49 });
50
51 expect(
52 resolveTerminalSelectionActionPosition({
53 bounds: { left: 100, top: 50, width: 500, height: 220 },
54 selectionRect: null,
55 pointer: { x: 40, y: 20 },
56 viewport: { width: 1024, height: 768 },
57 }),
58 ).toEqual({
59 x: 100,
60 y: 50,
61 });
62 });
63
64 it("delays multi-click selection actions so triple-click selection can complete", () => {
65 expect(terminalSelectionActionDelayForClickCount(1)).toBe(0);
66 expect(terminalSelectionActionDelayForClickCount(2)).toBe(260);
67 expect(terminalSelectionActionDelayForClickCount(3)).toBe(260);
68 });
69
70 it("only handles mouseup when the selection gesture started in the terminal", () => {
71 expect(shouldHandleTerminalSelectionMouseUp(true, 0)).toBe(true);
72 expect(shouldHandleTerminalSelectionMouseUp(false, 0)).toBe(false);
73 expect(shouldHandleTerminalSelectionMouseUp(true, 1)).toBe(false);
74 });
75});