From 2e4746e4d5b0480d36b8138bebde9ee47b2d0ed9 Mon Sep 17 00:00:00 2001 From: Tomasz Stefaniak Date: Thu, 7 Aug 2025 08:00:44 -0700 Subject: [PATCH] fix: tests --- src/ui/AppRoot.tsx | 24 +++++++++++++++++++ src/ui/__tests__/TUIChat.basic.test.tsx | 8 +++---- src/ui/__tests__/TUIChat.dualModeHelper.tsx | 6 ++--- src/ui/__tests__/TUIChat.remote.test.tsx | 12 +++++----- src/ui/__tests__/TUIChat.toolDisplay.test.tsx | 10 ++++---- src/ui/index.ts | 23 +++++++----------- 6 files changed, 51 insertions(+), 32 deletions(-) create mode 100644 src/ui/AppRoot.tsx diff --git a/src/ui/AppRoot.tsx b/src/ui/AppRoot.tsx new file mode 100644 index 000000000..84dd2094a --- /dev/null +++ b/src/ui/AppRoot.tsx @@ -0,0 +1,24 @@ +import React from "react"; + +import { NavigationProvider } from "./context/NavigationContext.js"; +import { TUIChat } from "./TUIChat.js"; + +interface AppRootProps { + remoteUrl?: string; + configPath?: string; + initialPrompt?: string; + resume?: boolean; + additionalRules?: string[]; +} + +/** + * Root component that wraps TUIChat with all necessary providers + * This is the main entry point for the UI application + */ +export const AppRoot: React.FC = (props) => { + return ( + + + + ); +}; \ No newline at end of file diff --git a/src/ui/__tests__/TUIChat.basic.test.tsx b/src/ui/__tests__/TUIChat.basic.test.tsx index bc31f6af6..faa083d27 100644 --- a/src/ui/__tests__/TUIChat.basic.test.tsx +++ b/src/ui/__tests__/TUIChat.basic.test.tsx @@ -2,7 +2,7 @@ import { render } from "ink-testing-library"; import React from "react"; import { createUITestContext } from "../../test-helpers/ui-test-context.js"; -import { TUIChat } from "../TUIChat.js"; +import { AppRoot } from "../AppRoot.js"; describe("TUIChat - Basic UI Tests", () => { let context: any; @@ -20,7 +20,7 @@ describe("TUIChat - Basic UI Tests", () => { }); it("renders without crashing", () => { - const { lastFrame } = render(React.createElement(TUIChat)); + const { lastFrame } = render(React.createElement(AppRoot)); const frame = lastFrame(); expect(frame).toBeDefined(); @@ -38,7 +38,7 @@ describe("TUIChat - Basic UI Tests", () => { allReady: false, }); - const { lastFrame } = render(React.createElement(TUIChat)); + const { lastFrame } = render(React.createElement(AppRoot)); const frame = lastFrame(); expect(frame).toBeDefined(); @@ -50,7 +50,7 @@ describe("TUIChat - Basic UI Tests", () => { it("handles remote URL prop", () => { const { lastFrame } = render( - React.createElement(TUIChat, { remoteUrl: "http://localhost:3000" }) + React.createElement(AppRoot, { remoteUrl: "http://localhost:3000" }) ); const frame = lastFrame(); diff --git a/src/ui/__tests__/TUIChat.dualModeHelper.tsx b/src/ui/__tests__/TUIChat.dualModeHelper.tsx index 4904459ed..4db481274 100644 --- a/src/ui/__tests__/TUIChat.dualModeHelper.tsx +++ b/src/ui/__tests__/TUIChat.dualModeHelper.tsx @@ -2,7 +2,7 @@ import { render } from "ink-testing-library"; import React from "react"; import { createUITestContext } from "../../test-helpers/ui-test-context.js"; -import { TUIChat } from "../TUIChat.js"; +import { AppRoot } from "../AppRoot.js"; export type TestMode = 'local' | 'remote'; @@ -68,8 +68,8 @@ export function testBothModes( export function renderInMode(mode: TestMode, props?: any) { return render( mode === 'remote' - ? React.createElement(TUIChat, { remoteUrl: "http://localhost:3000", ...props }) - : React.createElement(TUIChat, props) + ? React.createElement(AppRoot, { remoteUrl: "http://localhost:3000", ...props }) + : React.createElement(AppRoot, props) ) as ReturnType; // Explicit type to avoid TypeScript issues } diff --git a/src/ui/__tests__/TUIChat.remote.test.tsx b/src/ui/__tests__/TUIChat.remote.test.tsx index 6911ce550..a279c084b 100644 --- a/src/ui/__tests__/TUIChat.remote.test.tsx +++ b/src/ui/__tests__/TUIChat.remote.test.tsx @@ -2,7 +2,7 @@ import { render } from "ink-testing-library"; import React from "react"; import { createUITestContext } from "../../test-helpers/ui-test-context.js"; -import { TUIChat } from "../TUIChat.js"; +import { AppRoot } from "../AppRoot.js"; describe("TUIChat - Remote Server Tests", () => { let context: any; @@ -20,7 +20,7 @@ describe("TUIChat - Remote Server Tests", () => { it("renders in remote mode with remote URL", () => { const { lastFrame } = render( - + ); const frame = lastFrame(); @@ -31,7 +31,7 @@ describe("TUIChat - Remote Server Tests", () => { it("shows remote mode indicator", () => { const { lastFrame } = render( - + ); const frame = lastFrame(); @@ -41,7 +41,7 @@ describe("TUIChat - Remote Server Tests", () => { it("does not show service loading in remote mode", () => { const { lastFrame } = render( - + ); const frame = lastFrame(); @@ -54,7 +54,7 @@ describe("TUIChat - Remote Server Tests", () => { it("handles different remote URLs", () => { const { lastFrame } = render( - + ); const frame = lastFrame(); @@ -65,7 +65,7 @@ describe("TUIChat - Remote Server Tests", () => { it("shows slash commands in remote mode", async () => { const { lastFrame, stdin } = render( - + ); // Wait for initial render diff --git a/src/ui/__tests__/TUIChat.toolDisplay.test.tsx b/src/ui/__tests__/TUIChat.toolDisplay.test.tsx index e15389e39..d4e691939 100644 --- a/src/ui/__tests__/TUIChat.toolDisplay.test.tsx +++ b/src/ui/__tests__/TUIChat.toolDisplay.test.tsx @@ -2,7 +2,7 @@ import { render } from "ink-testing-library"; import React from "react"; import { createUITestContext } from "../../test-helpers/ui-test-context.js"; -import { TUIChat } from "../TUIChat.js"; +import { AppRoot } from "../AppRoot.js"; describe("TUIChat - Tool Display Tests", () => { let context: any; @@ -20,7 +20,7 @@ describe("TUIChat - Tool Display Tests", () => { it("renders without crashing when tools are available", () => { const { lastFrame } = render( - + ); const frame = lastFrame(); @@ -30,7 +30,7 @@ describe("TUIChat - Tool Display Tests", () => { it("handles UI with no tools configured", () => { const { lastFrame } = render( - + ); const frame = lastFrame(); @@ -41,7 +41,7 @@ describe("TUIChat - Tool Display Tests", () => { it("maintains UI stability during tool operations", async () => { const { lastFrame, stdin } = render( - + ); // Type a message that might trigger tool use @@ -60,7 +60,7 @@ describe("TUIChat - Tool Display Tests", () => { it("shows tool-related slash commands", async () => { const { lastFrame, stdin } = render( - + ); // Wait for initial render diff --git a/src/ui/index.ts b/src/ui/index.ts index 389df7024..20899bff5 100644 --- a/src/ui/index.ts +++ b/src/ui/index.ts @@ -5,8 +5,7 @@ import { PermissionMode } from "../permissions/types.js"; import { initializeServices } from "../services/index.js"; import { ServiceContainerProvider } from "../services/ServiceContainerContext.js"; -import { NavigationProvider } from "./context/NavigationContext.js"; -import { TUIChat } from "./TUIChat.js"; +import { AppRoot } from "./AppRoot.js"; export { MarkdownRenderer } from "./MarkdownRenderer.js"; @@ -38,13 +37,11 @@ export async function startTUIChat( // Start the TUI immediately - it will handle loading states const { unmount } = render( React.createElement(ServiceContainerProvider, { - children: React.createElement(NavigationProvider, { - children: React.createElement(TUIChat, { - configPath, - initialPrompt, - resume, - additionalRules, - }) + children: React.createElement(AppRoot, { + configPath, + initialPrompt, + resume, + additionalRules, }) }) ); @@ -65,11 +62,9 @@ export async function startRemoteTUIChat( // Start the TUI in remote mode - no services needed const { unmount } = render( React.createElement(ServiceContainerProvider, { - children: React.createElement(NavigationProvider, { - children: React.createElement(TUIChat, { - remoteUrl, - initialPrompt, - }) + children: React.createElement(AppRoot, { + remoteUrl, + initialPrompt, }) }) );