Files
Netcatty/components/terminal/useTerminalContextActions.test.ts
T
bincxz 19e89934c1 fix(terminal): keep preview copy and paste-selection consistent
#3026

Select All built an element-boundary range, so wrap joining never ran
and copied extra newlines. Context-menu paste selection also left the
overlay up, unlike the keyboard path. Select the text node, accept
element-boundary offsets, and dismiss the preview before pasting.
2026-08-17 20:38:58 +08:00

60 lines
2.0 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import { broadcastTerminalPasteData } from "./hooks/useTerminalContextActions";
test("terminal context paste reports whether it broadcast to peers", () => {
const broadcasted: Array<{ data: string; sessionId: string }> = [];
const didBroadcast = broadcastTerminalPasteData("line one", {
sourceSessionId: "workspace-session-1",
sessionRef: { current: "backend-session-1" },
isBroadcastEnabledRef: { current: true },
onBroadcastInputRef: {
current: (data, sourceSessionId) => {
broadcasted.push({ data, sessionId: sourceSessionId });
},
},
});
assert.equal(didBroadcast, true);
assert.deepEqual(broadcasted, [{ data: "line one", sessionId: "workspace-session-1" }]);
});
test("terminal context paste reports false when broadcast is disabled", () => {
const didBroadcast = broadcastTerminalPasteData("line one", {
sourceSessionId: "workspace-session-1",
sessionRef: { current: "session-1" },
isBroadcastEnabledRef: { current: false },
onBroadcastInputRef: {
current: () => {
throw new Error("broadcast should not run");
},
},
});
assert.equal(didBroadcast, false);
});
test("paste selection dismisses the history preview before sending text", async () => {
const { readFileSync } = await import("node:fs");
const source = readFileSync(new URL("./hooks/useTerminalContextActions.ts", import.meta.url), "utf8");
assert.match(source, /requestHistoryPreviewHide\(term\.element\?\.parentElement\)/);
});
test("terminal context paste never broadcasts password-prompt input", () => {
const didBroadcast = broadcastTerminalPasteData("secret", {
sourceSessionId: "workspace-session-1",
sessionRef: { current: "session-1" },
isBroadcastEnabledRef: { current: true },
passwordPromptActiveRef: { current: true },
onBroadcastInputRef: {
current: () => {
throw new Error("sensitive paste must not broadcast");
},
},
});
assert.equal(didBroadcast, false);
});