Open History to see the last commit
1import { assert, describe, it } from "vitest";
2
3import { compileResolvedKeybindingRule, parseKeybindingShortcut } from "./keybindings";
4
5describe("server keybindings", () => {
6 it("parses shortcuts including plus key", () => {
7 assert.deepEqual(parseKeybindingShortcut("mod+j"), {
8 key: "j",
9 metaKey: false,
10 ctrlKey: false,
11 shiftKey: false,
12 altKey: false,
13 modKey: true,
14 });
15 assert.deepEqual(parseKeybindingShortcut("mod++"), {
16 key: "+",
17 metaKey: false,
18 ctrlKey: false,
19 shiftKey: false,
20 altKey: false,
21 modKey: true,
22 });
23 });
24
25 it("compiles valid rule with parsed when AST", () => {
26 const compiled = compileResolvedKeybindingRule({
27 key: "mod+d",
28 command: "terminal.split",
29 when: "terminalOpen && !terminalFocus",
30 });
31
32 assert.deepEqual(compiled, {
33 command: "terminal.split",
34 shortcut: {
35 key: "d",
36 metaKey: false,
37 ctrlKey: false,
38 shiftKey: false,
39 altKey: false,
40 modKey: true,
41 },
42 whenAst: {
43 type: "and",
44 left: { type: "identifier", name: "terminalOpen" },
45 right: {
46 type: "not",
47 node: { type: "identifier", name: "terminalFocus" },
48 },
49 },
50 });
51 });
52
53 it("rejects invalid rules", () => {
54 assert.isNull(
55 compileResolvedKeybindingRule({
56 key: "mod+shift+d+o",
57 command: "terminal.new",
58 }),
59 );
60
61 assert.isNull(
62 compileResolvedKeybindingRule({
63 key: "mod+d",
64 command: "terminal.split",
65 when: "terminalFocus && (",
66 }),
67 );
68 });
69});