diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/QuestionForm.test.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/QuestionForm.test.tsx new file mode 100644 index 00000000000..7d3427df2a5 --- /dev/null +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/QuestionForm.test.tsx @@ -0,0 +1,58 @@ +import { afterAll, afterEach, expect, mock, test } from "bun:test"; +import type { ApprovalRequest } from "@superset/chat/protocol"; + +const reactActGlobal = globalThis as { IS_REACT_ACT_ENVIRONMENT?: boolean }; +const previousActEnvironment = reactActGlobal.IS_REACT_ACT_ENVIRONMENT; +reactActGlobal.IS_REACT_ACT_ENVIRONMENT = true; +const { cleanup, fireEvent, render } = await import("@testing-library/react"); +const { QuestionForm } = await import("./QuestionForm"); + +afterEach(cleanup); +afterAll(() => { + reactActGlobal.IS_REACT_ACT_ENVIRONMENT = previousActEnvironment; +}); + +const form: NonNullable = { + message: "Pick an answer", + fields: [ + { + id: "choice", + input: "single", + required: true, + options: [{ value: "sample", label: "Sample" }], + }, + { id: "choice_custom", input: "text", title: "Other" }, + ], +}; +const item: ApprovalRequest = { + id: "question", + startedAtMs: 0, + kind: "approval_request", + targetItemId: null, + title: "Question", + status: "pending", + form, +}; + +test.each([ + { isComposing: true, keyCode: 13 }, + { isComposing: false, keyCode: 229 }, +])("keeps IME confirmation in Other without submitting (%j)", (ime) => { + const onRespond = mock(() => {}); + const view = render( + , + ); + const input = view.getByRole("textbox", { name: "Other" }); + fireEvent.compositionStart(input); + fireEvent.change(input, { target: { value: "각" } }); + fireEvent.keyDown(input, { key: "Enter", ...ime }); + expect(onRespond).not.toHaveBeenCalled(); + expect((input as HTMLInputElement).value).toBe("각"); + fireEvent.compositionEnd(input, { data: "각" }); + fireEvent.keyDown(input, { key: "Enter", isComposing: false, keyCode: 13 }); + expect(onRespond).toHaveBeenCalledTimes(1); + expect(onRespond).toHaveBeenCalledWith("question", { + type: "form", + values: { choice_custom: "각" }, + }); +}); diff --git a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/components/QuestionPage/QuestionPage.tsx b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/components/QuestionPage/QuestionPage.tsx index 77a2d8ca922..afae059489f 100644 --- a/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/components/QuestionPage/QuestionPage.tsx +++ b/apps/desktop/src/renderer/routes/_authenticated/_dashboard/workspace/$workspaceId/hooks/usePaneRegistry/components/ChatSession/components/Transcript/components/ApprovalRow/components/QuestionForm/components/QuestionPage/QuestionPage.tsx @@ -6,6 +6,7 @@ import { type QuestionPage as Page, } from "@superset/chat/core"; import type { FormField } from "@superset/chat/protocol"; +import { isImeComposing } from "@superset/ui/lib/keyboard"; import { cn } from "@superset/ui/utils"; import { Check, PencilLine } from "lucide-react"; @@ -125,7 +126,7 @@ export function QuestionPage({ onChange={(event) => onType(textField.id, event.target.value)} onKeyDown={(event) => { event.stopPropagation(); - if (event.key === "Enter") onEnter(); + if (event.key === "Enter" && !isImeComposing(event)) onEnter(); }} placeholder={ field.input === "integer"