perf(monitor): bound map refresh fingerprints
This commit is contained in:
@@ -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'],
|
||||
|
||||
Reference in New Issue
Block a user