perf(monitor): isolate follow viewport events
This commit is contained in:
@@ -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' };
|
||||
|
||||
Reference in New Issue
Block a user