feat(vehicle): prioritize live status
This commit is contained in:
@@ -83,6 +83,7 @@ test('keeps the monitor return on the vehicle page and its nested investigation
|
||||
vi.spyOn(api, 'vehicleDetail').mockResolvedValue(detail);
|
||||
vi.spyOn(api, 'vehicleRealtime').mockResolvedValue({ items: [initialRealtime], total: 1, limit: 1, offset: 0 });
|
||||
vi.spyOn(api, 'latestTelemetry').mockResolvedValue({ values: [], categories: [], scannedFrames: 0 } as never);
|
||||
const addressSpy = vi.spyOn(api, 'reverseGeocode').mockResolvedValue({ provider: 'amap', longitude: 113.26, latitude: 23.13, formattedAddress: '广东省广州市测试道路' });
|
||||
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
const monitorPath = buildMonitorPath({
|
||||
mode: 'map', keyword: '', protocol: '', status: '', selectedVin: 'LTEST000000000001', detailOpen: true,
|
||||
@@ -95,6 +96,46 @@ test('keeps the monitor return on the vehicle page and its nested investigation
|
||||
expect(await screen.findByRole('link', { name: /返回全局监控/ })).toHaveAttribute('href', monitorPath);
|
||||
const trackLink = screen.getByRole('link', { name: /轨迹回放/ });
|
||||
const historyLink = screen.getByRole('link', { name: /历史数据/ });
|
||||
const mileageLink = screen.getByRole('link', { name: /里程查询/ });
|
||||
expect(new URL(trackLink.getAttribute('href')!, 'http://localhost').searchParams.get('monitorReturn')).toBe(monitorPath);
|
||||
expect(new URL(historyLink.getAttribute('href')!, 'http://localhost').searchParams.get('monitorReturn')).toBe(monitorPath);
|
||||
expect(new URL(mileageLink.getAttribute('href')!, 'http://localhost').searchParams.get('monitorReturn')).toBe(monitorPath);
|
||||
|
||||
const liveOverview = screen.getByText('最新上报').closest('section');
|
||||
const archive = screen.getByText('车辆主档').closest('section');
|
||||
expect(liveOverview).not.toBeNull();
|
||||
expect(archive).not.toBeNull();
|
||||
expect(liveOverview!.compareDocumentPosition(archive!)).toBe(Node.DOCUMENT_POSITION_FOLLOWING);
|
||||
|
||||
expect(addressSpy).not.toHaveBeenCalled();
|
||||
fireEvent.click(screen.getByRole('button', { name: '解析当前位置' }));
|
||||
expect(await screen.findByText('广东省广州市测试道路')).toBeInTheDocument();
|
||||
expect(addressSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
test('shows unavailable live fields as dashes instead of fabricated zeroes', async () => {
|
||||
const unavailable = {
|
||||
...initialRealtime,
|
||||
speedAvailable: false,
|
||||
speedKmh: 0,
|
||||
socAvailable: false,
|
||||
socPercent: 0,
|
||||
mileageAvailable: false,
|
||||
totalMileageKm: 0,
|
||||
todayMileageAvailable: false,
|
||||
todayMileageKm: 0
|
||||
};
|
||||
vi.spyOn(api, 'vehicleDetail').mockResolvedValue({ ...detail, realtimeSummary: unavailable });
|
||||
vi.spyOn(api, 'vehicleRealtime').mockResolvedValue({ items: [unavailable], total: 1, limit: 1, offset: 0 });
|
||||
vi.spyOn(api, 'latestTelemetry').mockResolvedValue({ values: [], categories: [], scannedFrames: 0 } as never);
|
||||
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
|
||||
render(<QueryClientProvider client={client}><MemoryRouter initialEntries={[`/vehicles/${initialRealtime.vin}`]} future={ROUTER_FUTURE}><Routes><Route path="/vehicles/:vin" element={<VehiclePage />} /></Routes></MemoryRouter></QueryClientProvider>);
|
||||
|
||||
const liveOverview = (await screen.findByText('最新上报')).closest('section')!;
|
||||
for (const label of ['速度', 'SOC', '总里程', '当日里程']) {
|
||||
const metric = Array.from(liveOverview.querySelectorAll('.v2-live-grid > div')).find((item) => item.querySelector('small')?.textContent === label);
|
||||
expect(metric).toHaveTextContent('—');
|
||||
expect(metric).not.toHaveTextContent(/^0/);
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user