perf(monitor): bound map refresh fingerprints

This commit is contained in:
lingniu
2026-07-16 08:38:41 +08:00
parent 4c54cfa6ff
commit 91b5d76657
2 changed files with 85 additions and 10 deletions

View File

@@ -2,7 +2,7 @@ import { act, cleanup, fireEvent, render, screen, waitFor } from '@testing-libra
import { afterEach, expect, test, vi } from 'vitest';
import type { MonitorMapResponse } from '../../api/types';
import { wgs84ToGcj02, type AMapLike, type AMapMap, type AMapMassPoint } from '../../integrations/amap';
import { FleetMap } from './FleetMap';
import { FleetMap, massPointFingerprint } from './FleetMap';
const setData = vi.fn<(data: AMapMassPoint[]) => void>();
const setStyle = vi.fn();
@@ -124,6 +124,23 @@ const pointMap: MonitorMapResponse = {
}]
};
test('keeps large fleet redraw fingerprints constant-size and sensitive to point changes', () => {
const manyPoints = Array.from({ length: 10_000 }, (_, index) => ({
...pointMap.points[index % pointMap.points.length],
vin: `LARGE-FLEET-${index}`,
longitude: 113.26 + index / 1_000_000
}));
const fingerprint = massPointFingerprint('points', [], manyPoints, []);
const changed = massPointFingerprint('points', [], [
...manyPoints.slice(0, -1),
{ ...manyPoints[manyPoints.length - 1], longitude: 114.5 }
], []);
expect(fingerprint.length).toBeLessThan(40);
expect(changed).not.toBe(fingerprint);
expect(massPointFingerprint('points', [], manyPoints, [])).toBe(fingerprint);
});
function amapMock(): AMapLike {
return {
Map: TestMap as unknown as AMapLike['Map'],