Files
Netcatty/components/QuickAddSnippetDialog.test.tsx
T
bincxz 074724eb68 feat(scripts): improve terminal scripts side panel UX
Address #2502: bind shortkeys when quick-adding snippets, add package
creation via a split + menu, convert quick-add to a right-side drawer,
and let code snippets run on all workspace tabs from the context menu.
2026-07-27 13:37:50 +08:00

34 lines
1.1 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { getQuickAddSnippetInitialCommand } from "./QuickAddSnippetDialog.tsx";
const source = readFileSync(new URL("./QuickAddSnippetDialog.tsx", import.meta.url), "utf8");
test("quick add snippet event can prefill command", () => {
const event = {
detail: { command: "ls -la\npwd" },
} as CustomEvent<{ command?: string }>;
assert.equal(getQuickAddSnippetInitialCommand(event), "ls -la\npwd");
});
test("quick add snippet event defaults to an empty command", () => {
assert.equal(getQuickAddSnippetInitialCommand({} as Event), "");
assert.equal(
getQuickAddSnippetInitialCommand({
detail: { command: 123 },
} as unknown as Event),
"",
);
});
test("quick add snippet form binds shortkeys and uses a side panel drawer", () => {
assert.match(source, /AsidePanel/);
assert.match(source, /snippets\.field\.shortkey/);
assert.match(source, /keyEventToString/);
assert.match(source, /shortkey: shortkey \|\| undefined/);
assert.match(source, /if \(e\.defaultPrevented\) return/);
});