feat(platform): show realtime data freshness
This commit is contained in:
@@ -7626,6 +7626,79 @@ test('refreshes realtime vehicle data from the monitoring workspace', async () =
|
||||
expect(realtimeCalls).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test('shows realtime freshness status for recently updated and stale vehicles', async () => {
|
||||
window.history.replaceState(null, '', '/#/map');
|
||||
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
|
||||
const path = String(input);
|
||||
if (path.includes('/api/realtime/vehicles')) {
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: {
|
||||
items: [
|
||||
{
|
||||
vin: 'VIN-FRESH-001',
|
||||
plate: '粤A新鲜1',
|
||||
protocols: ['GB32960'],
|
||||
sourceStatus: [{ protocol: 'GB32960', online: true, lastSeen: '2999-07-04 17:00:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }],
|
||||
sourceCount: 1,
|
||||
onlineSourceCount: 1,
|
||||
online: true,
|
||||
primaryProtocol: 'GB32960',
|
||||
longitude: 113.2,
|
||||
latitude: 23.1,
|
||||
speedKmh: 30,
|
||||
socPercent: 78,
|
||||
totalMileageKm: 119925,
|
||||
lastSeen: '2999-07-04 17:00:00',
|
||||
bindingStatus: 'bound'
|
||||
},
|
||||
{
|
||||
vin: 'VIN-STALE-001',
|
||||
plate: '粤A超时1',
|
||||
protocols: ['JT808'],
|
||||
sourceStatus: [{ protocol: 'JT808', online: false, lastSeen: '2020-01-01 00:00:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }],
|
||||
sourceCount: 1,
|
||||
onlineSourceCount: 0,
|
||||
online: false,
|
||||
primaryProtocol: 'JT808',
|
||||
longitude: 113.3,
|
||||
latitude: 23.2,
|
||||
speedKmh: 0,
|
||||
socPercent: 50,
|
||||
totalMileageKm: 1000,
|
||||
lastSeen: '2020-01-01 00:00:00',
|
||||
bindingStatus: 'bound'
|
||||
}
|
||||
],
|
||||
total: 2,
|
||||
limit: 50,
|
||||
offset: 0
|
||||
},
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
}
|
||||
return {
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
data: { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
|
||||
traceId: 'trace-test',
|
||||
timestamp: 1783094400000
|
||||
})
|
||||
} as Response;
|
||||
});
|
||||
|
||||
render(<App />);
|
||||
|
||||
expect(await screen.findByRole('heading', { name: '地图态势' })).toBeInTheDocument();
|
||||
expect(screen.getAllByText('数据新鲜').length).toBeGreaterThan(0);
|
||||
expect(screen.getAllByText('更新超时').length).toBeGreaterThan(0);
|
||||
expect(screen.getByText('超时车辆')).toBeInTheDocument();
|
||||
expect(screen.getByText('1 辆超过 5 分钟未更新。')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test('exports current realtime vehicles as CSV', async () => {
|
||||
window.history.replaceState(null, '', '/#/realtime?protocol=JT808');
|
||||
const createObjectURL = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:realtime-export');
|
||||
|
||||
Reference in New Issue
Block a user