/** * ConnectionPool Store Tests - 连接池状态管理测试 * * 注意: 这些测试验证 store 接口存在且可用 * 实际的连接功能需要集成测试环境 */ import { describe, it, expect } from 'vitest' import { useConnectionPool, useConnectionStore, getConnectionStore } from '../../src/stores/connection' 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) }) }) })