Files
NetMesh/components/SftpView.memo.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

166 lines
4.7 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
test("main SftpView keeps browse sessions across top-tab switches", () => {
const source = readFileSync(new URL("./SftpView.tsx", import.meta.url), "utf8");
// Mount stays alive after first visit; parking on isActive caused every
// remote tab to reconnect when leaving SFTP for Terminal and coming back.
assert.match(source, /interactive:\s*true/);
assert.doesNotMatch(source, /interactive:\s*isActive/);
});
test("Open SFTP always restores dual-pane layout through the planner", () => {
const source = readFileSync(new URL("./SftpView.tsx", import.meta.url), "utf8");
assert.match(source, /setMagnifiedSide\(null\);\s*applyDualPaneSftpOpen/);
assert.match(source, /applyDualPaneSftpOpen/);
assert.doesNotMatch(source, /firstVisitBothEmpty/);
});
test("SFTP magnification overlays one side while preserving the original two-pane geometry", async () => {
const { resolveTwoPaneMagnificationStyle } = await import("../domain/paneMagnification.ts");
assert.deepEqual(resolveTwoPaneMagnificationStyle('left', true, false), {
left: '0%', top: '0%', width: '50%', height: '100%', zIndex: 10,
});
assert.deepEqual(resolveTwoPaneMagnificationStyle('right', true, false), {
left: '50%', top: '0%', width: '50%', height: '100%', zIndex: 10,
});
assert.deepEqual(resolveTwoPaneMagnificationStyle('right', true, true), {
left: '12px', top: '12px', width: 'calc(100% - 24px)', height: 'calc(100% - 24px)', zIndex: 50,
});
});
test("SFTP keyboard focus tracks the active side and blocks the covered sibling", () => {
const source = readFileSync(new URL("./SftpView.tsx", import.meta.url), "utf8");
assert.match(source, /inert=\{magnifiedSide === 'right' \? true : undefined\}[\s\S]*onFocusCapture=\{\(\) => handlePaneFocus\("left"\)\}/);
assert.match(source, /inert=\{magnifiedSide === 'left' \? true : undefined\}[\s\S]*onFocusCapture=\{\(\) => handlePaneFocus\("right"\)\}/);
});
test("SftpView re-renders when host-key verification setting changes", async () => {
Object.defineProperty(globalThis, "localStorage", {
configurable: true,
value: {
getItem: () => null,
setItem: () => {},
removeItem: () => {},
},
});
const { sftpViewAreEqual } = await import("./SftpView.tsx");
const baseProps = {
hosts: [],
keys: [],
identities: [],
knownHosts: [],
groupConfigs: [],
proxyProfiles: [],
updateHosts: () => {},
onAddKnownHost: () => {},
sftpDefaultViewMode: "list",
sftpDoubleClickBehavior: "open",
sftpAutoSync: false,
sftpShowHiddenFiles: false,
sftpUseCompressedUpload: false,
hotkeyScheme: {},
keyBindings: [],
editorWordWrap: false,
setEditorWordWrap: () => {},
terminalSettings: {
verifyHostKeys: true,
keepaliveInterval: 30,
keepaliveCountMax: 10,
},
};
assert.equal(
sftpViewAreEqual(
baseProps as never,
{
...baseProps,
terminalSettings: {
...baseProps.terminalSettings,
verifyHostKeys: false,
},
} as never,
),
false,
);
});
test("SftpView ignores session title-only updates for memoization", async () => {
Object.defineProperty(globalThis, "localStorage", {
configurable: true,
value: {
getItem: () => null,
setItem: () => {},
removeItem: () => {},
},
});
const { sftpViewAreEqual } = await import("./SftpView.tsx");
const baseProps = {
hosts: [],
sessions: [{
id: "s1",
hostId: "h1",
hostLabel: "Host",
username: "alice",
hostname: "h1.example.test",
protocol: "ssh",
status: "connected",
dynamicTitle: "old",
}],
keys: [],
identities: [],
knownHosts: [],
groupConfigs: [],
proxyProfiles: [],
updateHosts: () => {},
onAddKnownHost: () => {},
sftpDefaultViewMode: "list",
sftpDoubleClickBehavior: "open",
sftpAutoSync: false,
sftpShowHiddenFiles: false,
sftpUseCompressedUpload: false,
hotkeyScheme: {},
keyBindings: [],
editorWordWrap: false,
setEditorWordWrap: () => {},
terminalSettings: {
verifyHostKeys: true,
keepaliveInterval: 30,
keepaliveCountMax: 10,
},
};
assert.equal(
sftpViewAreEqual(
baseProps as never,
{
...baseProps,
sessions: [{
...baseProps.sessions[0],
dynamicTitle: "new title from OSC",
}],
} as never,
),
true,
);
assert.equal(
sftpViewAreEqual(
baseProps as never,
{
...baseProps,
sessions: [{
...baseProps.sessions[0],
status: "connecting",
}],
} as never,
),
false,
);
});