diff --git a/src/ui/__tests__/TUIChat.dualModeHelper.ts b/src/ui/__tests__/TUIChat.dualModeHelper.ts new file mode 100644 index 000000000..7aa028f07 --- /dev/null +++ b/src/ui/__tests__/TUIChat.dualModeHelper.ts @@ -0,0 +1,92 @@ +import { render } from "ink-testing-library"; +import React from "react"; +import { createUITestContext } from "../../test-helpers/ui-test-context.js"; +import TUIChat from "../TUIChat.js"; + +export type TestMode = 'local' | 'remote'; + +/** + * Helper to run a test in both local and remote modes + * This creates two test suites - one for each mode + */ +export function testBothModes( + name: string, + testFn: (mode: TestMode) => void | Promise +) { + describe(`${name} [LOCAL MODE]`, () => { + let context: any; + + beforeEach(() => { + context = createUITestContext({ + allServicesReady: true, + serviceState: "ready", + }); + }); + + afterEach(() => { + context.cleanup(); + }); + + it("works in local mode", async () => { + await testFn('local'); + }); + }); + + describe(`${name} [REMOTE MODE]`, () => { + let context: any; + + beforeEach(() => { + context = createUITestContext({ + allServicesReady: true, + serviceState: "ready", + }); + }); + + afterEach(() => { + context.cleanup(); + }); + + it("works in remote mode", async () => { + await testFn('remote'); + }); + }); +} + +/** + * Helper to render TUIChat in the specified mode + */ +export function renderInMode(mode: TestMode, props?: any) { + return render( + mode === 'remote' + ? React.createElement(TUIChat, { remoteUrl: "http://localhost:3000", ...props }) + : React.createElement(TUIChat, props) + ) as ReturnType; // Explicit type to avoid TypeScript issues +} + +/** + * Helper to run a test in only one mode + */ +export function testSingleMode( + name: string, + mode: TestMode, + testFn: () => void | Promise +) { + describe(`${name} [${mode.toUpperCase()} MODE ONLY]`, () => { + let context: any; + + beforeEach(() => { + context = createUITestContext({ + allServicesReady: true, + serviceState: "ready", + }); + }); + + afterEach(() => { + context.cleanup(); + }); + + it(`works in ${mode} mode`, async () => { + await testFn(); + }); + }); +} \ No newline at end of file diff --git a/src/ui/__tests__/TUIChat.messages.dual.test.tsx b/src/ui/__tests__/TUIChat.messages.dual.test.tsx new file mode 100644 index 000000000..80dd07479 --- /dev/null +++ b/src/ui/__tests__/TUIChat.messages.dual.test.tsx @@ -0,0 +1,6 @@ +// This file has been removed - functionality merged into TUIChat.messages.test.tsx +describe('placeholder', () => { + it('exists', () => { + expect(true).toBe(true); + }); +}); \ No newline at end of file diff --git a/src/ui/__tests__/TUIChat.messages.test.tsx b/src/ui/__tests__/TUIChat.messages.test.tsx index 71d4213a7..3c877c674 100644 --- a/src/ui/__tests__/TUIChat.messages.test.tsx +++ b/src/ui/__tests__/TUIChat.messages.test.tsx @@ -1,30 +1,10 @@ -import { render } from "ink-testing-library"; -import React from "react"; import type { ChatCompletionMessageParam } from "openai/resources/index.js"; import { createUITestContext } from "../../test-helpers/ui-test-context.js"; -import TUIChat from "../TUIChat.js"; - -// Import our new test utilities (they will work with mocked modules) -import { renderWithServices } from "../../test-helpers/renderWithServices.js"; -import { createTestServiceContainer } from "../../test-helpers/testServiceContainer.js"; +import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js"; describe("TUIChat - Message Display Tests", () => { - let context: any; - - beforeEach(() => { - context = createUITestContext({ - allServicesReady: true, - serviceState: "ready", - }); - }); - - afterEach(() => { - context.cleanup(); - }); - - it("displays empty chat correctly in local mode", () => { - // Test local mode - services are mocked to be ready - const { lastFrame } = render(); + testBothModes("displays empty chat correctly", (mode) => { + const { lastFrame } = renderInMode(mode); const frame = lastFrame(); @@ -34,16 +14,42 @@ describe("TUIChat - Message Display Tests", () => { // Should have box borders (using the actual characters) expect(frame).toContain("│"); - // Should NOT show remote mode indicator in local mode - expect(frame).not.toContain("Remote Mode"); - - // Should show Continue CLI branding - expect(frame).toContain("Continue CLI"); + // Mode-specific assertions + if (mode === 'remote') { + expect(frame).toContain("Remote Mode"); + } else { + expect(frame).not.toContain("Remote Mode"); + expect(frame).toContain("Continue CLI"); + } }); - it("displays messages in correct order in local mode", () => { + testBothModes("shows input prompt", (mode) => { + const { lastFrame } = renderInMode(mode); + + const frame = lastFrame(); + + // Should show the default prompt + expect(frame).toContain("Ask anything"); + + // Should show slash commands hint + expect(frame).toContain("/ for slash commands"); + + // In local mode, also shows context hint + if (mode === 'local') { + expect(frame).toContain("@ for context"); + } + + // Verify mode-specific UI + if (mode === 'remote') { + expect(frame).toContain("Remote Mode"); + } else { + expect(frame).toContain("Continue CLI"); + } + }); + + testBothModes("displays messages in correct order", (mode) => { // Set up chat history in context - context = createUITestContext({ + const context = createUITestContext({ allServicesReady: true, serviceState: "ready", chatMessages: [ @@ -54,48 +60,18 @@ describe("TUIChat - Message Display Tests", () => { ], }); - // Test local mode - const { lastFrame } = render(); + const { lastFrame } = renderInMode(mode); // Verify the component renders const frame = lastFrame(); expect(frame).toContain("Ask anything"); // In local mode, we have access to more UI elements - expect(frame).toContain("@ for context"); - expect(frame).toContain("/ for slash commands"); - }); + if (mode === 'local') { + expect(frame).toContain("@ for context"); + expect(frame).toContain("/ for slash commands"); + } - it("shows input prompt in local mode", () => { - // Test local mode - const { lastFrame } = render(); - - const frame = lastFrame(); - - // Should show the default prompt - expect(frame).toContain("Ask anything"); - - // Should show context hint - expect(frame).toContain("@ for context"); - - // Should show slash commands hint - expect(frame).toContain("/ for slash commands"); - - // Should NOT indicate remote mode - expect(frame).not.toContain("Remote Mode"); - }); - - // Additional test to demonstrate remote mode still works - it("still supports remote mode for remote server testing", () => { - // Remote mode should still work for testing remote connections - const { lastFrame } = render(); - - const frame = lastFrame(); - - // Should show remote mode indicator - expect(frame).toContain("Remote Mode"); - - // Should still have the UI - expect(frame).toContain("Ask anything"); + context.cleanup(); }); }); \ No newline at end of file