Files
Netcatty/domain/settingsSearch.test.ts
T
57089a3abf feat: temporary network device mode and tab-bar quick connect (#3793)
* feat(ssh): opt temporary connections into network device mode

Saved hosts and group-backed clones keep their own device type. SSH
connections with no saved host, including external launches and quick
connect, can start in network device mode when the new Terminal setting
is on. The setting stays off unless the user turns it on.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* feat(terminal): quick connect typed addresses from the tab switcher

The tab-bar quick switcher now offers the typed address when it already
parses as a connection target. Choosing that row opens the existing
quick connect wizard, including from a terminal tab where the vault
surface is hidden.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(ssh): keep temporary Mosh and ET off network device mode

Those transports are stored as SSH plus a flag. Stamping network device
mode onto them made raw-host checks skip the copy-session working
directory probe. Plain temporary SSH still opts in.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(ssh): read temporary connection settings at connect time

VaultView keeps a stale onConnect callback because its memo ignores that
prop. Read both temporary-connection toggles from a ref when connecting
so turning them on or off applies in the same session.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(terminal): stop word queries from opening quick connect

Show the switcher quick-connect row only for address-like input, and
place it after matching hosts so Enter still connects to a saved host.
Translate the Hosts, Tabs, and New Workspace labels.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

* fix(terminal): keep matching tabs ahead of quick connect

An address that matches an open session or workspace was still the
default Enter target when no saved host matched. Put that row after
those tabs so Enter switches to the existing one.

Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: 陈大猫 <binaricat@users.noreply.github.com>
2026-10-20 18:29:41 +08:00

155 lines
7.2 KiB
TypeScript

import assert from "node:assert/strict";
import test from "node:test";
import en from "../application/i18n/locales/en.ts";
import zhCN from "../application/i18n/locales/zh-CN.ts";
import zhTW from "../application/i18n/locales/zh-TW.ts";
import { filterSettingsSearchCatalog } from "./settingsSearch.ts";
import { SETTINGS_SEARCH_CATALOG } from "./settingsSearchCatalog.ts";
const EN: Record<string, string> = {
"settings.tab.application": "Application",
"settings.tab.appearance": "Appearance",
"settings.tab.terminal": "Terminal",
"settings.tab.shortcuts": "Shortcuts",
"settings.tab.sftpFileAssociations": "SFTP",
"settings.tab.ai": "AI",
"settings.tab.syncCloud": "Sync & Cloud",
"settings.tab.system": "System",
"settings.tab.plugins": "Plugins",
"settings.appearance.theme": "Theme",
"settings.appearance.uiTheme": "UI theme",
"settings.terminal.behavior.copyOnSelect": "Copy on select",
"settings.terminal.behavior.copyOnSelect.desc": "Copy selected text automatically",
"settings.terminal.cursor.barWidth": "Bar cursor width",
"settings.terminal.cursor.barWidth.desc": "Width of bar cursors used by applications such as vi (1-4 px)",
"settings.terminal.section.cursor": "Cursor",
"settings.terminal.behavior.disconnectedNotice": "When a connection disconnects",
"settings.terminal.behavior.disconnectedNotice.desc": "Show a terminal notice or dialog",
"settings.terminal.section.behavior": "Behavior",
"settings.system.networkProxy.mode": "Proxy mode",
"settings.system.networkProxy.description": "HTTP(S) proxy for cloud sync and AI",
"settings.system.networkProxy.title": "Network Proxy",
"settings.appLock.title": "App Lock",
"settings.appLock.description": "Require a local lock password when Netcatty opens",
"ai.safety.permissionMode": "Permission mode",
"ai.safety.permissionMode.description": "Control tool approvals",
"ai.safety.title": "Safety",
"cloudSync.localBackups.title": "Local backups",
"cloudSync.localBackups.desc": "Keep offline snapshots",
};
const ZH: Record<string, string> = {
...EN,
"settings.appearance.theme": "主题",
"settings.terminal.behavior.copyOnSelect": "选中即复制",
"settings.terminal.cursor.barWidth": "竖线光标粗细",
"settings.terminal.cursor.barWidth.desc": "vi 等应用使用竖线光标时的宽度(1-4 像素)",
"settings.terminal.section.cursor": "光标",
"settings.terminal.behavior.disconnectedNotice": "连接断开时",
"settings.terminal.behavior.disconnectedNotice.desc": "在终端内显示简短提示,或使用完整弹窗",
"settings.system.networkProxy.mode": "代理模式",
"settings.system.networkProxy.title": "网络代理",
"settings.appLock.title": "应用锁定",
"settings.appLock.description": "在 Netcatty 打开、长时间无操作或手动锁定后,要求输入本地锁定密码。",
"ai.safety.permissionMode": "权限模式",
};
const tEn = (key: string) => EN[key] ?? key;
const tZh = (key: string) => ZH[key] ?? key;
test("settings search catalog has unique ids", () => {
const ids = SETTINGS_SEARCH_CATALOG.map((entry) => entry.id);
assert.equal(new Set(ids).size, ids.length);
});
test("filterSettingsSearchCatalog matches English labels", () => {
const hits = filterSettingsSearchCatalog("copy on select", tEn);
assert.ok(hits.some((hit) => hit.entry.id === "terminal-copy-on-select"));
});
test("settings search finds the disconnected notice preference", () => {
const byEnglish = filterSettingsSearchCatalog("connection disconnects", tEn);
assert.ok(byEnglish.some((hit) => hit.entry.id === "terminal-disconnected-notice"));
const byChinese = filterSettingsSearchCatalog("断开连接", tZh);
assert.ok(byChinese.some((hit) => hit.entry.id === "terminal-disconnected-notice"));
const byPopupAlias = filterSettingsSearchCatalog("弹窗提醒", tZh);
assert.ok(byPopupAlias.some((hit) => hit.entry.id === "terminal-disconnected-notice"));
});
test("settings search finds bar cursor width in English and Chinese", () => {
const byEnglish = filterSettingsSearchCatalog("bar cursor width", tEn);
assert.ok(byEnglish.some((hit) => hit.entry.id === "terminal-cursor-bar-width"));
const byChinese = filterSettingsSearchCatalog("竖线光标粗细", tZh);
assert.ok(byChinese.some((hit) => hit.entry.id === "terminal-cursor-bar-width"));
});
test("filterSettingsSearchCatalog matches Chinese labels and pinyin", () => {
const byLabel = filterSettingsSearchCatalog("主题", tZh);
assert.ok(byLabel.some((hit) => hit.entry.id === "appearance-theme"));
const byPinyin = filterSettingsSearchCatalog("zhuti", tZh);
assert.ok(byPinyin.some((hit) => hit.entry.id === "appearance-theme"));
});
test("filterSettingsSearchCatalog matches keywords and tab labels", () => {
const proxyHits = filterSettingsSearchCatalog("proxy", tEn);
assert.ok(proxyHits.some((hit) => hit.entry.id === "system-network-proxy-mode"));
const syncHits = filterSettingsSearchCatalog("backup", tEn);
assert.ok(syncHits.some((hit) => hit.entry.id === "sync-local-backups"));
});
test("filterSettingsSearchCatalog matches App Lock by title and aliases", () => {
const byEnglish = filterSettingsSearchCatalog("app lock", tEn);
assert.ok(byEnglish.some((hit) => hit.entry.id === "system-app-lock"));
const byChineseTitle = filterSettingsSearchCatalog("应用锁定", tZh);
assert.ok(byChineseTitle.some((hit) => hit.entry.id === "system-app-lock"));
// Users commonly search the shorter "应用锁" alias rather than "应用锁定".
const byChineseAlias = filterSettingsSearchCatalog("应用锁", tZh);
assert.ok(byChineseAlias.some((hit) => hit.entry.id === "system-app-lock"));
const byTimeout = filterSettingsSearchCatalog("无操作", tZh);
assert.ok(byTimeout.some((hit) => hit.entry.id === "system-app-lock"));
});
test("settings search finds App Lock from the zh-CN locale", () => {
const t = (key: string) => zhCN[key] ?? key;
const hits = filterSettingsSearchCatalog("应用锁", t);
assert.ok(hits.some((hit) => hit.entry.id === "system-app-lock"));
});
test("settings search finds temporary network device mode", () => {
const tEnReal = (key: string) => en[key] ?? key;
const tZhTW = (key: string) => zhTW[key] ?? key;
const english = filterSettingsSearchCatalog("network device", tEnReal);
assert.ok(english.some((hit) => hit.entry.id === "terminal-temporary-network-device-mode"));
const traditional = filterSettingsSearchCatalog("網路裝置", tZhTW);
assert.ok(traditional.some((hit) => hit.entry.id === "terminal-temporary-network-device-mode"));
});
test("filterSettingsSearchCatalog can exclude plugins tab", () => {
const hits = filterSettingsSearchCatalog("plugin", tEn, { includePlugins: false });
assert.equal(hits.some((hit) => hit.entry.tab === "plugins"), false);
});
test("AI safety entries retain aiSubTab for navigation", () => {
const hits = filterSettingsSearchCatalog("permission", tEn);
const safety = hits.find((hit) => hit.entry.id === "ai-safety-permission-mode");
assert.ok(safety);
assert.equal(safety?.entry.aiSubTab, "safety");
});
test("Sync status entries retain syncSubTab for navigation", () => {
const hits = filterSettingsSearchCatalog("backup", tEn);
const backups = hits.find((hit) => hit.entry.id === "sync-local-backups");
assert.ok(backups);
assert.equal(backups?.entry.syncSubTab, "status");
});