Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions extensions/cli/src/ui/__tests__/TUIChat.editMessage.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js";
import { renderInMode, testBothModes } from "./TUIChat.dualModeHelper.js";

async function waitForCondition(
conditionFn: () => boolean,
timeoutMs = 2000,
intervalMs = 50,
): Promise<void> {
const startTime = Date.now();
while (Date.now() - startTime < timeoutMs) {
if (conditionFn()) {
return;
}
await new Promise((resolve) => setTimeout(resolve, intervalMs));
}
}

/**
* Integration tests for the message edit feature in TUIChat
Expand All @@ -10,7 +24,6 @@ import { testBothModes, renderInMode } from "./TUIChat.dualModeHelper.js";
* 4. History is rewound and new message is submitted
* 5. Chat updates correctly
*/

describe("TUIChat - Message Edit Feature", () => {
testBothModes("double Esc should open edit selector", async (mode) => {
const { lastFrame, stdin } = renderInMode(mode);
Expand Down Expand Up @@ -119,7 +132,11 @@ describe("TUIChat - Message Edit Feature", () => {
// Perform various operations
stdin.write("\u001b");
stdin.write("\u001b"); // Open edit with separate Esc presses
await new Promise((resolve) => setTimeout(resolve, 100));

// Wait for selector to open (poll instead of fixed timeout)
await waitForCondition(
() => lastFrame()?.includes("No user messages to edit") ?? false,
);

// Verify selector opened
let frame = lastFrame();
Expand All @@ -130,7 +147,11 @@ describe("TUIChat - Message Edit Feature", () => {
await new Promise((resolve) => setTimeout(resolve, 50));

stdin.write("\u001b"); // Close
await new Promise((resolve) => setTimeout(resolve, 100));

// Wait for selector to close (poll instead of fixed timeout)
await waitForCondition(
() => !(lastFrame()?.includes("No user messages to edit") ?? true),
);

frame = lastFrame();

Expand Down
Loading