Files
SuperCharged-Claude-Code-Up…/dexto/packages/webui/lib/stores/sessionStore.test.ts
admin b52318eeae feat: Add intelligent auto-router and enhanced integrations
- Add intelligent-router.sh hook for automatic agent routing
- Add AUTO-TRIGGER-SUMMARY.md documentation
- Add FINAL-INTEGRATION-SUMMARY.md documentation
- Complete Prometheus integration (6 commands + 4 tools)
- Complete Dexto integration (12 commands + 5 tools)
- Enhanced Ralph with access to all agents
- Fix /clawd command (removed disable-model-invocation)
- Update hooks.json to v5 with intelligent routing
- 291 total skills now available
- All 21 commands with automatic routing

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2026-01-28 00:27:56 +04:00

170 lines
7.5 KiB
TypeScript

import { describe, it, expect, beforeEach } from 'vitest';
import { useSessionStore } from './sessionStore.js';
describe('sessionStore', () => {
beforeEach(() => {
// Reset store to default state
useSessionStore.setState({
currentSessionId: null,
isWelcomeState: true,
isCreatingSession: false,
isSwitchingSession: false,
isReplayingHistory: false,
isLoadingHistory: false,
});
});
describe('setCurrentSession', () => {
it('should set the current session ID', () => {
useSessionStore.getState().setCurrentSession('session-123');
expect(useSessionStore.getState().currentSessionId).toBe('session-123');
});
it('should set isWelcomeState to false when setting a session', () => {
useSessionStore.getState().setCurrentSession('session-123');
expect(useSessionStore.getState().isWelcomeState).toBe(false);
});
it('should set isWelcomeState to true when setting null', () => {
useSessionStore.getState().setCurrentSession('session-123');
useSessionStore.getState().setCurrentSession(null);
expect(useSessionStore.getState().isWelcomeState).toBe(true);
expect(useSessionStore.getState().currentSessionId).toBeNull();
});
});
describe('setWelcomeState', () => {
it('should set welcome state to true and clear session', () => {
useSessionStore.getState().setCurrentSession('session-123');
useSessionStore.getState().setWelcomeState(true);
expect(useSessionStore.getState().isWelcomeState).toBe(true);
expect(useSessionStore.getState().currentSessionId).toBeNull();
});
it('should set welcome state to false without clearing session', () => {
useSessionStore.getState().setCurrentSession('session-123');
useSessionStore.getState().setWelcomeState(false);
expect(useSessionStore.getState().isWelcomeState).toBe(false);
expect(useSessionStore.getState().currentSessionId).toBe('session-123');
});
});
describe('returnToWelcome', () => {
it('should reset to welcome state and clear all flags', () => {
useSessionStore.setState({
currentSessionId: 'session-123',
isWelcomeState: false,
isCreatingSession: true,
isSwitchingSession: true,
isReplayingHistory: true,
isLoadingHistory: true,
});
useSessionStore.getState().returnToWelcome();
expect(useSessionStore.getState().currentSessionId).toBeNull();
expect(useSessionStore.getState().isWelcomeState).toBe(true);
expect(useSessionStore.getState().isCreatingSession).toBe(false);
expect(useSessionStore.getState().isSwitchingSession).toBe(false);
expect(useSessionStore.getState().isReplayingHistory).toBe(false);
expect(useSessionStore.getState().isLoadingHistory).toBe(false);
});
});
describe('session creation flow', () => {
it('should handle beginSessionCreation', () => {
useSessionStore.getState().beginSessionCreation();
expect(useSessionStore.getState().isCreatingSession).toBe(true);
expect(useSessionStore.getState().isWelcomeState).toBe(false);
});
it('should handle completeSessionCreation', () => {
useSessionStore.getState().beginSessionCreation();
useSessionStore.getState().completeSessionCreation('new-session-id');
expect(useSessionStore.getState().currentSessionId).toBe('new-session-id');
expect(useSessionStore.getState().isCreatingSession).toBe(false);
expect(useSessionStore.getState().isWelcomeState).toBe(false);
});
it('should handle cancelSessionCreation returning to welcome', () => {
// Start from welcome state
useSessionStore.getState().beginSessionCreation();
useSessionStore.getState().cancelSessionCreation();
expect(useSessionStore.getState().isCreatingSession).toBe(false);
expect(useSessionStore.getState().isWelcomeState).toBe(true);
});
it('should handle cancelSessionCreation staying in session', () => {
// Start from existing session
useSessionStore.getState().setCurrentSession('existing-session');
useSessionStore.getState().beginSessionCreation();
useSessionStore.getState().cancelSessionCreation();
expect(useSessionStore.getState().isCreatingSession).toBe(false);
// Should stay on existing session, not go to welcome
expect(useSessionStore.getState().isWelcomeState).toBe(false);
});
});
describe('selectors', () => {
it('isSessionOperationPending should return true when creating', () => {
useSessionStore.setState({ isCreatingSession: true });
expect(useSessionStore.getState().isSessionOperationPending()).toBe(true);
});
it('isSessionOperationPending should return true when switching', () => {
useSessionStore.setState({ isSwitchingSession: true });
expect(useSessionStore.getState().isSessionOperationPending()).toBe(true);
});
it('isSessionOperationPending should return true when loading history', () => {
useSessionStore.setState({ isLoadingHistory: true });
expect(useSessionStore.getState().isSessionOperationPending()).toBe(true);
});
it('isSessionOperationPending should return false when idle', () => {
expect(useSessionStore.getState().isSessionOperationPending()).toBe(false);
});
it('shouldSuppressNotifications should return true during replay', () => {
useSessionStore.setState({ isReplayingHistory: true });
expect(useSessionStore.getState().shouldSuppressNotifications()).toBe(true);
});
it('shouldSuppressNotifications should return true during switch', () => {
useSessionStore.setState({ isSwitchingSession: true });
expect(useSessionStore.getState().shouldSuppressNotifications()).toBe(true);
});
it('shouldSuppressNotifications should return false during normal operation', () => {
expect(useSessionStore.getState().shouldSuppressNotifications()).toBe(false);
});
});
describe('individual setters', () => {
it('should set creating session flag', () => {
useSessionStore.getState().setCreatingSession(true);
expect(useSessionStore.getState().isCreatingSession).toBe(true);
useSessionStore.getState().setCreatingSession(false);
expect(useSessionStore.getState().isCreatingSession).toBe(false);
});
it('should set switching session flag', () => {
useSessionStore.getState().setSwitchingSession(true);
expect(useSessionStore.getState().isSwitchingSession).toBe(true);
});
it('should set replaying history flag', () => {
useSessionStore.getState().setReplayingHistory(true);
expect(useSessionStore.getState().isReplayingHistory).toBe(true);
});
it('should set loading history flag', () => {
useSessionStore.getState().setLoadingHistory(true);
expect(useSessionStore.getState().isLoadingHistory).toBe(true);
});
});
});