mirror of
https://github.com/tinyhumansai/openhuman.git
synced 2026-07-27 21:08:00 +00:00
Co-authored-by: Steven Enamakel's Droid <enamakel.agent@tinyhumans.ai> Co-authored-by: oxoxDev <164490987+oxoxDev@users.noreply.github.com> Co-authored-by: sanil-23 <sanil@tinyhumans.ai> Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
129 lines
3.6 KiB
TypeScript
129 lines
3.6 KiB
TypeScript
import { act, renderHook } from '@testing-library/react';
|
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
|
|
import { useSubconscious } from '../useSubconscious';
|
|
|
|
const mockStatus = {
|
|
result: {
|
|
enabled: true,
|
|
mode: 'simple',
|
|
provider_available: true,
|
|
provider_unavailable_reason: null,
|
|
interval_minutes: 30,
|
|
last_tick_at: null,
|
|
total_ticks: 0,
|
|
consecutive_failures: 0,
|
|
},
|
|
logs: [],
|
|
};
|
|
|
|
const mockSettings = {
|
|
result: {
|
|
settings: {
|
|
enabled: true,
|
|
interval_minutes: 30,
|
|
inference_enabled: true,
|
|
notify_meetings: false,
|
|
notify_reminders: false,
|
|
notify_relevant_events: false,
|
|
external_delivery_enabled: false,
|
|
meeting_lookahead_minutes: 120,
|
|
max_calendar_connections_per_tick: 2,
|
|
reminder_lookahead_minutes: 30,
|
|
subconscious_mode: 'simple' as const,
|
|
},
|
|
},
|
|
logs: [],
|
|
};
|
|
|
|
let currentMode = 'simple';
|
|
|
|
vi.mock('../../utils/tauriCommands', () => ({
|
|
isTauri: () => true,
|
|
subconsciousStatus: vi.fn(async () => mockStatus),
|
|
subconsciousTrigger: vi.fn(async () => ({ result: { triggered: true }, logs: [] })),
|
|
openhumanHeartbeatSettingsGet: vi.fn(async () => ({
|
|
result: { settings: { ...mockSettings.result.settings, subconscious_mode: currentMode } },
|
|
logs: [],
|
|
})),
|
|
openhumanHeartbeatSettingsSet: vi.fn(async (patch: Record<string, unknown>) => {
|
|
if (patch.subconscious_mode) currentMode = patch.subconscious_mode as string;
|
|
return {
|
|
result: {
|
|
settings: { ...mockSettings.result.settings, ...patch, subconscious_mode: currentMode },
|
|
},
|
|
logs: [],
|
|
};
|
|
}),
|
|
}));
|
|
|
|
describe('useSubconscious', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks();
|
|
vi.useFakeTimers();
|
|
currentMode = 'simple';
|
|
});
|
|
|
|
afterEach(() => {
|
|
vi.useRealTimers();
|
|
});
|
|
|
|
it('loads status and mode on mount', async () => {
|
|
const { result } = renderHook(() => useSubconscious());
|
|
|
|
await act(async () => {
|
|
await vi.advanceTimersByTimeAsync(0);
|
|
});
|
|
|
|
expect(result.current.mode).toBe('simple');
|
|
expect(result.current.intervalMinutes).toBe(30);
|
|
expect(result.current.status).not.toBeNull();
|
|
});
|
|
|
|
it('setMode calls heartbeat settings set', async () => {
|
|
const { openhumanHeartbeatSettingsSet } = await import('../../utils/tauriCommands');
|
|
const { result } = renderHook(() => useSubconscious());
|
|
|
|
await act(async () => {
|
|
await vi.advanceTimersByTimeAsync(0);
|
|
});
|
|
|
|
await act(async () => {
|
|
await result.current.setMode('aggressive');
|
|
});
|
|
|
|
expect(openhumanHeartbeatSettingsSet).toHaveBeenCalledWith({ subconscious_mode: 'aggressive' });
|
|
expect(result.current.mode).toBe('aggressive');
|
|
});
|
|
|
|
it('setIntervalMinutes calls heartbeat settings set', async () => {
|
|
const { openhumanHeartbeatSettingsSet } = await import('../../utils/tauriCommands');
|
|
const { result } = renderHook(() => useSubconscious());
|
|
|
|
await act(async () => {
|
|
await vi.advanceTimersByTimeAsync(0);
|
|
});
|
|
|
|
await act(async () => {
|
|
await result.current.setIntervalMinutes(15);
|
|
});
|
|
|
|
expect(openhumanHeartbeatSettingsSet).toHaveBeenCalledWith({ interval_minutes: 15 });
|
|
});
|
|
|
|
it('triggerTick calls subconsciousTrigger', async () => {
|
|
const { subconsciousTrigger } = await import('../../utils/tauriCommands');
|
|
const { result } = renderHook(() => useSubconscious());
|
|
|
|
await act(async () => {
|
|
await vi.advanceTimersByTimeAsync(0);
|
|
});
|
|
|
|
await act(async () => {
|
|
await result.current.triggerTick();
|
|
});
|
|
|
|
expect(subconsciousTrigger).toHaveBeenCalled();
|
|
});
|
|
});
|