All files / frontend/src/test mockStoreFactories.ts

93.46% Statements 143/153
100% Branches 20/20
73.68% Functions 14/19
93.46% Lines 143/153

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 1641x       1x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x   1x 64x 448x 448x 448x 448x 448x 448x 448x 448x 448x 448x 448x 448x 64x 64x 64x 448x 448x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x   1x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 3x 3x 64x 64x 64x 64x   1x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x     1x 1x 1x 1x   1x             1x            
import { create } from 'zustand';
 
// Create mock stores using Zustand's create() function
 
export const createMockDashboardStore = () => create(() => ({
    data: {
        modelInfo: {
            accuracy: 0.28,
            predictions_total: 150,
            predictions_successful: 135,
        },
        servicesHealth: {
            'api-gateway': { status: 'healthy', latency_ms: 10 },
            'rf-acquisition': { status: 'healthy', latency_ms: 50 },
            'training': { status: 'healthy', latency_ms: 30 },
            'inference': { status: 'healthy', latency_ms: 45 },
            'data-ingestion-web': { status: 'healthy', latency_ms: 20 },
        },
    },
    metrics: {
        accuracy_history: [0.25, 0.26, 0.27, 0.28],
        latency_avg_ms: 150,
        signalDetections: 42,
        systemUptime: 3600,
        activeWebSDRs: 7,
        totalWebSDRs: 7,
    },
    isLoading: false,
    error: null,
    lastUpdate: new Date().toISOString(),
    wsConnectionState: 'Disconnected',
    wsEnabled: false,
    fetchDashboardData: () => { },
    connectWebSocket: () => { },
    disconnectWebSocket: () => { },
}));
 
export const createMockWebSDRStore = () => create(() => ({
    websdrs: Array(7).fill(null).map((_, i) => ({
        id: i + 1,
        name: `WebSDR ${i + 1}`,
        url: `http://localhost:800${i}`,
        country: 'Italy',
        location: `Receiver ${i + 1}`,
        location_name: `Receiver ${i + 1}, Italy`,
        latitude: 45.1 + i * 0.1,
        longitude: 7.5 + i * 0.1,
        is_active: true,
        last_response_time_ms: 150 + i * 10,
        frequency_min_mhz: 140,
        frequency_max_mhz: 450,
    })),
    healthStatus: Object.fromEntries(
        Array(7).fill(null).map((_, i) => [
            `${i + 1}`,
            { status: 'online', response_time_ms: 150 + i * 10 },
        ])
    ),
    statistics: {
        online_count: 7,
        total_count: 7,
        active_count: 7,
        avg_response_time_ms: 151,
    },
    isLoading: false,
    error: null,
    fetchWebSDRs: () => { },
    checkHealth: () => { },
    refreshAll: () => { },
    lastHealthCheck: new Date().toISOString(),
}));
 
export const createMockSessionStore = () => {
    const store = create(() => ({
        knownSources: [
            {
                id: 1,
                name: 'Source 1',
                frequency_mhz: 145.5,
                frequency_hz: 145500000,
                is_validated: true,
                latitude: 45.1234,
                longitude: 7.5678,
            },
            {
                id: 2,
                name: 'Source 2',
                frequency_mhz: 430.5,
                frequency_hz: 430500000,
                is_validated: false,
                latitude: 45.5678,
                longitude: 7.1234,
            },
        ],
        sessions: [
            { id: 1, session_name: 'Session 1', status: 'completed', created_at: new Date().toISOString(), frequency_mhz: 145.5, duration_seconds: 60 },
            { id: 2, session_name: 'Session 2', status: 'pending', created_at: new Date().toISOString(), frequency_mhz: 430.5, duration_seconds: 120 },
        ],
        analytics: {
            total_sessions: 10,
            completed_sessions: 8,
            pending_sessions: 2,
            failed_sessions: 0,
            success_rate: 80,
            total_measurements: 100,
        },
        pagination: {
            page: 1,
            pageSize: 10,
            total: 2,
        },
        currentPage: 1,
        totalSessions: 2,
        perPage: 10,
        statusFilter: 'all',
        isLoading: false,
        error: null,
        fetchKnownSources: () => { },
        fetchSessions: () => { },
        fetchAnalytics: () => { },
        setStatusFilter: (filter: string) => {
            store.setState({ statusFilter: filter });
        },
        clearError: () => { },
    }));
    return store;
};
 
export const createMockAuthStore = () => create(() => ({
    user: {
        email: 'admin@heimdall.local',
        firstName: 'Admin',
        lastName: 'User',
        role: 'administrator',
        organization: 'Heimdall SDR',
        createdAt: new Date().toISOString(),
    },
    isAuthenticated: true,
    isLoading: false,
    error: null,
    logout: () => { },
    updateProfile: () => { },
}));
 
// Export stores globally during testing
let mockDashboardStore = createMockDashboardStore();
let mockWebSDRStore = createMockWebSDRStore();
let mockSessionStore = createMockSessionStore();
let mockAuthStore = createMockAuthStore();
 
export const getMockStores = () => ({
    mockDashboardStore,
    mockWebSDRStore,
    mockSessionStore,
    mockAuthStore,
});
 
export const resetMockStores = () => {
    mockDashboardStore = createMockDashboardStore();
    mockWebSDRStore = createMockWebSDRStore();
    mockSessionStore = createMockSessionStore();
    mockAuthStore = createMockAuthStore();
};