-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathterminal-key-repeat.test.ts
More file actions
47 lines (42 loc) · 1.95 KB
/
Copy pathterminal-key-repeat.test.ts
File metadata and controls
47 lines (42 loc) · 1.95 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
import { describe, expect, it } from "vitest";
import {
ENTER_REPEAT_MIN_INTERVAL_MS,
shouldThrottleEnterRepeat,
shouldThrottleGenericKeyRepeat,
} from "./terminal-key-repeat";
describe("shouldThrottleGenericKeyRepeat", () => {
it("does not throttle Backspace repeat", () => {
const map = new Map<string, number>();
const event = { type: "keydown", repeat: true, key: "Backspace", code: "Backspace" };
expect(shouldThrottleGenericKeyRepeat(event, map, 100, 45)).toBe(false);
expect(shouldThrottleGenericKeyRepeat(event, map, 110, 45)).toBe(false);
});
it("does not throttle Delete repeat", () => {
const map = new Map<string, number>();
const event = { type: "keydown", repeat: true, key: "Delete", code: "Delete" };
expect(shouldThrottleGenericKeyRepeat(event, map, 100, 45)).toBe(false);
});
it("throttles other repeated keys within the interval", () => {
const map = new Map<string, number>();
const event = { type: "keydown", repeat: true, key: "a", code: "KeyA" };
expect(shouldThrottleGenericKeyRepeat(event, map, 100, 45)).toBe(false);
expect(shouldThrottleGenericKeyRepeat(event, map, 120, 45)).toBe(true);
expect(shouldThrottleGenericKeyRepeat(event, map, 150, 45)).toBe(false);
});
it("ignores non-repeat keydown", () => {
const map = new Map<string, number>();
const event = { type: "keydown", repeat: false, key: "a", code: "KeyA" };
expect(shouldThrottleGenericKeyRepeat(event, map, 100, 45)).toBe(false);
});
});
describe("shouldThrottleEnterRepeat", () => {
it("throttles Enter repeat within interval", () => {
const event = { type: "keydown", repeat: true, key: "Enter", code: "Enter" };
expect(
shouldThrottleEnterRepeat(event, 100, 100 + ENTER_REPEAT_MIN_INTERVAL_MS - 1, ENTER_REPEAT_MIN_INTERVAL_MS),
).toBe(true);
expect(
shouldThrottleEnterRepeat(event, 100, 100 + ENTER_REPEAT_MIN_INTERVAL_MS, ENTER_REPEAT_MIN_INTERVAL_MS),
).toBe(false);
});
});