63 lines
2.8 KiB
TypeScript
63 lines
2.8 KiB
TypeScript
|
|
import assert from 'node:assert/strict';
|
||
|
|
import { readFileSync } from 'node:fs';
|
||
|
|
import test from 'node:test';
|
||
|
|
|
||
|
|
const snippetEditorSource = readFileSync(
|
||
|
|
new URL('./snippets/SnippetScriptEditor.tsx', import.meta.url),
|
||
|
|
'utf8',
|
||
|
|
);
|
||
|
|
const codeEditorSource = readFileSync(
|
||
|
|
new URL('./scripts/ScriptCodeEditor.tsx', import.meta.url),
|
||
|
|
'utf8',
|
||
|
|
);
|
||
|
|
|
||
|
|
test('snippet editing uses the Monaco editor in both inline and expanded layouts', () => {
|
||
|
|
assert.doesNotMatch(snippetEditorSource, /CodeTextarea/);
|
||
|
|
assert.equal(snippetEditorSource.match(/<ScriptCodeEditor\s/g)?.length, 2);
|
||
|
|
assert.equal(snippetEditorSource.match(/language="shell"/g)?.length, 2);
|
||
|
|
assert.equal(snippetEditorSource.match(/placeholder=\{placeholder\}/g)?.length, 2);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('inline snippet editing preserves form focus behavior', () => {
|
||
|
|
assert.match(snippetEditorSource, /inlineEditorRef\.current\?\.focus\(\)/);
|
||
|
|
assert.match(snippetEditorSource, /\sref=\{inlineEditorRef\}/);
|
||
|
|
assert.match(snippetEditorSource, /\stabFocusMode(?:\s|\n)/);
|
||
|
|
assert.match(codeEditorSource, /tabFocusMode,/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('snippet editor forwards the surrounding form submit shortcut', () => {
|
||
|
|
assert.equal(snippetEditorSource.match(/onSubmitShortcut=\{onSubmitShortcut\}/g)?.length, 2);
|
||
|
|
assert.match(codeEditorSource, /if \(onSubmitShortcut\)/);
|
||
|
|
assert.match(codeEditorSource, /KeyMod\.CtrlCmd \| monacoInstance\.KeyCode\.Enter/);
|
||
|
|
assert.match(codeEditorSource, /onSubmitShortcutRef\.current\?\.\(\)/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('dialog submit handlers ignore shortcuts already handled by Monaco', () => {
|
||
|
|
const quickAddSource = readFileSync(new URL('./QuickAddSnippetDialog.tsx', import.meta.url), 'utf8');
|
||
|
|
const tmuxSource = readFileSync(
|
||
|
|
new URL('./systemManager/TmuxNewSessionModal.tsx', import.meta.url),
|
||
|
|
'utf8',
|
||
|
|
);
|
||
|
|
assert.match(quickAddSource, /if \(e\.defaultPrevented\) return/);
|
||
|
|
assert.match(tmuxSource, /if \(e\.defaultPrevented\) return/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('visual placeholder is hidden from assistive technology', () => {
|
||
|
|
assert.match(codeEditorSource, /<span\s+aria-hidden/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('script code editor restores Electron clipboard paste for Cmd/Ctrl+V and native right-click', () => {
|
||
|
|
assert.match(codeEditorSource, /useClipboardBackend/);
|
||
|
|
assert.match(codeEditorSource, /readClipboardTextWithFallbacks/);
|
||
|
|
assert.match(codeEditorSource, /buildMonacoPasteEdits/);
|
||
|
|
assert.match(codeEditorSource, /KeyMod\.CtrlCmd \| monacoInstance\.KeyCode\.KeyV/);
|
||
|
|
assert.match(codeEditorSource, /contextmenu:\s*false/);
|
||
|
|
assert.match(codeEditorSource, /editor\.action\.clipboardPasteAction/);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('script code editor pastes into Monaco find widget instead of script body', () => {
|
||
|
|
assert.match(codeEditorSource, /pasteForMonacoEditorCommand/);
|
||
|
|
assert.match(codeEditorSource, /activeElement:\s*document\.activeElement/);
|
||
|
|
assert.match(codeEditorSource, /pasteIntoEditor:\s*\(\)\s*=>\s*handlePasteRef\.current\(\)/);
|
||
|
|
});
|