dual test mode
This commit is contained in:
parent
90bb223e20
commit
05a4cac90d
3 changed files with 140 additions and 66 deletions
92
src/ui/__tests__/TUIChat.dualModeHelper.ts
Normal file
92
src/ui/__tests__/TUIChat.dualModeHelper.ts
Normal file
|
|
@ -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<void>
|
||||
) {
|
||||
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<typeof render>; // 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<void>
|
||||
) {
|
||||
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();
|
||||
});
|
||||
});
|
||||
}
|
||||
6
src/ui/__tests__/TUIChat.messages.dual.test.tsx
Normal file
6
src/ui/__tests__/TUIChat.messages.dual.test.tsx
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
// This file has been removed - functionality merged into TUIChat.messages.test.tsx
|
||||
describe('placeholder', () => {
|
||||
it('exists', () => {
|
||||
expect(true).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
@ -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(<TUIChat />);
|
||||
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(<TUIChat />);
|
||||
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(<TUIChat />);
|
||||
|
||||
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(<TUIChat remoteUrl="http://localhost:3000" />);
|
||||
|
||||
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();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Reference in a new issue