feat(platform): add realtime auto refresh controls

This commit is contained in:
lingniu
2026-07-04 17:07:51 +08:00
parent 5ca6b51d0b
commit 34a9def4ff
2 changed files with 93 additions and 1 deletions

View File

@@ -7569,6 +7569,63 @@ test('frames realtime page as one vehicle service with source evidence', async (
expect(screen.getAllByText('2/2 来源在线').length).toBeGreaterThan(0);
});
test('refreshes realtime vehicle data from the monitoring workspace', async () => {
window.history.replaceState(null, '', '/#/realtime');
let realtimeCalls = 0;
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/realtime/vehicles')) {
realtimeCalls += 1;
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: `VIN-REFRESH-${realtimeCalls}`,
plate: `粤A刷新${realtimeCalls}`,
protocols: ['JT808'],
sourceStatus: [{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
primaryProtocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound'
}],
total: 1,
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.findAllByText('粤A刷新1')).length).toBeGreaterThan(0);
expect(screen.getByText('自动刷新 15秒')).toBeInTheDocument();
expect(screen.getByText((content) => content.includes('最后刷新'))).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '刷新实时数据' }));
expect((await screen.findAllByText('粤A刷新2')).length).toBeGreaterThan(0);
expect(realtimeCalls).toBeGreaterThanOrEqual(2);
});
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');