fix(web): retry transient map load failures
This commit is contained in:
@@ -167,13 +167,16 @@ afterEach(() => {
|
||||
vi.restoreAllMocks();
|
||||
});
|
||||
|
||||
test('renders data that arrives before the delayed AMap SDK is ready', async () => {
|
||||
test('recovers in place after a transient AMap failure and renders data that arrived while retrying', async () => {
|
||||
let resolveAMap!: (value: AMapLike) => void;
|
||||
const delayedAMap = new Promise<AMapLike>((resolve) => {
|
||||
resolveAMap = resolve;
|
||||
});
|
||||
window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: 'amap-web-key' };
|
||||
window.AMapLoader = { load: vi.fn(() => delayedAMap) };
|
||||
const load = vi.fn()
|
||||
.mockRejectedValueOnce(new Error('temporary map network failure'))
|
||||
.mockImplementationOnce(() => delayedAMap);
|
||||
window.AMapLoader = { load };
|
||||
|
||||
render(
|
||||
<FleetMap
|
||||
@@ -183,6 +186,8 @@ test('renders data that arrives before the delayed AMap SDK is ready', async ()
|
||||
/>
|
||||
);
|
||||
|
||||
expect(await screen.findByText(/地图加载失败/)).toBeInTheDocument();
|
||||
fireEvent.click(screen.getByRole('button', { name: /重新加载地图/ }));
|
||||
expect(setData).not.toHaveBeenCalled();
|
||||
|
||||
await act(async () => {
|
||||
@@ -196,6 +201,8 @@ test('renders data that arrives before the delayed AMap SDK is ready', async ()
|
||||
const clusterStyles = setStyle.mock.calls[setStyle.mock.calls.length - 1]?.[0] as Array<{ url: string }>;
|
||||
expect(decodeURIComponent(clusterStyles[5].url)).toContain('>12</text>');
|
||||
expect(decodeURIComponent(clusterStyles[5].url)).not.toContain('10+');
|
||||
expect(load).toHaveBeenCalledTimes(2);
|
||||
expect(screen.queryByText(/地图加载失败/)).not.toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('detaches AMap listeners and destroys the map on unmount', async () => {
|
||||
|
||||
Reference in New Issue
Block a user