perf(tracks): defer empty map runtime
This commit is contained in:
@@ -98,6 +98,68 @@ afterEach(() => {
|
||||
mapInstances.length = 0;
|
||||
});
|
||||
|
||||
test('defers the map runtime until valid track data exists and releases it when data is cleared', async () => {
|
||||
window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: 'amap-web-key' };
|
||||
const load = vi.fn(async () => amapMock());
|
||||
window.AMapLoader = { load };
|
||||
const view = render(<TrackMap
|
||||
points={[]}
|
||||
stops={[]}
|
||||
activeIndex={0}
|
||||
showStops={false}
|
||||
follow
|
||||
onSelectIndex={() => undefined}
|
||||
onFollowChange={() => undefined}
|
||||
/>);
|
||||
|
||||
expect(load).not.toHaveBeenCalled();
|
||||
expect(mapInstances).toHaveLength(0);
|
||||
expect(view.container.querySelector('.v2-map-state')).not.toBeInTheDocument();
|
||||
|
||||
view.rerender(<TrackMap
|
||||
points={points}
|
||||
stops={[]}
|
||||
activeIndex={0}
|
||||
showStops={false}
|
||||
follow
|
||||
onSelectIndex={() => undefined}
|
||||
onFollowChange={() => undefined}
|
||||
/>);
|
||||
await waitFor(() => expect(mapInstances).toHaveLength(1));
|
||||
expect(load).toHaveBeenCalledTimes(1);
|
||||
|
||||
view.rerender(<TrackMap
|
||||
points={[]}
|
||||
stops={[]}
|
||||
activeIndex={0}
|
||||
showStops={false}
|
||||
follow
|
||||
onSelectIndex={() => undefined}
|
||||
onFollowChange={() => undefined}
|
||||
/>);
|
||||
await waitFor(() => expect(mapDestroy).toHaveBeenCalledTimes(1));
|
||||
expect(mapInstances).toHaveLength(1);
|
||||
});
|
||||
|
||||
test('does not initialize the map for rows without a valid coordinate', () => {
|
||||
window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: 'amap-web-key' };
|
||||
const load = vi.fn(async () => amapMock());
|
||||
window.AMapLoader = { load };
|
||||
render(<TrackMap
|
||||
points={[{ ...points[0], longitude: 0, latitude: 0 }]}
|
||||
stops={[]}
|
||||
activeIndex={0}
|
||||
showStops={false}
|
||||
follow
|
||||
onSelectIndex={() => undefined}
|
||||
onFollowChange={() => undefined}
|
||||
/>);
|
||||
|
||||
expect(load).not.toHaveBeenCalled();
|
||||
expect(mapInstances).toHaveLength(0);
|
||||
expect(document.body).toHaveTextContent('当前轨迹没有可展示的有效坐标');
|
||||
});
|
||||
|
||||
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()) };
|
||||
|
||||
Reference in New Issue
Block a user