第7项:按路由加载页面并核验登录和开单冷启动预算

This commit is contained in:
黄健铭 committed 2026-12-05 08:25:22 -08:00
1 parent c6ad648d7e
commit f9cd68c569
71 files changed
+1250 -454

No files matched your search

@@ -0,0 +1,37 @@
import { lazy } from 'react';
import { render, screen } from '@testing-library/react';
import { expect, it, vi } from 'vitest';
import { RouteBoundary } from '../src/components/RouteBoundary';
import { loadPage } from '../src/lib/loadPage';
it('页面资源中断时保留外壳,仍可切到其他页面', async () => {
const page = new Promise<{ default: () => null }>((_, reject) => {
queueMicrotask(() => reject(new TypeError('offline')));
});
const MissingPage = lazy(() => loadPage(page));
const logged = vi.spyOn(console, 'error').mockImplementation(() => {});
try {
const view = render(
<>
<nav>功能菜单</nav>
<RouteBoundary location="/next/report">
<MissingPage />
</RouteBoundary>
</>,
);
expect(await screen.findByRole('button', { name: '重新加载页面' })).toBeEnabled();
expect(screen.getByRole('navigation')).toBeVisible();
view.rerender(
<>
<nav>功能菜单</nav>
<RouteBoundary location="/next/stock">
<p>库存</p>
</RouteBoundary>
</>,
);
expect(screen.getByText('库存')).toBeVisible();
expect(screen.queryByRole('button', { name: '重新加载页面' })).toBeNull();
} finally {
logged.mockRestore();
}
});