fix(FN-911): close refine dropdown immediately on selection

- Close the refine model dropdown as soon as a selection is made instead of waiting for the next render cycle
- Add test verifying the dropdown closes immediately upon refine selection in QuickEntryBox
This commit is contained in:
gsxdsm
2026-04-04 11:37:44 -07:00
parent 94f035ca53
commit fec4642003
2 changed files with 29 additions and 1 deletions

View File

@@ -589,11 +589,11 @@ export function QuickEntryBox({ onCreate, addToast, tasks = [], availableModels,
const trimmed = description.trim();
if (!trimmed || isRefining) return;
setIsRefineMenuOpen(false);
setIsRefining(true);
try {
const refined = await refineText(trimmed, type);
setDescription(refined);
setIsRefineMenuOpen(false);
addToast("Description refined with AI", "success");
// Auto-resize textarea after content update
if (textareaRef.current) {

View File

@@ -1321,6 +1321,34 @@ describe("QuickEntryBox", () => {
});
});
it("closes refine menu immediately when option is clicked (before API response)", async () => {
const { refineText } = await import("../../api");
// Use a slow promise to ensure we can check the menu is closed before it resolves
vi.mocked(refineText).mockImplementation(
() => new Promise((resolve) => setTimeout(() => resolve("Refined"), 500)),
);
renderQuickEntryBox({});
expandQuickEntry();
const textarea = screen.getByTestId("quick-entry-input");
fireEvent.change(textarea, { target: { value: "Original text" } });
fireEvent.click(screen.getByTestId("refine-button"));
// Menu should be open
expect(screen.getByTestId("refine-clarify")).toBeTruthy();
// Click on an option
fireEvent.click(screen.getByTestId("refine-clarify"));
// Menu should close IMMEDIATELY (before the slow promise resolves)
expect(screen.queryByTestId("refine-clarify")).toBeNull();
// The loading state should still be shown
const refineButton = screen.getByTestId("refine-button");
expect(refineButton.textContent).toContain("Refining...");
});
it("successful refinement updates textarea content", async () => {
const { refineText } = await import("../../api");
vi.mocked(refineText).mockResolvedValueOnce("Refined description");