Files
opsxshell/test/stores/connectionPool.test.ts
T
Logan.Li 484d850abd feat: v0.3.0 版本 - SSH终端、SFTP、端口转发功能实现
核心功能:
- SSH终端: 密码/密钥认证、XTerm.js终端、多主题配色、IP高亮
- SFTP管理: 双栏文件管理、上传下载、传输队列
- 端口转发: 本地/远程转发、SOCKS5动态代理、规则管理

架构改进:
- 拆分大型组件 (SFTPView/TabBar/Sidebar)
- 添加统一日志和错误处理
- 修复React严格模式下的终端黑屏问题

UI更新:
- 新增端口转发视图
- 更新UI预览文档
- 左侧栏右键菜单支持SFTP快捷打开
2026-04-06 01:20:47 +08:00

71 lines
2.3 KiB
TypeScript

/**
* ConnectionPool Store Tests - 连接池状态管理测试
*
* 注意: 这些测试验证 store 接口存在且可用
* 实际的连接功能需要集成测试环境
*/
import { describe, it, expect } from 'vitest'
import { useConnectionPool, useConnectionStore, getConnectionStore } from '../../src/stores/connectionPool'
describe('ConnectionPool Store', () => {
describe('store 初始化', () => {
it('useConnectionStore hook 应该存在', () => {
expect(typeof useConnectionStore).toBe('function')
})
it('useConnectionPool hook 应该存在 (向后兼容别名)', () => {
expect(typeof useConnectionPool).toBe('function')
})
it('getConnectionStore 函数应该存在', () => {
expect(typeof getConnectionStore).toBe('function')
})
it('getConnectionStore 应该返回正确的接口', () => {
const store = getConnectionStore()
expect(store).toHaveProperty('createConnection')
expect(store).toHaveProperty('getConnection')
expect(store).toHaveProperty('releaseConnection')
expect(store).toHaveProperty('disconnectConnection')
expect(store).toHaveProperty('getStats')
})
})
describe('store 方法签名', () => {
it('createConnection 应该是异步函数', () => {
const store = getConnectionStore()
expect(store.createConnection).toBeInstanceOf(Function)
// 验证是 async function (通过返回 Promise)
const result = store.createConnection('test-tab', {
host: 'localhost',
port: 22,
username: 'test',
})
expect(result).toBeInstanceOf(Promise)
})
it('getStats 应该返回连接统计', () => {
const store = getConnectionStore()
const stats = store.getStats()
expect(stats).toHaveProperty('total')
expect(stats).toHaveProperty('connected')
expect(stats).toHaveProperty('background')
expect(stats).toHaveProperty('suspended')
})
})
describe('配置', () => {
it('应该有默认最大连接数配置', () => {
const store = getConnectionStore()
expect(store.config).toBeDefined()
expect(store.config.maxConnections).toBeGreaterThan(0)
})
it('应该有默认后台连接配置', () => {
const store = getConnectionStore()
expect(store.config.maxBackgroundConnections).toBeGreaterThan(0)
})
})
})