import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js"; describe("TUIChat - User Input Tests", () => { testBothModes("shows typed text in input field", (mode) => { const { lastFrame, stdin } = renderInMode(mode); stdin.write("Testing 123"); const frame = lastFrame(); // The input might be in a different format, let's be more flexible expect(frame ? frame.toLowerCase() : "").toMatch( /testing|123|ask anything/, ); // Mode-specific assertions if (mode === "remote") { expect(frame).toContain("Remote Mode"); } else { expect(frame).not.toContain("Remote Mode"); } }); testBothModes("handles Enter key to submit", async (mode) => { const { lastFrame, stdin } = renderInMode(mode); const beforeEnter = lastFrame(); expect(beforeEnter).toContain("Ask anything"); stdin.write("\r"); // Wait for the UI to update after pressing enter await new Promise((resolve) => setTimeout(resolve, 50)); const afterEnter = lastFrame(); // The UI should remain stable after Enter (no crash) expect(afterEnter).toBeDefined(); expect(afterEnter).toContain("Ask anything"); // Local mode specific features if (mode === "local") { expect(afterEnter).toContain("@ for context"); expect(afterEnter).toContain("/ for slash commands"); } }); testBothModes( "handles special characters in input without crashing", (mode) => { const { lastFrame, stdin } = renderInMode(mode); // Try typing various special characters stdin.write("!@#$%^&*()"); const frame = lastFrame(); // Should handle special characters without crashing expect(frame).toBeDefined(); expect(frame).not.toBe(""); // UI should still be functional expect(frame).toContain("Ask anything"); // Mode-specific UI elements if (mode === "remote") { expect(frame).toContain("Remote Mode"); } else { expect(frame).toContain("Continue CLI"); } }, ); });