| 1 | import { render } from "ink-testing-library"; |
| 2 | import React from "react"; |
| 3 | |
| 4 | import { createUITestContext } from "../../test-helpers/ui-test-context.js"; |
| 5 | import { AppRoot } from "../AppRoot.js"; |
| 6 | |
| 7 | describe("TUIChat - Remote Server Tests", () => { |
| 8 | let context: any; |
| 9 | |
| 10 | beforeEach(() => { |
| 11 | context = createUITestContext({ |
| 12 | allServicesReady: true, |
| 13 | serviceState: "ready", |
| 14 | }); |
| 15 | }); |
| 16 | |
| 17 | afterEach(() => { |
| 18 | context.cleanup(); |
| 19 | }); |
| 20 | |
| 21 | it("renders in remote mode with remote URL", () => { |
| 22 | const { lastFrame } = render(<AppRoot remoteUrl="http://localhost:3000" />); |
| 23 | const frame = lastFrame(); |
| 24 | |
| 25 | expect(frame).toBeDefined(); |
| 26 | expect(frame).toContain("Remote Mode"); |
| 27 | expect(frame).toContain("Ask anything"); |
| 28 | }); |
| 29 | |
| 30 | it("shows remote mode indicator", () => { |
| 31 | const { lastFrame } = render(<AppRoot remoteUrl="http://localhost:3000" />); |
| 32 | const frame = lastFrame(); |
| 33 | |
| 34 | // Should show remote mode in the UI |
| 35 | expect(frame).toContain("◉ Remote Mode"); |
| 36 | }); |
| 37 | |
| 38 | it("does not show service loading in remote mode", () => { |
| 39 | const { lastFrame } = render(<AppRoot remoteUrl="http://localhost:3000" />); |
| 40 | const frame = lastFrame(); |
| 41 | |
| 42 | // Should not show loading services message |
| 43 | expect(frame).not.toContain("Loading services"); |
| 44 | |
| 45 | // Should go directly to chat UI |
| 46 | expect(frame).toContain("Ask anything"); |
| 47 | }); |
| 48 | |
| 49 | it("handles different remote URLs", () => { |
| 50 | const { lastFrame } = render( |
| 51 | <AppRoot remoteUrl="https://api.example.com:8080" />, |
| 52 | ); |
| 53 | const frame = lastFrame(); |
| 54 | |
| 55 | // Should still work with different URLs |
| 56 | expect(frame).toBeDefined(); |
| 57 | expect(frame).toContain("Remote Mode"); |
| 58 | }); |
| 59 | |
| 60 | it("shows slash commands in remote mode", async () => { |
| 61 | const { lastFrame, stdin } = render( |
| 62 | <AppRoot remoteUrl="http://localhost:3000" />, |
| 63 | ); |
| 64 | |
| 65 | // Wait for initial render |
| 66 | await new Promise((resolve) => setTimeout(resolve, 50)); |
| 67 | |
| 68 | // Type / to see slash commands |
| 69 | stdin.write("/"); |
| 70 | |
| 71 | // Wait longer for slash command menu to appear |
| 72 | await new Promise((resolve) => setTimeout(resolve, 200)); |
| 73 | |
| 74 | const frame = lastFrame(); |
| 75 | |
| 76 | // Should show slash character at minimum |
| 77 | expect(frame).toContain("/"); |
| 78 | |
| 79 | // The slash command menu might show /exit or navigation instructions |
| 80 | // Different timing might show different states |
| 81 | const hasSlashCommandUI = frame |
| 82 | ? frame.includes("/exit") || |
| 83 | frame.includes("↑/↓ to navigate") || |
| 84 | frame.includes("◉ /") || |
| 85 | frame.includes("/ for slash commands") // Placeholder text is also valid |
| 86 | : false; |
| 87 | |
| 88 | expect(hasSlashCommandUI).toBe(true); |
| 89 | }); |
| 90 | }); |