/** * Route guard for the main webview. Verifies that each auth-store precondition * (logged-in flag, an active server id, at least one stored server) is enforced * independently before the children render. */ import { afterEach, describe, expect, it, vi } from 'vitest'; import { render, cleanup } from '@testing-library/react'; const { authState } = vi.hoisted(() => ({ authState: { isLoggedIn: true, activeServerId: 'srv-1', servers: [{ id: 'srv-1', name: 'home' }], }, })); vi.mock('../store/authStore', () => ({ useAuthStore: () => authState, })); vi.mock('react-router-dom', () => ({ Navigate: ({ to }: { to: string }) =>
, })); import { RequireAuth } from './RequireAuth'; afterEach(() => { cleanup(); authState.isLoggedIn = true; authState.activeServerId = 'srv-1'; authState.servers = [{ id: 'srv-1', name: 'home' }]; }); describe('RequireAuth', () => { it('renders children when fully authenticated', () => { const { getByTestId, queryByTestId } = render(