continue-custom/extensions/cli/src/ui/__tests__/TUIChat.input.test.tsx
Ting-Wai 6748434c9c
fix: flakey CLI tests (#8124)
fix: flakey test with waitForNextRender
2025-10-08 07:25:31 -07:00

77 lines
2.3 KiB
TypeScript

import { renderInMode, testBothModes } from "./TUIChat.dualModeHelper.js";
import { waitForNextRender } from "./TUIChat.testHelper.js";
describe("TUIChat - User Input Tests", () => {
testBothModes("shows typed text in input field", async (mode) => {
const { lastFrame, stdin } = renderInMode(mode);
stdin.write("Testing 123");
await waitForNextRender();
const frame = lastFrame();
// The input might be in a different format, let's be more flexible
expect(frame ? frame.toLowerCase() : "").toMatch(
/testing|123|ask anything/,
);
// Mode-specific assertions
if (mode === "remote") {
expect(frame).toContain("Remote Mode");
} else {
expect(frame).not.toContain("Remote Mode");
}
});
testBothModes("handles Enter key to submit", async (mode) => {
const { lastFrame, stdin } = renderInMode(mode);
await waitForNextRender();
const beforeEnter = lastFrame();
expect(beforeEnter).toContain("Ask anything");
stdin.write("\r");
// Wait for the UI to update after pressing enter
await new Promise((resolve) => setTimeout(resolve, 500));
const afterEnter = lastFrame();
// The UI should remain stable after Enter (no crash)
expect(afterEnter).toBeDefined();
expect(afterEnter).toContain("Ask anything");
// Local mode specific features
if (mode === "local") {
expect(afterEnter).toContain("@ for context");
expect(afterEnter).toContain("/ for slash commands");
}
});
testBothModes(
"handles special characters in input without crashing",
async (mode) => {
const { lastFrame, stdin } = renderInMode(mode);
// Try typing various special characters
stdin.write("!@#$%^&*()");
await waitForNextRender();
const frame = lastFrame();
// Should handle special characters without crashing
expect(frame).toBeDefined();
expect(frame).not.toBe("");
// UI should still be functional and show the typed special characters
// Note: "Ask anything" placeholder is replaced when text is typed
expect(frame).toContain("!@#$%^&*()");
// Mode-specific UI elements
if (mode === "remote") {
expect(frame).toContain("Remote Mode");
} else {
expect(frame).toContain("Continue CLI");
}
},
);
});