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,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<unknown, { children: ReactNode }>(({ 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(
<VarInput
nodeId="mcp-node"
itemKey="query"
paramItem={{
label: "SQL",
required: false,
varZh: { "code.result": "code/result" },
}}
value=""
onChange={onChange}
/>,
);
const input = container.querySelector('[contenteditable="true"]');
expect(input).not.toBeNull();

input!.innerHTML =
'select * from risk_info where name = <span class="textarea-badge" contenteditable="false">code/result</span>&nbsp;limit 2000';
fireEvent.input(input!);

expect(onChange).toHaveBeenLastCalledWith(
"select * from risk_info where name = {{#code.result#}} limit 2000",
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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); // 递归解析子元素
}
Expand Down