| 1 | import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js"; |
| 2 | |
| 3 | describe("TUIChat - @ File Search Tests", () => { |
| 4 | testBothModes("shows @ character when user types @", async (mode) => { |
| 5 | const { lastFrame, stdin } = renderInMode(mode); |
| 6 | |
| 7 | // Wait a bit for initial render |
| 8 | await new Promise((resolve) => setTimeout(resolve, 50)); |
| 9 | |
| 10 | // Type the @ character to trigger file search |
| 11 | stdin.write("@"); |
| 12 | |
| 13 | // Wait longer for file search to initialize and display files |
| 14 | await new Promise((resolve) => setTimeout(resolve, 200)); |
| 15 | |
| 16 | const frame = lastFrame()!; |
| 17 | |
| 18 | // Should show @ character in input or show file search UI |
| 19 | // The @ might be in the input line or in a file search UI |
| 20 | const hasAtSymbol = frame.includes("@") || frame.includes("◉ @"); |
| 21 | expect(hasAtSymbol).toBe(true); |
| 22 | |
| 23 | // Mode-specific UI |
| 24 | if (mode === "remote") { |
| 25 | expect(frame).toContain("Remote Mode"); |
| 26 | } else { |
| 27 | expect(frame).not.toContain("Remote Mode"); |
| 28 | expect(frame).toContain("Continue CLI"); |
| 29 | } |
| 30 | }); |
| 31 | |
| 32 | testBothModes("shows search text when user types after @", async (mode) => { |
| 33 | const { lastFrame, stdin } = renderInMode(mode); |
| 34 | |
| 35 | // Type @ followed by text to filter files |
| 36 | stdin.write("@READ"); |
| 37 | |
| 38 | // Wait for file search to filter and display results |
| 39 | await new Promise((resolve) => setTimeout(resolve, 100)); |
| 40 | |
| 41 | const frame = lastFrame()!; |
| 42 | |
| 43 | // Should show the typed text |
| 44 | expect(frame).toContain("@READ"); |
| 45 | |
| 46 | // In local mode, should show either navigation hints or files |
| 47 | if (mode === "local") { |
| 48 | // Should show either navigation hints or at least indicate file search is working |
| 49 | const hasNavigationHints = frame.includes("↑/↓ to navigate"); |
| 50 | const hasFileSearch = |
| 51 | frame.includes("@READ") && !frame.includes("Remote Mode"); |
| 52 | expect(hasNavigationHints || hasFileSearch).toBe(true); |
| 53 | } |
| 54 | |
| 55 | // Mode-specific checks |
| 56 | if (mode === "remote") { |
| 57 | expect(frame).toContain("Remote Mode"); |
| 58 | } else { |
| 59 | expect(frame).not.toContain("Remote Mode"); |
| 60 | } |
| 61 | }); |
| 62 | |
| 63 | testBothModes("handles multiple @ characters", async (mode) => { |
| 64 | const { lastFrame, stdin } = renderInMode(mode); |
| 65 | |
| 66 | // Type multiple @ characters |
| 67 | stdin.write("@@test"); |
| 68 | |
| 69 | // Wait for UI update |
| 70 | await new Promise((resolve) => setTimeout(resolve, 100)); |
| 71 | |
| 72 | const frame = lastFrame(); |
| 73 | |
| 74 | // Should handle multiple @ without crashing |
| 75 | expect(frame).toBeDefined(); |
| 76 | expect(frame).toContain("@@test"); |
| 77 | |
| 78 | // Mode-specific UI elements |
| 79 | if (mode === "remote") { |
| 80 | expect(frame).toContain("Remote Mode"); |
| 81 | } else { |
| 82 | expect(frame).toContain("Continue CLI"); |
| 83 | } |
| 84 | }); |
| 85 | |
| 86 | testBothModes("handles @ character input without crashing", async (mode) => { |
| 87 | const { lastFrame, stdin } = renderInMode(mode); |
| 88 | |
| 89 | // Type @ to trigger file search |
| 90 | stdin.write("@"); |
| 91 | |
| 92 | // Wait for potential async operations |
| 93 | await new Promise((resolve) => setTimeout(resolve, 50)); |
| 94 | |
| 95 | const frame = lastFrame()!; |
| 96 | |
| 97 | // Should not crash and show something |
| 98 | expect(frame).toBeDefined(); |
| 99 | expect(frame.length).toBeGreaterThan(0); |
| 100 | |
| 101 | // In local mode, should show either navigation hints or file search UI |
| 102 | if (mode === "local") { |
| 103 | // Should show either navigation hints or at least the @ character in file search |
| 104 | const hasNavigationHints = frame.includes("↑/↓ to navigate"); |
| 105 | const hasFileSearchUI = |
| 106 | frame.includes("@") && !frame.includes("Remote Mode"); |
| 107 | expect(hasNavigationHints || hasFileSearchUI).toBe(true); |
| 108 | } |
| 109 | }); |
| 110 | }); |