fix(web): recover route errors on scope change
This commit is contained in:
@@ -58,4 +58,29 @@ describe('route recovery boundary', () => {
|
||||
expect(screen.getByText('本地状态 1')).toBeInTheDocument();
|
||||
expect(mounts).toBe(1);
|
||||
});
|
||||
|
||||
it('retries a failed route when its search scope changes without remounting healthy scopes', () => {
|
||||
vi.spyOn(console, 'error').mockImplementation(() => undefined);
|
||||
let healthyMounts = 0;
|
||||
function ScopeSensitivePage() {
|
||||
const [params] = useSearchParams();
|
||||
if (params.get('scope') === 'broken') throw new Error('invalid route scope');
|
||||
useEffect(() => { healthyMounts += 1; }, []);
|
||||
return <strong>新筛选范围已恢复</strong>;
|
||||
}
|
||||
function RecoveryHarness() {
|
||||
const [, setSearchParams] = useSearchParams();
|
||||
return <><button type="button" onClick={() => setSearchParams({ scope: 'healthy' })}>修正筛选条件</button><RoutePage page={ScopeSensitivePage} label="告警中心" /></>;
|
||||
}
|
||||
|
||||
render(<MemoryRouter future={ROUTER_FUTURE} initialEntries={['/alerts?scope=broken']}><RecoveryHarness /></MemoryRouter>);
|
||||
expect(screen.getByRole('alert')).toHaveTextContent('当前模块暂时无法显示');
|
||||
expect(screen.getByText(/更换筛选条件会自动重试/)).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '修正筛选条件' }));
|
||||
|
||||
expect(screen.queryByRole('alert')).not.toBeInTheDocument();
|
||||
expect(screen.getByText('新筛选范围已恢复')).toBeInTheDocument();
|
||||
expect(healthyMounts).toBe(1);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user