feat: command snippets + UI test coverage for new features
- core/snippets.py: SnippetManager with 20 prebuilt sysadmin commands, CRUD + reorder, persisted to ~/.sshclient/snippets.json - ui/snippet_dialog.py: SnippetDialog (add/edit) + SnippetManagerDialog (table view with add/edit/delete/move up/down) - ui/terminal_panel.py: snippet combo box in toolbar, send_command() method to inject commands into interactive shell, snippet manager button - README.md: updated feature table, usage section, project structure - test_ui.py: added [2/4] checks for sparkline/snippets/theme, added [4/4] theme toggle verification
This commit is contained in:
+25
-4
@@ -33,13 +33,21 @@ def main():
|
||||
assert w.tabs.count() == 4, f"应有 4 个 Tab,实际 {w.tabs.count()}"
|
||||
print(f" ✓ 主窗口创建,Tab 数量 = {w.tabs.count()}")
|
||||
|
||||
print("[2/3] 验证子组件")
|
||||
print("[2/4] 验证子组件")
|
||||
assert isinstance(w.file_browser, FileBrowser)
|
||||
assert isinstance(w.monitor, MonitorPanel)
|
||||
assert isinstance(w.ai_panel, AIChatPanel)
|
||||
# 验证新增功能
|
||||
assert hasattr(w.monitor, "_spark_cpu"), "MonitorPanel 应有 CPU 迷你图"
|
||||
assert hasattr(w.monitor, "_spark_mem"), "MonitorPanel 应有内存迷你图"
|
||||
assert hasattr(w.terminal_panel, "snippet_combo"), "TerminalPanel 应有片段下拉框"
|
||||
assert hasattr(w, "act_dark"), "MainWindow 应有暗色主题菜单项"
|
||||
menus = [a.text() for a in w.menuBar().actions()]
|
||||
assert "视图(&V)" in menus, f"应有视图菜单: {menus}"
|
||||
print(f" ✓ FileBrowser / MonitorPanel / AIChatPanel 全部就位")
|
||||
print(f" ✓ 暗色主题切换 / CPU·内存迷你图 / 命令片段下拉框")
|
||||
|
||||
print("[3/3] 验证对话框")
|
||||
print("[3/4] 验证对话框")
|
||||
# 主机对话框
|
||||
hd = HostDialog(current={"name": "test", "host": "1.2.3.4", "port": 22,
|
||||
"username": "u", "password": "p", "key_path": ""})
|
||||
@@ -56,10 +64,23 @@ def main():
|
||||
cd.close()
|
||||
print(f" ✓ AIConfigDialog + {len(PRESETS)} 个预设")
|
||||
|
||||
# 不真正 show,只确保不崩
|
||||
print("[4/4] 验证主题切换")
|
||||
from ui.theme import get_theme, set_theme, get_qss
|
||||
# 切换到暗色
|
||||
w.act_dark.setChecked(True)
|
||||
w._toggle_theme()
|
||||
assert get_theme() == "dark"
|
||||
qss = app.styleSheet()
|
||||
assert len(qss) > 100, "QSS 应该有内容"
|
||||
# 切回亮色
|
||||
w.act_dark.setChecked(False)
|
||||
w._toggle_theme()
|
||||
assert get_theme() == "light"
|
||||
print(f" ✓ 暗/亮主题切换正常 (dark QSS={len(get_qss('dark'))} chars)")
|
||||
|
||||
# 清理
|
||||
w.close()
|
||||
print("\n所有 UI 组件加载正常 ✓")
|
||||
# 不进入事件循环,强制退出
|
||||
QTimer.singleShot(0, app.quit)
|
||||
app.exec_()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user