Elffuss BraidHub

kikocis/continue public

main · 2.0 KiBRawPermalink
1import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js";
2
3describe("TUIChat - User Input Tests", () => {
4 testBothModes("shows typed text in input field", (mode) => {
5 const { lastFrame, stdin } = renderInMode(mode);
6
7 stdin.write("Testing 123");
8
9 const frame = lastFrame();
10 // The input might be in a different format, let's be more flexible
11 expect(frame ? frame.toLowerCase() : "").toMatch(
12 /testing|123|ask anything/,
13 );
14
15 // Mode-specific assertions
16 if (mode === "remote") {
17 expect(frame).toContain("Remote Mode");
18 } else {
19 expect(frame).not.toContain("Remote Mode");
20 }
21 });
22
23 testBothModes("handles Enter key to submit", async (mode) => {
24 const { lastFrame, stdin } = renderInMode(mode);
25
26 const beforeEnter = lastFrame();
27 expect(beforeEnter).toContain("Ask anything");
28
29 stdin.write("\r");
30
31 // Wait for the UI to update after pressing enter
32 await new Promise((resolve) => setTimeout(resolve, 50));
33
34 const afterEnter = lastFrame();
35
36 // The UI should remain stable after Enter (no crash)
37 expect(afterEnter).toBeDefined();
38 expect(afterEnter).toContain("Ask anything");
39
40 // Local mode specific features
41 if (mode === "local") {
42 expect(afterEnter).toContain("@ for context");
43 expect(afterEnter).toContain("/ for slash commands");
44 }
45 });
46
47 testBothModes(
48 "handles special characters in input without crashing",
49 (mode) => {
50 const { lastFrame, stdin } = renderInMode(mode);
51
52 // Try typing various special characters
53 stdin.write("!@#$%^&*()");
54
55 const frame = lastFrame();
56
57 // Should handle special characters without crashing
58 expect(frame).toBeDefined();
59 expect(frame).not.toBe("");
60
61 // UI should still be functional
62 expect(frame).toContain("Ask anything");
63
64 // Mode-specific UI elements
65 if (mode === "remote") {
66 expect(frame).toContain("Remote Mode");
67 } else {
68 expect(frame).toContain("Continue CLI");
69 }
70 },
71 );
72});