perf(monitor): isolate follow viewport events

This commit is contained in:
lingniu
2026-07-16 10:41:41 +08:00
parent e0a5ba6f5d
commit 9384d6acf5
2 changed files with 25 additions and 1 deletions

View File

@@ -14,7 +14,7 @@ const markerSetMap = vi.fn();
const markerSetPosition = vi.fn();
const labelSetPosition = vi.fn();
const setZoomAndCenter = vi.fn();
const setCenter = vi.fn();
const setCenter = vi.fn(() => mapHandlers.get('moveend')?.({}));
const panTo = vi.fn();
const mapOff = vi.fn();
const mapDestroy = vi.fn();
@@ -521,6 +521,24 @@ test('renders one selected plate and smoothly follows it until the map is dragge
expect((hiddenFloatingLabels[0].options.text as { content: string }).content).toBe('粤A12345');
});
test('does not treat intermediate programmatic follow frames as user viewport changes', async () => {
useFastAnimationFrames();
window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: 'amap-web-key' };
window.AMapLoader = { load: vi.fn(async () => amapMock()) };
const onViewportChange = vi.fn();
const view = render(<FleetMap vehicles={[]} monitorMap={pointMap} selectedVin="LTEST000000000001" onSelect={() => undefined} onViewportChange={onViewportChange} />);
await waitFor(() => expect(onViewportChange).toHaveBeenCalled());
onViewportChange.mockReset();
view.rerender(<FleetMap vehicles={[]} monitorMap={{
...pointMap,
points: [{ ...pointMap.points[0], longitude: 113.27, latitude: 23.14 }, pointMap.points[1]]
}} selectedVin="LTEST000000000001" onSelect={() => undefined} onViewportChange={onViewportChange} />);
await waitFor(() => expect(setCenter).toHaveBeenLastCalledWith(wgs84ToGcj02(113.27, 23.14)), { timeout: 1_800 });
await waitFor(() => expect(onViewportChange).toHaveBeenCalledTimes(1));
});
test('renders every nearby plate with staggered positions at maximum zoom', async () => {
getZoom.mockReturnValue(20);
window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: 'amap-web-key' };