perf(tracks): bound playback rendering work
This commit is contained in:
@@ -9,8 +9,11 @@ const overlaySetMap = vi.fn();
|
||||
const mapOff = vi.fn();
|
||||
const mapDestroy = vi.fn();
|
||||
const markerListeners: Array<{ overlay: TestOverlay; event: string; handler: () => void }> = [];
|
||||
const overlayInstances: TestOverlay[] = [];
|
||||
const mapInstances: TestMap[] = [];
|
||||
|
||||
class TestOverlay {
|
||||
constructor() { overlayInstances.push(this); }
|
||||
on = vi.fn((event: string, handler: () => void) => markerListeners.push({ overlay: this, event, handler }));
|
||||
off = overlayOff;
|
||||
setMap = overlaySetMap;
|
||||
@@ -19,6 +22,7 @@ class TestOverlay {
|
||||
}
|
||||
|
||||
class TestMap {
|
||||
constructor() { mapInstances.push(this); }
|
||||
add = vi.fn();
|
||||
addControl = vi.fn();
|
||||
setFitView = vi.fn();
|
||||
@@ -90,6 +94,38 @@ afterEach(() => {
|
||||
mapOff.mockReset();
|
||||
mapDestroy.mockReset();
|
||||
markerListeners.length = 0;
|
||||
overlayInstances.length = 0;
|
||||
mapInstances.length = 0;
|
||||
});
|
||||
|
||||
test('uses the playback cadence for follow animation and advances the passed path', async () => {
|
||||
window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: 'amap-web-key' };
|
||||
window.AMapLoader = { load: vi.fn(async () => amapMock()) };
|
||||
const view = render(<TrackMap
|
||||
points={points}
|
||||
stops={[]}
|
||||
activeIndex={0}
|
||||
showStops={false}
|
||||
follow
|
||||
followDurationMs={65}
|
||||
onSelectIndex={() => undefined}
|
||||
onFollowChange={() => undefined}
|
||||
/>);
|
||||
|
||||
await waitFor(() => expect(mapInstances).toHaveLength(1));
|
||||
view.rerender(<TrackMap
|
||||
points={points}
|
||||
stops={[]}
|
||||
activeIndex={1}
|
||||
showStops={false}
|
||||
follow
|
||||
followDurationMs={65}
|
||||
onSelectIndex={() => undefined}
|
||||
onFollowChange={() => undefined}
|
||||
/>);
|
||||
|
||||
await waitFor(() => expect(mapInstances[0].panTo).toHaveBeenLastCalledWith(expect.any(Array), 65));
|
||||
expect(overlayInstances.some((overlay) => overlay.setPath.mock.calls.some(([path]) => Array.isArray(path) && path.length === 2))).toBe(true);
|
||||
});
|
||||
|
||||
test('detaches every marker listener and map listener on unmount', async () => {
|
||||
|
||||
Reference in New Issue
Block a user