/** @vitest-environment jsdom */ import { fireEvent, render, screen } from '@testing-library/react'; import { createElement } from 'react'; import { afterEach, describe, expect, it, vi } from 'vitest'; import { ClientRuntimeErrorBoundary } from '../src/app/AuthenticatedClient'; function BrokenAuthenticatedContent() { throw new Error('首页渲染失败'); } describe('AGC authenticated client error boundary', () => { afterEach(() => { vi.restoreAllMocks(); }); it('replaces a render crash with a recoverable login action', () => { vi.spyOn(console, 'error').mockImplementation(() => undefined); const onLogout = vi.fn(); render( createElement( ClientRuntimeErrorBoundary, { onLogout }, createElement(BrokenAuthenticatedContent), ), ); expect( screen.getByRole('main', { name: '客户端页面加载失败' }), ).toBeTruthy(); expect(screen.getByText('首页渲染失败')).toBeTruthy(); fireEvent.click(screen.getByRole('button', { name: '返回登录' })); expect(onLogout).toHaveBeenCalledTimes(1); }); });