mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-12 17:30:45 +00:00
Skip terminal focus steal during multi-tab snippet fan-out and restore the original pane afterward. Trap Tab focus inside the quick-add drawer and restore the opener element on close.
42 lines
1.5 KiB
TypeScript
42 lines
1.5 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/);
|
|
// Modal contract for hasOpenAppDialog / Cmd+W interception
|
|
assert.match(source, /role="dialog"/);
|
|
assert.match(source, /data-state="open"/);
|
|
assert.match(source, /data-dialog-close="true"/);
|
|
// Focus trap + restore opener focus
|
|
assert.match(source, /previouslyFocusedRef/);
|
|
assert.match(source, /listFocusable/);
|
|
assert.match(source, /focusin/);
|
|
});
|