Files
Netcatty/components/VaultViewLayout.test.ts
T
3c67392455 fix(ui): keep New Host menu icons from shrinking and fix toast contrast when app/system themes differ (#3795)
* fix(vault): keep the New Host local shell icon at 14px

The dropdown was a fixed w-44 flex row. "Local Shell (CMD)" is wider than
the sibling labels, so the icon SVG flex-shrunk below size 14 (and longer
shell names collapsed it entirely). Pin every menu icon with shrink-0 and
let the menu grow with the label.

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

* fix(ui): keep toast text on the app theme surface

Palette fills used a prefers-color-scheme dark variant, so an app-dark session with a light OS left light text on a pale background.

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:14:11 +08:00

68 lines
3.8 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
const vaultViewLayoutSource = readFileSync(new URL("./vault/VaultViewLayout.tsx", import.meta.url), "utf8");
const pluginImporterCommitHookSource = readFileSync(new URL("../application/state/usePluginImporterCommit.ts", import.meta.url), "utf8");
test("vault stage aligns its content to the top tab bar", () => {
assert.match(vaultViewLayoutSource, /className="flex min-w-0 flex-1 py-0 pr-2 pb-2 pl-0"/);
assert.doesNotMatch(vaultViewLayoutSource, /className="flex min-w-0 flex-1 p-2 pl-0"/);
});
test("vault notes stay mounted while switching sections", () => {
assert.match(vaultViewLayoutSource, /data-section="vault-notes-retained"/);
assert.match(vaultViewLayoutSource, /currentSection !== "notes" && "hidden"/);
assert.doesNotMatch(vaultViewLayoutSource, /currentSection === "notes" && \(\s*<NotesManager/);
});
test("vault header collapsed actions cannot retain hidden focus", () => {
assert.match(vaultViewLayoutSource, /newHostActionsRef\.current\?\.contains\(activeElement\)/);
assert.match(vaultViewLayoutSource, /sessionActionsRef\.current\?\.contains\(activeElement\)/);
assert.match(vaultViewLayoutSource, /activeElement\.blur\(\)/);
// Both the SSH/new-host panel and the local-shell host panel collapse the
// header actions so hidden buttons cannot retain focus.
assert.match(vaultViewLayoutSource, /aria-hidden=\{isHostAsideOpen \? true : undefined\}/);
assert.match(vaultViewLayoutSource, /inert=\{isHostAsideOpen \? true : undefined\}/);
});
test("vault sidebar toggle keeps an accessible action label", () => {
assert.match(
vaultViewLayoutSource,
/aria-label=\{sidebarCollapsed \? t\("vault\.sidebar\.expand"\) : t\("vault\.sidebar\.collapse"\)\}/,
);
});
test("keychain deletion clears the remembered passphrase through the vault handler", () => {
assert.match(vaultViewLayoutSource, /const handleDeleteVaultKey = React\.useCallback/);
assert.match(vaultViewLayoutSource, /void deleteVaultKey\(\{/);
assert.match(vaultViewLayoutSource, /onDelete=\{handleDeleteVaultKey\}/);
});
test("plugin importer merge and commit workflow is owned by application state", () => {
assert.match(vaultViewLayoutSource, /usePluginImporterCommit\(\{/);
assert.doesNotMatch(vaultViewLayoutSource, /normalizePluginImporterRecords|mergePluginImporterDrafts|buildPluginImporterSafePreview/);
assert.match(pluginImporterCommitHookSource, /normalizePluginImporterRecords/);
assert.match(pluginImporterCommitHookSource, /mergePluginImporterDrafts/);
assert.match(pluginImporterCommitHookSource, /buildPluginImporterSafePreview/);
});
test("Vault import entry is disabled while an import is running", () => {
assert.match(vaultViewLayoutSource, /disabled=\{importProgress\?\.status === "running"\}/);
assert.match(vaultViewLayoutSource, /if \(importProgress\?\.status === "running"\) return;/);
});
test("new host menu keeps the local shell icon at the same size as its siblings", () => {
const menuStart = vaultViewLayoutSource.indexOf('<DropdownContent className="flex w-max min-w-44 flex-col" align="end" alignToParent>');
assert.ok(menuStart >= 0);
const menuEnd = vaultViewLayoutSource.indexOf("</DropdownContent>", menuStart);
const menu = vaultViewLayoutSource.slice(menuStart, menuEnd);
assert.match(menu, /className="flex w-max min-w-44 flex-col"/);
assert.doesNotMatch(menu, /className="w-44"/);
assert.match(menu, /<TerminalSquare size=\{14\} className="shrink-0" \/>/);
assert.match(menu, /<FolderTree size=\{14\} className="shrink-0" \/>/);
assert.match(menu, /<Upload size=\{14\} className="shrink-0" \/>/);
assert.match(menu, /<Download size=\{14\} className="shrink-0" \/>/);
assert.doesNotMatch(menu, /className="w-full justify-start gap-2"/);
});