| 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 - Basic UI Tests", () => { |
| 8 | let context: any; |
| 9 | |
| 10 | beforeEach(() => { |
| 11 | context = createUITestContext({ |
| 12 | allServicesReady: true, |
| 13 | serviceState: "ready", |
| 14 | serviceValue: { some: "data" }, |
| 15 | }); |
| 16 | }); |
| 17 | |
| 18 | afterEach(() => { |
| 19 | context.cleanup(); |
| 20 | }); |
| 21 | |
| 22 | it("renders without crashing", () => { |
| 23 | const { lastFrame } = render(React.createElement(AppRoot)); |
| 24 | const frame = lastFrame(); |
| 25 | |
| 26 | expect(frame).toBeDefined(); |
| 27 | if (frame) { |
| 28 | expect(frame.length).toBeGreaterThan(0); |
| 29 | } |
| 30 | }); |
| 31 | |
| 32 | it("shows UI even when services are loading", () => { |
| 33 | // Override for this test |
| 34 | context.mockUseServices.mockReturnValue({ |
| 35 | services: {}, |
| 36 | loading: true, |
| 37 | error: null, |
| 38 | allReady: false, |
| 39 | }); |
| 40 | |
| 41 | const { lastFrame } = render(React.createElement(AppRoot)); |
| 42 | const frame = lastFrame(); |
| 43 | |
| 44 | expect(frame).toBeDefined(); |
| 45 | if (frame) { |
| 46 | // Should show the chat UI even while loading |
| 47 | expect(frame).toContain("Ask anything"); |
| 48 | } |
| 49 | }); |
| 50 | |
| 51 | it("handles remote URL prop", () => { |
| 52 | const { lastFrame } = render( |
| 53 | React.createElement(AppRoot, { remoteUrl: "http://localhost:3000" }), |
| 54 | ); |
| 55 | const frame = lastFrame(); |
| 56 | |
| 57 | expect(frame).toBeDefined(); |
| 58 | if (frame) { |
| 59 | expect(frame.length).toBeGreaterThan(0); |
| 60 | } |
| 61 | }); |
| 62 | }); |