Set up the complete project foundation for ClawX, a graphical AI assistant: - Electron main process with IPC handlers, menu, tray, and gateway management - React renderer with routing, layout components, and page scaffolding - Zustand state management for gateway, settings, channels, skills, chat, and cron - shadcn/ui components with Tailwind CSS and CSS variable theming - Build tooling with Vite, electron-builder, and TypeScript configuration - Testing setup with Vitest and Playwright - Development configurations (ESLint, Prettier, gitignore, env example)
76 lines
2.2 KiB
TypeScript
76 lines
2.2 KiB
TypeScript
/**
|
|
* Zustand Stores Tests
|
|
*/
|
|
import { describe, it, expect, beforeEach, vi } from 'vitest';
|
|
import { useSettingsStore } from '@/stores/settings';
|
|
import { useGatewayStore } from '@/stores/gateway';
|
|
|
|
describe('Settings Store', () => {
|
|
beforeEach(() => {
|
|
// Reset store to default state
|
|
useSettingsStore.setState({
|
|
theme: 'system',
|
|
language: 'en',
|
|
sidebarCollapsed: false,
|
|
devModeUnlocked: false,
|
|
gatewayAutoStart: true,
|
|
gatewayPort: 18789,
|
|
autoCheckUpdate: true,
|
|
autoDownloadUpdate: false,
|
|
startMinimized: false,
|
|
launchAtStartup: false,
|
|
updateChannel: 'stable',
|
|
});
|
|
});
|
|
|
|
it('should have default values', () => {
|
|
const state = useSettingsStore.getState();
|
|
expect(state.theme).toBe('system');
|
|
expect(state.sidebarCollapsed).toBe(false);
|
|
expect(state.gatewayAutoStart).toBe(true);
|
|
});
|
|
|
|
it('should update theme', () => {
|
|
const { setTheme } = useSettingsStore.getState();
|
|
setTheme('dark');
|
|
expect(useSettingsStore.getState().theme).toBe('dark');
|
|
});
|
|
|
|
it('should toggle sidebar collapsed state', () => {
|
|
const { setSidebarCollapsed } = useSettingsStore.getState();
|
|
setSidebarCollapsed(true);
|
|
expect(useSettingsStore.getState().sidebarCollapsed).toBe(true);
|
|
});
|
|
|
|
it('should unlock dev mode', () => {
|
|
const { setDevModeUnlocked } = useSettingsStore.getState();
|
|
setDevModeUnlocked(true);
|
|
expect(useSettingsStore.getState().devModeUnlocked).toBe(true);
|
|
});
|
|
});
|
|
|
|
describe('Gateway Store', () => {
|
|
beforeEach(() => {
|
|
// Reset store
|
|
useGatewayStore.setState({
|
|
status: { state: 'stopped', port: 18789 },
|
|
isInitialized: false,
|
|
});
|
|
});
|
|
|
|
it('should have default status', () => {
|
|
const state = useGatewayStore.getState();
|
|
expect(state.status.state).toBe('stopped');
|
|
expect(state.status.port).toBe(18789);
|
|
});
|
|
|
|
it('should update status', () => {
|
|
const { setStatus } = useGatewayStore.getState();
|
|
setStatus({ state: 'running', port: 18789, pid: 12345 });
|
|
|
|
const state = useGatewayStore.getState();
|
|
expect(state.status.state).toBe('running');
|
|
expect(state.status.pid).toBe(12345);
|
|
});
|
|
});
|