aa5c857060
移除根 H5 包中冗余的 Tauri HTTP 依赖并同步锁文件 修正客户端错误边界测试的 import 顺序 固定两项后台 Runtime 恢复测试使用 Provider 模式 补充 AGC 原生 HTTP 依赖归属约束
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
/** @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);
|
|
});
|
|
});
|