- Add backend validation to detect and warn about anon vs service keys - Prevent startup with incorrect Supabase key configuration - Consolidate frontend state management following KISS principles - Remove duplicate state tracking and sessionStorage polling - Add clear error display when backend fails to start - Improve .env.example documentation with detailed key selection guide - Add comprehensive test coverage for validation logic - Remove unused test results checking to eliminate 404 errors The implementation now warns users about key misconfiguration while maintaining backward compatibility. Frontend state is simplified with MainLayout as the single source of truth for backend status.
83 lines
1.9 KiB
TypeScript
83 lines
1.9 KiB
TypeScript
import { expect, afterEach, vi } from 'vitest'
|
|
import { cleanup } from '@testing-library/react'
|
|
import '@testing-library/jest-dom/vitest'
|
|
|
|
// Set required environment variables for tests
|
|
process.env.ARCHON_SERVER_PORT = '8181'
|
|
|
|
// Clean up after each test
|
|
afterEach(() => {
|
|
cleanup()
|
|
})
|
|
|
|
// Simple mocks only - fetch and WebSocket
|
|
global.fetch = vi.fn(() =>
|
|
Promise.resolve({
|
|
ok: true,
|
|
json: () => Promise.resolve({}),
|
|
text: () => Promise.resolve(''),
|
|
status: 200,
|
|
} as Response)
|
|
) as any
|
|
|
|
// Mock WebSocket
|
|
class MockWebSocket {
|
|
onopen: ((event: Event) => void) | null = null
|
|
onclose: ((event: CloseEvent) => void) | null = null
|
|
onerror: ((event: Event) => void) | null = null
|
|
onmessage: ((event: MessageEvent) => void) | null = null
|
|
readyState: number = WebSocket.CONNECTING
|
|
|
|
constructor(public url: string) {
|
|
setTimeout(() => {
|
|
this.readyState = WebSocket.OPEN
|
|
if (this.onopen) {
|
|
this.onopen(new Event('open'))
|
|
}
|
|
}, 0)
|
|
}
|
|
|
|
send() {}
|
|
close() {
|
|
this.readyState = WebSocket.CLOSED
|
|
if (this.onclose) {
|
|
this.onclose(new CloseEvent('close'))
|
|
}
|
|
}
|
|
}
|
|
|
|
window.WebSocket = MockWebSocket as any
|
|
|
|
// Mock localStorage
|
|
const localStorageMock = {
|
|
getItem: vi.fn(() => null),
|
|
setItem: vi.fn(),
|
|
removeItem: vi.fn(),
|
|
clear: vi.fn(),
|
|
}
|
|
Object.defineProperty(window, 'localStorage', {
|
|
value: localStorageMock,
|
|
})
|
|
|
|
// Mock DOM methods that might not exist in test environment
|
|
Element.prototype.scrollIntoView = vi.fn()
|
|
window.HTMLElement.prototype.scrollIntoView = vi.fn()
|
|
|
|
// Mock lucide-react icons - create a proxy that returns icon name for any icon
|
|
vi.mock('lucide-react', () => {
|
|
return new Proxy({}, {
|
|
get: (target, prop) => {
|
|
if (typeof prop === 'string') {
|
|
return () => prop
|
|
}
|
|
return undefined
|
|
}
|
|
})
|
|
})
|
|
|
|
// Mock ResizeObserver
|
|
global.ResizeObserver = vi.fn().mockImplementation(() => ({
|
|
observe: vi.fn(),
|
|
unobserve: vi.fn(),
|
|
disconnect: vi.fn(),
|
|
})) |