Some checks failed
CI Docker Mining Proof / Linux agent hashrate proof (push) Has been cancelled
Dashboard ambient layer, comrade presence, Mission Deck and War Room, Emberwake supply chain, spread/docs publishing, fleet policy and modules API, CI docker mining, and refreshed USB pack.
45 lines
1.5 KiB
TypeScript
45 lines
1.5 KiB
TypeScript
/**
|
|
* @vitest-environment happy-dom
|
|
*/
|
|
import { describe, expect, it } from 'vitest';
|
|
import { renderHook } from '@testing-library/react';
|
|
import { WebSocketContext, useWebSocketContext } from './WebSocketContext';
|
|
import { mockAgent } from '../test/fixtures';
|
|
|
|
describe('WebSocketContext', () => {
|
|
it('useWebSocketContext returns default value outside provider', () => {
|
|
const { result } = renderHook(() => useWebSocketContext());
|
|
|
|
expect(result.current.isConnected).toBe(false);
|
|
expect(result.current.agents).toEqual([]);
|
|
expect(result.current.commandResults).toEqual([]);
|
|
expect(result.current.latestMessage).toBeNull();
|
|
});
|
|
|
|
it('useWebSocketContext reads provider value', () => {
|
|
const value = {
|
|
isConnected: true,
|
|
agents: [mockAgent()],
|
|
recentShares: [],
|
|
fleetAlerts: [],
|
|
poolStatus: [],
|
|
aiActivity: [],
|
|
agentLogs: { 'agent-001-uuid': 'log line' },
|
|
commandResults: [{ agent_id: 'a1', action: 'pause', success: true, _seq: 1 }],
|
|
latestMessage: null,
|
|
sendDashboardMessage: () => {},
|
|
};
|
|
|
|
const wrapper = ({ children }: { children: React.ReactNode }) => (
|
|
<WebSocketContext.Provider value={value}>{children}</WebSocketContext.Provider>
|
|
);
|
|
|
|
const { result } = renderHook(() => useWebSocketContext(), { wrapper });
|
|
|
|
expect(result.current.isConnected).toBe(true);
|
|
expect(result.current.agents).toHaveLength(1);
|
|
expect(result.current.agentLogs['agent-001-uuid']).toBe('log line');
|
|
expect(result.current.commandResults[0]._seq).toBe(1);
|
|
});
|
|
});
|