fix(monitor): isolate batch search scope

This commit is contained in:
lingniu
2026-07-16 04:52:35 +08:00
parent 14525887ea
commit 25f3fa9c64
8 changed files with 113 additions and 20 deletions

View File

@@ -41,6 +41,45 @@ test('rapid viewport changes retain one workspace payload and avoid duplicate fl
client.clear();
});
test('retains workspace data for viewport changes but clears it across filter scopes', async () => {
const oldWorkspace = {
summary: { totalVehicles: 1, onlineVehicles: 1, offlineVehicles: 0, drivingVehicles: 1, idleVehicles: 0, unknownVehicles: 0, alertVehicles: 0, activeToday: 1, frameToday: 1, alertDataAvailable: false, truncated: false, asOf: '' },
vehicles: { items: [{ vin: 'OLDVIN', plate: '旧车牌' }], total: 1, limit: 200, offset: 0 },
map: { mode: 'points', zoom: 13, total: 1, truncated: false, points: [], clusters: [], asOf: '' }
} as never;
let calls = 0;
const monitorWorkspace = vi.spyOn(api, 'monitorWorkspace').mockImplementation(() => {
calls += 1;
return calls === 1 ? Promise.resolve(oldWorkspace) : new Promise(() => undefined);
});
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
const wrapper = ({ children }: { children: ReactNode }) => <QueryClientProvider client={client}>{children}</QueryClientProvider>;
const view = renderHook(({ bounds, protocol }) => useMonitorData(
{ keyword: '', protocol, status: '' },
{ zoom: 13, bounds },
'',
true,
false
), {
wrapper,
initialProps: { bounds: '113,22,114,23', protocol: '' }
});
await waitFor(() => expect(view.result.current.vehicles.data?.items[0]?.vin).toBe('OLDVIN'));
view.rerender({ bounds: '113.1,22,114.1,23', protocol: '' });
await waitFor(() => expect(monitorWorkspace).toHaveBeenCalledTimes(2));
expect(view.result.current.vehicles.data?.items[0]?.vin).toBe('OLDVIN');
expect(view.result.current.vehicles.isPlaceholderData).toBe(true);
view.rerender({ bounds: '113.1,22,114.1,23', protocol: 'JT808' });
await waitFor(() => expect(monitorWorkspace).toHaveBeenCalledTimes(3));
expect(view.result.current.vehicles.data).toBeUndefined();
expect(view.result.current.vehicles.isLoading).toBe(true);
view.unmount();
client.clear();
});
test('repeated vehicle selections retain only the active realtime payload and release it on unmount', async () => {
vi.spyOn(api, 'monitorSummary').mockResolvedValue({ totalVehicles: 0, onlineVehicles: 0, offlineVehicles: 0, drivingVehicles: 0, idleVehicles: 0, unknownVehicles: 0, alertVehicles: 0, activeToday: 0, frameToday: 0, alertDataAvailable: false, truncated: false, asOf: '' });
const vehicleRealtime = vi.spyOn(api, 'vehicleRealtime').mockResolvedValue({ items: [], total: 0, limit: 1, offset: 0 });