Files
Netcatty/components/sftp/SftpHostPicker.test.ts
T
陈大猫andnetcatty-bot aaff0edc7f perf(vault): virtualize host pickers for large inventories (#2553)
* perf(vault): virtualize host pickers for large inventories

Virtualize Select Host, Quick Switcher, SFTP host picker, and workspace
dialogs so thousands of hosts only mount a viewport window. Shared scroll
and keyboard clamp helpers keep selection and filter-while-scrolled paths
stable under virtualization.

* fix: address Codex review on PR #2553

* fix(vault): plugin row heights and Select Host keyboard types

Give Quick Switcher plugin command/view rows a taller virtual slot so
two-line chrome does not overflow into the next absolute row. Narrow
Select Host navigable rows to group|host so Enter keyboard activation
typechecks cleanly.

* fix(vault): finish host-picker review feedback

Clip and truncate fixed-height Quick Switcher / workspace rows so long
labels never overlap the next virtual slot. Wire Select Host listbox
aria-activedescendant to stable option ids for keyboard AT feedback.

* fix: address Codex review on PR #2553

* fix: address Codex review on PR #2553

* fix: address Codex review on PR #2553

* fix: address Codex review on PR #2553

* fix(vault): clear remaining host-picker codex findings

Declare multi-select listboxes, drop empty SFTP Hosts headers when only
connected rows remain, size the SFTP list to content under a 360px cap,
and give Quick Switcher / workspace pickers a definite max scroll height
so large inventories remain reachable.

---------

Co-authored-by: netcatty-bot <308658023+netcatty-bot@users.noreply.github.com>
2026-07-28 11:48:01 +08:00

69 lines
2.8 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import { fileURLToPath } from "node:url";
const source = fs.readFileSync(
path.join(path.dirname(fileURLToPath(import.meta.url)), "SftpHostPicker.tsx"),
"utf8",
);
test("sftp host picker rows reuse quick switcher selection classes", () => {
assert.match(source, /getQuickSwitcherRowStateClass/);
assert.match(source, /shouldUseQuickSwitcherPointerNavigation/);
assert.match(source, /isKeyboardNavigating/);
assert.match(source, /onMouseMove=\{\(event\) => handlePointerHover\(event\.movementX, event\.movementY\)\}/);
assert.match(
source,
/const handlePointerHover = useCallback\(\(movementX: number, movementY: number\) => \{[\s\S]*if \(!isKeyboardNavigatingRef\.current\) return;[\s\S]*setIsKeyboardNavigating\(false\);[\s\S]*\}, \[\]\);/,
);
assert.doesNotMatch(
source,
/const handlePointerHover = useCallback\(\(itemIndex: number, movementX: number, movementY: number\) => \{[\s\S]*setSelectedIndex\(itemIndex\);/,
);
});
test("sftp host picker uses single-line quick switcher row layout", () => {
assert.match(
source,
/className=\{`flex items-center justify-between px-4 py-2\.5 cursor-pointer transition-colors \$\{getQuickSwitcherRowStateClass/,
);
assert.match(
source,
/className="h-6 w-6 rounded flex items-center justify-center text-muted-foreground"/,
);
assert.match(
source,
/<span className="text-sm font-medium truncate">\{t\('sftp\.picker\.local\.title'\)\}<\/span>/,
);
assert.match(
source,
/<span className="text-sm font-medium truncate">\{host\.label\}<\/span>/,
);
assert.match(
source,
/className="ml-3 shrink-0 text-\[11px\] text-muted-foreground truncate max-w-\[12rem\]"/,
);
assert.match(source, /formatHostMeta\(host\)/);
assert.doesNotMatch(source, /bg-primary\/10 border border-primary\/30/);
assert.doesNotMatch(source, /text-xs text-muted-foreground truncate/);
});
test("sftp host picker virtualizes the host list", () => {
assert.match(source, /VariableSizeVirtualList/);
assert.match(source, /data-host-picker-virtual="sftp"/);
assert.match(source, /itemIndexToVisualIndex/);
assert.doesNotMatch(source, /filteredHosts\.map\(\(host\) =>/);
// Connected-only results must not leave a dangling empty Hosts header.
assert.match(source, /if \(filteredHosts\.length > 0\) \{\s*pushHeader\('header:hosts'/);
assert.match(
source,
/else if \(filteredConnectedHosts\.length === 0\) \{\s*pushHeader\('header:hosts'/,
);
// Short lists shrink; long lists cap at 360px (not a forced blank 360px dialog).
assert.match(source, /Math\.min\(360, Math\.max\(total, 1\)\)/);
assert.match(source, /listViewportHeight/);
assert.doesNotMatch(source, /className="h-\[360px\]"/);
});