fix: tests

This commit is contained in:
Tomasz Stefaniak 2025-08-07 08:00:44 -07:00
parent 1c746a625a
commit 2e4746e4d5
6 changed files with 51 additions and 32 deletions

24
src/ui/AppRoot.tsx Normal file
View file

@ -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<AppRootProps> = (props) => {
return (
<NavigationProvider>
<TUIChat {...props} />
</NavigationProvider>
);
};

View file

@ -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();

View file

@ -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<typeof render>; // Explicit type to avoid TypeScript issues
}

View file

@ -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(
<TUIChat remoteUrl="http://localhost:3000" />
<AppRoot remoteUrl="http://localhost:3000" />
);
const frame = lastFrame();
@ -31,7 +31,7 @@ describe("TUIChat - Remote Server Tests", () => {
it("shows remote mode indicator", () => {
const { lastFrame } = render(
<TUIChat remoteUrl="http://localhost:3000" />
<AppRoot remoteUrl="http://localhost:3000" />
);
const frame = lastFrame();
@ -41,7 +41,7 @@ describe("TUIChat - Remote Server Tests", () => {
it("does not show service loading in remote mode", () => {
const { lastFrame } = render(
<TUIChat remoteUrl="http://localhost:3000" />
<AppRoot remoteUrl="http://localhost:3000" />
);
const frame = lastFrame();
@ -54,7 +54,7 @@ describe("TUIChat - Remote Server Tests", () => {
it("handles different remote URLs", () => {
const { lastFrame } = render(
<TUIChat remoteUrl="https://api.example.com:8080" />
<AppRoot remoteUrl="https://api.example.com:8080" />
);
const frame = lastFrame();
@ -65,7 +65,7 @@ describe("TUIChat - Remote Server Tests", () => {
it("shows slash commands in remote mode", async () => {
const { lastFrame, stdin } = render(
<TUIChat remoteUrl="http://localhost:3000" />
<AppRoot remoteUrl="http://localhost:3000" />
);
// Wait for initial render

View file

@ -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(
<TUIChat remoteUrl="http://localhost:3000" />
<AppRoot remoteUrl="http://localhost:3000" />
);
const frame = lastFrame();
@ -30,7 +30,7 @@ describe("TUIChat - Tool Display Tests", () => {
it("handles UI with no tools configured", () => {
const { lastFrame } = render(
<TUIChat remoteUrl="http://localhost:3000" />
<AppRoot remoteUrl="http://localhost:3000" />
);
const frame = lastFrame();
@ -41,7 +41,7 @@ describe("TUIChat - Tool Display Tests", () => {
it("maintains UI stability during tool operations", async () => {
const { lastFrame, stdin } = render(
<TUIChat remoteUrl="http://localhost:3000" />
<AppRoot remoteUrl="http://localhost:3000" />
);
// 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(
<TUIChat remoteUrl="http://localhost:3000" />
<AppRoot remoteUrl="http://localhost:3000" />
);
// Wait for initial render

View file

@ -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,
})
})
);