Skip to content

The open-source app everyone uses to manage agents at work

test(ui): stabilize annotation popover submit-shortcut test (#11330)

Nicky Leach68ea3fcf5381
diff --git a/ui/src/components/DocumentAnnotationPopover.test.tsx b/ui/src/components/DocumentAnnotationPopover.test.tsx
index e52b0cebb8..fc8ecae2b0 100644
--- a/ui/src/components/DocumentAnnotationPopover.test.tsx
+++ b/ui/src/components/DocumentAnnotationPopover.test.tsx
@@ -102,6 +102,12 @@ describe("DocumentAnnotationPopover", () => {
const setter = Object.getOwnPropertyDescriptor(HTMLTextAreaElement.prototype, "value")?.set;
setter?.call(textarea, "Looks good");
textarea.dispatchEvent(new Event("input", { bubbles: true }));
+ // Wait for React to commit the composer value before the submit shortcut.
+ // The Comment button enables only after the controlled value updates, so its
+ // enabled state proves the keydown handler now reads the typed text. Without
+ // this wait the keydown can run against an empty composer and never submit.
+ const commentButton = Array.from(container.querySelectorAll("button")).find((button) => button.textContent?.includes("Comment")) as HTMLButtonElement;
+ await vi.waitFor(() => expect(commentButton.disabled).toBe(false));
textarea.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", metaKey: true, bubbles: true }));
await vi.waitFor(() => expect(mutations.create).toHaveBeenCalledWith("Looks good"));
});