Files
NetMesh/components/QuickSwitcher.pluginContributions.test.tsx
zhaolei 3c72efcb7f
Some checks failed
build-packages / resolve bundled mosh-client (push) Has been cancelled
build-packages / resolve bundled et-client (push) Has been cancelled
build-packages / build-macos (push) Has been cancelled
build-packages / build-windows (push) Has been cancelled
build-packages / build-linux-x64 (push) Has been cancelled
build-packages / build-linux-arm64 (push) Has been cancelled
build-packages / release (push) Has been cancelled
build-packages / update Nix release metadata (push) Has been cancelled
build-packages / bump homebrew tap (push) Has been cancelled
test / lint-and-test (push) Has been cancelled
AI automation / Route event (push) Has been cancelled
AI automation / Hand reopened issue to maintainers (push) Has been cancelled
AI automation / Clean source issue state (push) Has been cancelled
AI automation / Reconcile handoffs (push) Has been cancelled
AI automation / Classify issue (push) Has been cancelled
AI automation / Claude Code smoke (push) Has been cancelled
AI automation / Review issue follow-up (push) Has been cancelled
AI automation / Publish issue follow-up (push) Has been cancelled
AI automation / Implement with Claude Code (push) Has been cancelled
AI automation / Publish implement PR (push) Has been cancelled
AI automation / Continue queued issue comments (push) Has been cancelled
AI automation / Codex review loop (push) Has been cancelled
AI automation / Publish Codex fix (push) Has been cancelled
AI automation / Clear Codex dispatch marker (push) Has been cancelled
AI automation / Own PR re-request Codex (push) Has been cancelled
AI automation / External PR re-request Codex (push) Has been cancelled
AI automation / Poll Codex reaction / retry (push) Has been cancelled
build-et-binaries / build-linux-x64 (push) Has been cancelled
build-et-binaries / build-linux-arm64 (push) Has been cancelled
build-et-binaries / build-macos-universal (push) Has been cancelled
build-et-binaries / build-windows-x64 (push) Has been cancelled
build-et-binaries / release (push) Has been cancelled
[Init] Initial commit - NetMesh terminal manager
2026-09-13 18:24:01 +08:00

154 lines
5.4 KiB
TypeScript

