Skip to content
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -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<ApprovalRequest["form"]> = {
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(
<QuestionForm form={form} item={item} onRespond={onRespond} />,
);
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: "각" },
});
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Trans, useLingui } from "@lingui/react/macro";
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";
import {
Expand Down Expand Up @@ -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"
Expand Down
Loading