-
Notifications
You must be signed in to change notification settings - Fork 155
Expand file tree
/
Copy pathinput-mouse.test.ts
More file actions
86 lines (79 loc) · 2.26 KB
/
Copy pathinput-mouse.test.ts
File metadata and controls
86 lines (79 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { afterEach, beforeEach, describe, expect, it } from "vitest";
import type { TerminalCore } from "@wterm/core";
import { InputHandler } from "../input.js";
describe("InputHandler mouse and focus modes", () => {
let container: HTMLDivElement;
let received: string[];
let handler: InputHandler;
let core: TerminalCore;
beforeEach(() => {
container = document.createElement("div");
document.body.appendChild(container);
Object.defineProperty(container, "getBoundingClientRect", {
value: () => ({
left: 10,
top: 20,
width: 800,
height: 400,
}),
});
received = [];
core = {
getCols: () => 80,
getRows: () => 40,
mouseTracking: () => 1002,
mouseSgr: () => true,
focusEvents: () => true,
} as unknown as TerminalCore;
handler = new InputHandler(
container,
(data) => received.push(data),
() => core,
);
});
afterEach(() => {
handler.destroy();
container.remove();
});
it("encodes SGR press, drag, release, and wheel", () => {
container.dispatchEvent(
new MouseEvent("mousedown", {
button: 0,
buttons: 1,
clientX: 85,
clientY: 65,
}),
);
container.dispatchEvent(
new MouseEvent("mousemove", { buttons: 1, clientX: 105, clientY: 75 }),
);
container.dispatchEvent(
new MouseEvent("mouseup", { button: 0, clientX: 105, clientY: 75 }),
);
const wheel = new WheelEvent("wheel", {
deltaY: 100,
clientX: 105,
clientY: 75,
cancelable: true,
});
container.dispatchEvent(wheel);
expect(received).toEqual([
"\x1b[<0;8;5M",
"\x1b[<32;10;6M",
"\x1b[<0;10;6m",
"\x1b[<65;10;6M",
]);
expect(wheel.defaultPrevented).toBe(true);
});
it("emits focus reports only when mode 1004 is enabled", () => {
const textarea = container.querySelector("textarea")!;
textarea.dispatchEvent(new FocusEvent("focus"));
textarea.dispatchEvent(new FocusEvent("blur"));
expect(received).toEqual(["\x1b[I", "\x1b[O"]);
received = [];
core.focusEvents = () => false;
textarea.dispatchEvent(new FocusEvent("focus"));
textarea.dispatchEvent(new FocusEvent("blur"));
expect(received).toEqual([]);
});
});