diff --git a/src/frontend/platform/src/pages/BuildPage/flow/FlowNode/component/VarInput.test.tsx b/src/frontend/platform/src/pages/BuildPage/flow/FlowNode/component/VarInput.test.tsx new file mode 100644 index 0000000000..e1a8137d1b --- /dev/null +++ b/src/frontend/platform/src/pages/BuildPage/flow/FlowNode/component/VarInput.test.tsx @@ -0,0 +1,57 @@ +import { fireEvent, render } from "@/test/test-utils"; +import type { ReactNode } from "react"; +import { describe, expect, it, vi } from "vitest"; + +import VarInput from "./VarInput"; + +vi.mock("../../flowStore", () => ({ + default: () => ({ flow: { nodes: [] } }), +})); + +vi.mock("../flowNodeStore", () => ({ + useUpdateVariableState: () => [null], +})); + +vi.mock("./SelectVar", async () => { + const { forwardRef } = await import("react"); + return { + default: forwardRef(({ children }, _ref) => children), + }; +}); + +vi.mock("@/components/bs-ui/tooltip/tip", () => ({ + default: ({ children }) => children, +})); + +vi.mock("@/components/bs-icons/rbDrag", () => ({ + RbDragIcon: () => null, +})); + +describe("VarInput", () => { + it("normalizes non-breaking spaces when serializing variable input", () => { + const onChange = vi.fn(); + const { container } = render( + , + ); + const input = container.querySelector('[contenteditable="true"]'); + expect(input).not.toBeNull(); + + input!.innerHTML = + 'select * from risk_info where name = code/result limit 2000'; + fireEvent.input(input!); + + expect(onChange).toHaveBeenLastCalledWith( + "select * from risk_info where name = {{#code.result#}} limit 2000", + ); + }); +}); diff --git a/src/frontend/platform/src/pages/BuildPage/flow/FlowNode/component/VarInput.tsx b/src/frontend/platform/src/pages/BuildPage/flow/FlowNode/component/VarInput.tsx index d7a6f41d91..877ab94e6d 100644 --- a/src/frontend/platform/src/pages/BuildPage/flow/FlowNode/component/VarInput.tsx +++ b/src/frontend/platform/src/pages/BuildPage/flow/FlowNode/component/VarInput.tsx @@ -43,7 +43,7 @@ function parseToValue(input, paramItem) { if (child.nodeName === 'BR') { result += '\n'; // 换行符 } else if (child.nodeType === Node.TEXT_NODE) { - result += child.textContent; // 文本内容 + result += child.textContent.replace(/\u00a0/g, ' '); // 文本内容 } else if (child.nodeType === Node.ELEMENT_NODE) { result += traverseNodes(child); // 递归解析子元素 }