fix(web): retry transient map load failures

This commit is contained in:
lingniu
2026-07-16 07:13:23 +08:00
parent 970ef5d7c0
commit a0448d6615
5 changed files with 29 additions and 12 deletions

View File

@@ -1,4 +1,4 @@
import { cleanup, render, waitFor } from '@testing-library/react';
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { afterEach, expect, test, vi } from 'vitest';
import type { HistoryLocationRow, TrackStop } from '../../api/types';
import type { AMapLike } from '../../integrations/amap';
@@ -98,9 +98,11 @@ afterEach(() => {
mapInstances.length = 0;
});
test('defers the map runtime until valid track data exists and releases it when data is cleared', async () => {
test('defers the map runtime until valid data exists, retries a transient failure, and releases it when cleared', async () => {
window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: 'amap-web-key' };
const load = vi.fn(async () => amapMock());
const load = vi.fn()
.mockRejectedValueOnce(new Error('temporary map network failure'))
.mockResolvedValueOnce(amapMock());
window.AMapLoader = { load };
const view = render(<TrackMap
points={[]}
@@ -125,8 +127,11 @@ test('defers the map runtime until valid track data exists and releases it when
onSelectIndex={() => undefined}
onFollowChange={() => undefined}
/>);
expect(await screen.findByText(/地图加载失败/)).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /重新加载地图/ }));
await waitFor(() => expect(mapInstances).toHaveLength(1));
expect(load).toHaveBeenCalledTimes(1);
expect(load).toHaveBeenCalledTimes(2);
expect(screen.queryByText(/地图加载失败/)).not.toBeInTheDocument();
view.rerender(<TrackMap
points={[]}