Elffuss BraidHub

kikocis/continue public

c61dd95048cf · 3.0 KiBRawPermalink
1import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js";
2
3describe("TUIChat - Slash Commands Tests", () => {
4 testBothModes("shows slash when user types /", async (mode) => {
5 const { lastFrame, stdin } = renderInMode(mode);
6
7 // Type / to trigger slash command
8 stdin.write("/");
9
10 // Wait a bit for the UI to update
11 await new Promise((resolve) => setTimeout(resolve, 50));
12
13 const frame = lastFrame();
14
15 // Should show the slash character
16 expect(frame).toContain("/");
17
18 // Mode-specific assertions
19 if (mode === "remote") {
20 expect(frame).toContain("Remote Mode");
21 } else {
22 expect(frame).not.toContain("Remote Mode");
23 expect(frame).toContain("Continue CLI");
24 }
25 });
26
27 testBothModes("filters slash commands when typing /log", async (mode) => {
28 const { lastFrame, stdin } = renderInMode(mode);
29
30 // Type /log to trigger slash command filtering
31 stdin.write("/log");
32
33 // Wait a bit for the UI to update (allow extra time in both modes)
34 await new Promise((resolve) =>
35 setTimeout(resolve, mode === "remote" ? 200 : 150),
36 );
37
38 const frame = lastFrame();
39
40 // Should show the typed command
41 expect(frame).toContain("/log");
42
43 // Mode-specific UI elements
44 if (mode === "remote") {
45 expect(frame).toContain("Remote Mode");
46 } else {
47 expect(frame).not.toContain("Remote Mode");
48 expect(frame).toContain("Continue CLI");
49 }
50 });
51
52 testBothModes("handles tab key after slash command", async (mode) => {
53 const { lastFrame, stdin } = renderInMode(mode);
54
55 // Type /log and then tab
56 stdin.write("/log");
57
58 await new Promise((resolve) => setTimeout(resolve, 50));
59
60 stdin.write("\t");
61
62 await new Promise((resolve) => setTimeout(resolve, 50));
63
64 const frameAfterTab = lastFrame();
65
66 // Should not crash after tab
67 expect(frameAfterTab).toBeDefined();
68 if (frameAfterTab) {
69 expect(frameAfterTab.length).toBeGreaterThan(0);
70
71 // Mode-specific checks
72 if (mode === "remote") {
73 expect(frameAfterTab).toContain("Remote Mode");
74 } else {
75 expect(frameAfterTab).not.toContain("Remote Mode");
76 }
77 }
78 });
79
80 testBothModes("shows slash command menu when typing /", async (mode) => {
81 const { lastFrame, stdin } = renderInMode(mode);
82
83 // Type just /
84 stdin.write("/");
85
86 await new Promise((resolve) =>
87 setTimeout(resolve, mode === "remote" ? 120 : 50),
88 );
89
90 const frame = lastFrame();
91
92 // Should show the slash
93 expect(frame).toContain("/");
94
95 // In remote mode, slash command menu shows immediately
96 if (mode === "remote") {
97 expect(frame).toContain("/exit");
98 expect(frame).toContain("Remote Mode");
99 } else {
100 // In local mode, the / is shown in the input
101 expect(frame).toContain("Continue CLI");
102 // The slash should be visible somewhere in the frame
103 // It might be in the input area or in a command palette
104 const hasSlash = frame ? frame.includes("/") : false;
105 expect(hasSlash).toBe(true);
106 }
107 });
108});