import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import test from 'node:test';
import {
buildPaneMagnificationPaletteAction,
buildPluginPaletteItems,
getQuickSwitcherRowStateClass,
shouldUseQuickSwitcherPointerNavigation,
} from './QuickSwitcher';
test('command palette follows the active pane magnification state', () => {
const t = (key: string) => key;
assert.equal(buildPaneMagnificationPaletteAction('unavailable', t), null);
assert.deepEqual(buildPaneMagnificationPaletteAction('focusable', t), {
type: 'action',
id: 'magnify-current-pane',
title: 'terminal.paneMagnification.magnify',
});
assert.deepEqual(buildPaneMagnificationPaletteAction('focused', t), {
type: 'action',
id: 'restore-magnified-pane',
title: 'terminal.paneMagnification.restore',
});
});
test('keeps the new workspace action outside the scrollable results', () => {
const source = readFileSync(new URL('./QuickSwitcher.tsx', import.meta.url), 'utf8');
const actionIndex = source.indexOf('{/* Jump To hint + New Workspace action */}');
const resultsScrollIndex = source.indexOf('data-host-picker-virtual="quick-switcher"');
assert.notEqual(actionIndex, -1);
assert.notEqual(resultsScrollIndex, -1);
assert.ok(actionIndex < resultsScrollIndex);
assert.match(source, /VariableSizeVirtualList/);
});
test('host rows expose optional edit-host context menu', () => {
const source = readFileSync(new URL('./QuickSwitcher.tsx', import.meta.url), 'utf8');
assert.match(source, /onEditHost\?: \(host: Host\) => void/);
assert.match(source, /terminal\.layer\.hostTree\.editHost/);
assert.match(source, /ContextMenuTrigger asChild/);
assert.match(source, /#netcatty-context-menu-root/);
});
test('pointer hover never rewrites the keyboard selection', () => {
const quickSwitcherSource = readFileSync(new URL('./QuickSwitcher.tsx', import.meta.url), 'utf8');
const workspacePickerSource = readFileSync(new URL('./workspace/AddToWorkspaceDialog.tsx', import.meta.url), 'utf8');
assert.doesNotMatch(quickSwitcherSource, /onMouseEnter/);
assert.doesNotMatch(quickSwitcherSource, /selectWithPointer/);
assert.doesNotMatch(workspacePickerSource, /onMouseEnter/);
assert.doesNotMatch(workspacePickerSource, /onMouseMove/);
});
test('keyboard navigation shows only the current keyboard selection', () => {
assert.equal(getQuickSwitcherRowStateClass(true, true), 'bg-primary/15');
assert.equal(getQuickSwitcherRowStateClass(false, true), '');
assert.equal(getQuickSwitcherRowStateClass(false, false), 'hover:bg-muted/50');
});
test('layout movement under a stationary pointer cannot take over keyboard navigation', () => {
assert.equal(shouldUseQuickSwitcherPointerNavigation(0, 0), false);
assert.equal(shouldUseQuickSwitcherPointerNavigation(1, 0), true);
assert.equal(shouldUseQuickSwitcherPointerNavigation(0, -1), true);
});
function pluginSnapshot(menuEnabled: boolean): NetcattyPluginContributionSnapshot['plugins'] {
return [{
id: 'com.example.palette',
version: '1.0.0',
displayName: 'Palette plugin',
description: '',
commands: [{
id: 'com.example.palette.run',
title: 'Run command',
enabled: true,
}],
keybindings: [],
menus: [{
id: 'com.example.palette:menu:0',
command: 'com.example.palette.run',
alt: 'com.example.palette.runAlternate',
location: 'commandPalette',
title: 'Run from palette',
visible: true,
enabled: menuEnabled,
shortcut: 'ctrl+shift+r',
}],
settings: [],
views: [],
}];
}
test('plugin palette items preserve menu-specific enablement', () => {
assert.deepEqual(buildPluginPaletteItems(pluginSnapshot(false), ''), [{
type: 'plugin-command',
id: 'com.example.palette:menu:0',
commandId: 'com.example.palette.run',
title: 'Run from palette',
pluginTitle: 'Palette plugin',
pluginId: 'com.example.palette',
enabled: false,
altCommand: 'com.example.palette.runAlternate',
shortcut: 'ctrl+shift+r',
}]);
assert.equal(buildPluginPaletteItems(pluginSnapshot(true), '')[0]?.enabled, true);
});
test('plugin palette items honor declared menu ordering', () => {
const plugins = pluginSnapshot(true);
const plugin = plugins[0];
const ordered = [{
...plugin,
commands: [
...plugin.commands,
{ id: 'com.example.palette.first', title: 'First command', enabled: true },
],
menus: [
{ ...plugin.menus[0], group: 'navigation', order: 20 },
{
...plugin.menus[0],
id: 'com.example.palette:menu:1',
command: 'com.example.palette.first',
title: 'First from palette',
group: 'navigation',
order: 10,
},
],
}];
assert.deepEqual(buildPluginPaletteItems(ordered, '').map((item) => item.id), [
'com.example.palette:menu:1',
'com.example.palette:menu:0',
]);
});
test('plugin palette items keep repeated placements independently addressable', () => {
const plugins = pluginSnapshot(true);
plugins[0].menus.push({
...plugins[0].menus[0],
id: 'com.example.palette:menu:1',
title: 'Run another way',
});
const items = buildPluginPaletteItems(plugins, '');
assert.deepEqual(items.map(({ id, commandId }) => ({ id, commandId })), [{
id: 'com.example.palette:menu:0',
commandId: 'com.example.palette.run',
}, {
id: 'com.example.palette:menu:1',
commandId: 'com.example.palette.run',
}]);
});