Files
lingniu-vehicle-ingest/vehicle-data-platform/apps/web/src/test/App.test.tsx

8236 lines
283 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { cleanup, fireEvent, render, screen, waitFor } from '@testing-library/react';
import { afterEach, expect, test, vi } from 'vitest';
import App from '../App';
afterEach(() => {
cleanup();
window.history.replaceState(null, '', '/');
vi.restoreAllMocks();
});
test('renders vehicle platform shell', () => {
render(<App />);
expect(screen.getByText('车辆服务中台')).toBeInTheDocument();
expect(screen.getAllByText('总览工作台').length).toBeGreaterThanOrEqual(1);
});
test('shows vehicle service status distribution on dashboard', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [
{ status: 'healthy', title: '服务正常', count: 12 },
{ status: 'degraded', title: '来源不完整', count: 39 }
],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务状态')).toBeInTheDocument();
expect(screen.getByText('来源不完整')).toBeInTheDocument();
expect(screen.getByText('39')).toBeInTheDocument();
});
test('dashboard renders vehicle service summary metrics', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
archiveIncompleteVehicles: 366,
serviceStatuses: [
{ status: 'healthy', title: '服务正常', count: 161 },
{ status: 'degraded', title: '来源不完整', count: 41 }
],
protocols: [
{ protocol: 'JT808', online: 157, total: 388 },
{ protocol: 'YUTONG_MQTT', online: 0, total: 0 }
],
missingSources: [{ protocol: 'YUTONG_MQTT', count: 1033 }],
archiveMissingFields: [{ field: 'phone', title: '缺手机号', count: 353 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('总车辆')).toBeInTheDocument();
expect(screen.getAllByText('1,033').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('单源车辆')).toBeInTheDocument();
expect(screen.getByText('391')).toBeInTheDocument();
expect(screen.getByText('多源车辆')).toBeInTheDocument();
expect(screen.getByText('181')).toBeInTheDocument();
expect(screen.getByText('暂无来源车辆')).toBeInTheDocument();
expect(screen.getByText('461')).toBeInTheDocument();
expect(screen.getByText('身份未绑定')).toBeInTheDocument();
expect(screen.getByText('档案不完整')).toBeInTheDocument();
expect(screen.getByText('366')).toBeInTheDocument();
expect(screen.getByText('来源证据在线分布')).toBeInTheDocument();
expect(screen.getByText('YUTONG_MQTT')).toBeInTheDocument();
expect(screen.getByText('0%')).toBeInTheDocument();
expect(screen.queryByText('NaN%')).not.toBeInTheDocument();
expect(fetchMock).toHaveBeenCalledWith('/api/vehicle-service/summary', undefined);
});
test('dashboard presents one vehicle service operating posture', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
serviceStatuses: [],
protocols: [],
missingSources: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('统一车辆服务')).toBeInTheDocument();
expect(screen.getByText('208 / 1,033 在线')).toBeInTheDocument();
expect(screen.getByText('181 多源覆盖')).toBeInTheDocument();
expect(screen.getByText('7 质量关注')).toBeInTheDocument();
});
test('dashboard exposes vehicle command center map actions', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
serviceStatuses: [],
protocols: [],
missingSources: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: {
items: [
{
vin: 'VIN-COMMAND-001',
plate: '粤A指挥1',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
primaryProtocol: 'GB32960',
sourceCount: 3,
onlineSourceCount: 2,
online: true,
longitude: 113.2,
latitude: 23.1,
speedKmh: 31,
socPercent: 78,
totalMileageKm: 100.5,
lastSeen: '2026-07-03 20:12:10'
},
{
vin: 'VIN-COMMAND-002',
plate: '粤A指挥2',
protocols: ['JT808'],
primaryProtocol: 'JT808',
sourceCount: 3,
onlineSourceCount: 0,
online: false,
longitude: 0,
latitude: 0,
lastSeen: '2026-07-03 19:55:10'
}
],
total: 2,
limit: 8,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{ vin: 'VIN-COMMAND-002', plate: '粤A指挥2', protocol: 'VEHICLE_SERVICE', issueType: 'NO_SOURCE', severity: 'error', detail: '无来源', lastSeen: '2026-07-03 19:55:10' }],
total: 1,
limit: 5,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆态势指挥台')).toBeInTheDocument();
expect(screen.getByText('在线 1 / 2')).toBeInTheDocument();
expect(screen.getByText('有效定位 1')).toBeInTheDocument();
expect(screen.getByText('降级/离线 2')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '处理高优先级告警' }));
expect(window.location.hash).toBe('#/quality?issueType=NO_SOURCE');
cleanup();
window.history.replaceState(null, '', '/#/dashboard');
render(<App />);
expect(await screen.findByText('车辆态势指挥台')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '查看实时态势' }));
expect(window.location.hash).toBe('#/realtime?online=online');
});
test('dashboard shows vehicle service action queue', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
archiveIncompleteVehicles: 366,
serviceStatuses: [],
protocols: [],
missingSources: [{ protocol: 'YUTONG_MQTT', count: 983 }],
archiveMissingFields: [{ field: 'phone', title: '缺手机号', count: 353 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务处置队列')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '确认平台转发 461' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '维护身份绑定 9' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '完善车辆档案 366' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '补齐缺手机号 353' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '补齐 YUTONG_MQTT 来源 983' })).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '补齐缺手机号 353' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/vehicles?archiveMissing=phone');
});
});
test.each([
{ buttonName: '查看在线车辆', expectedHash: '#/vehicles?online=online' },
{ buttonName: '查看多源车辆', expectedHash: '#/vehicles?coverage=multi' },
{ buttonName: '查看质量关注', expectedHash: '#/quality' }
])('dashboard posture opens %s', async ({ buttonName, expectedHash }) => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
serviceStatuses: [],
protocols: [],
missingSources: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: { issueVehicleCount: 7, issueRecordCount: 9, errorCount: 1, warningCount: 8, protocols: [], issueTypes: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: buttonName }));
await waitFor(() => {
expect(window.location.hash).toBe(expectedHash);
});
});
test('dashboard keeps core vehicle service metrics when preview requests fail', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
serviceStatuses: [],
protocols: [],
missingSources: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: false,
status: 500,
json: async () => ({
error: { message: '质量预览失败', detail: 'TDengine timeout' },
traceId: 'trace-quality',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('总车辆')).toBeInTheDocument();
expect(screen.getAllByText('1,033').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('单源车辆')).toBeInTheDocument();
expect(screen.getByText('391')).toBeInTheDocument();
});
test('opens dashboard coverage from missing source distribution', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
serviceStatuses: [],
protocols: [{ protocol: 'YUTONG_MQTT', online: 1, total: 8 }],
missingSources: [{ protocol: 'YUTONG_MQTT', count: 983 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('缺失车辆')).toBeInTheDocument();
expect(screen.getByText('983')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '查看缺 YUTONG_MQTT' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=YUTONG_MQTT'), undefined);
});
expect(screen.getByText('当前筛选:缺 YUTONG_MQTT')).toBeInTheDocument();
});
test('opens vehicle list filtered by service summary KPI', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: { onlineVehicles: 3, activeToday: 4, frameToday: 1286320, issueVehicles: 7, kafkaLag: 0, protocols: [], serviceStatuses: [], linkHealth: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
serviceStatuses: [],
protocols: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: /暂无来源车辆/ }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/coverage?limit=20&offset=0&serviceStatus=no_data'), undefined);
});
expect(window.location.hash).toBe('#/vehicles?serviceStatus=no_data');
});
test('shows vehicle service result summary on vehicle list filters', async () => {
window.history.replaceState(null, '', '/#/vehicles?coverage=multi');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 181,
onlineVehicles: 73,
singleSourceVehicles: 0,
multiSourceVehicles: 181,
noDataVehicles: 4,
unboundVehicles: 9,
archiveIncompleteVehicles: 12,
archiveMissingFields: [{ field: 'phone', title: '缺手机号', count: 7 }],
missingSources: [{ protocol: 'YUTONG_MQTT', count: 181 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [
{
vin: 'VIN-MULTI-001',
plate: '粤A服务1',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
missingProtocols: ['YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'JT808', online: false, lastSeen: '2026-07-03 20:10:00', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '', hasRealtime: false, hasHistory: false, hasRaw: false, hasMileage: false }
],
sourceCount: 2,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '1/2 个来源在线',
sourceCount: 2,
onlineSourceCount: 1
}
},
{
vin: 'VIN-MISSING-ARCHIVE',
plate: '粤A缺项',
phone: '',
oem: '',
protocols: ['JT808'],
missingProtocols: ['GB32960', 'YUTONG_MQTT'],
sourceStatus: [],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-03 20:12:09',
bindingStatus: 'bound'
}
],
total: 181,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前车辆结果')).toBeInTheDocument();
expect(screen.getAllByText('181').length).toBeGreaterThanOrEqual(2);
expect(screen.getByText('过滤车辆')).toBeInTheDocument();
expect(screen.getByText('73')).toBeInTheDocument();
expect(screen.getByText('在线车辆')).toBeInTheDocument();
expect(screen.getByText('单源车辆')).toBeInTheDocument();
expect(screen.getByText('暂无来源车辆')).toBeInTheDocument();
expect(screen.getByText('待绑定')).toBeInTheDocument();
expect(screen.getByText('档案不完整')).toBeInTheDocument();
expect(screen.getAllByText('缺手机号').length).toBeGreaterThanOrEqual(2);
expect(screen.getByText('处置队列')).toBeInTheDocument();
expect(screen.getAllByText('P0').length).toBeGreaterThanOrEqual(2);
expect(screen.getAllByText('P1').length).toBeGreaterThanOrEqual(2);
expect(screen.getByText('已有数据但无法归并到 VIN先补绑定再看跨来源服务。')).toBeInTheDocument();
expect(screen.getByText('车辆没有任何来源证据,优先确认平台转发、端口和订阅配置。')).toBeInTheDocument();
expect(screen.getByText('缺手机号会影响车辆档案检索、绑定确认和运营侧筛选。')).toBeInTheDocument();
expect(screen.getByText('YUTONG_MQTT 来源缺失会降低跨来源定位、里程和实时判断可信度。')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '维护身份绑定 9' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '确认平台转发 4' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '补齐缺手机号 7' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '补齐 YUTONG_MQTT 来源 181' })).toBeInTheDocument();
expect(screen.getByText('档案完整度')).toBeInTheDocument();
expect(screen.getByText('4/4')).toBeInTheDocument();
expect(screen.getByText('2/4')).toBeInTheDocument();
expect(screen.getByText('缺OEM')).toBeInTheDocument();
expect(screen.getByText('VIN-MULTI-001')).toBeInTheDocument();
expect(screen.getByText('VIN-MISSING-ARCHIVE')).toBeInTheDocument();
expect(screen.getAllByText('来源证据').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('GB32960 在线')).toBeInTheDocument();
expect(screen.getAllByText('JT808 离线').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('YUTONG_MQTT 未接入')).toBeInTheDocument();
expect(screen.getByText('1/2 来源在线')).toBeInTheDocument();
expect(screen.getByText('1/2 来源在线,缺 YUTONG_MQTT')).toBeInTheDocument();
expect(screen.getByText('建议动作')).toBeInTheDocument();
expect(screen.getByText('补齐 YUTONG_MQTT 来源')).toBeInTheDocument();
});
test('exports current vehicle coverage page as csv', async () => {
window.history.replaceState(null, '', '/#/vehicles?missingProtocol=YUTONG_MQTT');
const createObjectURL = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:vehicle-coverage');
const revokeObjectURL = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined);
vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => undefined);
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1,
onlineVehicles: 1,
singleSourceVehicles: 1,
multiSourceVehicles: 0,
noDataVehicles: 0,
unboundVehicles: 0,
archiveIncompleteVehicles: 0,
archiveMissingFields: [],
missingSources: [{ protocol: 'YUTONG_MQTT', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-EXPORT-VEHICLE',
plate: '粤A车辆导出',
phone: '13307795425',
oem: 'G7s',
protocols: ['JT808'],
missingProtocols: ['YUTONG_MQTT'],
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,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: { status: 'degraded', severity: 'warning', title: '来源不完整', detail: '缺少 YUTONG_MQTT', sourceCount: 1, onlineSourceCount: 1 },
sourceConsistency: { sourceCount: 1, onlineSourceCount: 1, locatedSourceCount: 1, missingProtocols: ['YUTONG_MQTT'], mileageDeltaKm: 0, sourceTimeDeltaSeconds: 0, scope: 'overview', status: 'degraded', severity: 'warning', title: '来源不完整', detail: '缺少 YUTONG_MQTT' }
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-EXPORT-VEHICLE')).toBeInTheDocument();
expect(screen.getByText('当前页 1 辆')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '导出车辆当前页 CSV' }));
expect(createObjectURL).toHaveBeenCalled();
expect(revokeObjectURL).toHaveBeenCalledWith('blob:vehicle-coverage');
});
test('filters vehicle list from recommended action', async () => {
window.history.replaceState(null, '', '/#/vehicles');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 181,
onlineVehicles: 73,
singleSourceVehicles: 0,
multiSourceVehicles: 181,
noDataVehicles: 0,
unboundVehicles: 0,
missingSources: [{ protocol: 'YUTONG_MQTT', count: 181 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-MISSING-MQTT',
plate: '粤A服务2',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
missingProtocols: ['YUTONG_MQTT'],
sourceStatus: [],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound'
}],
total: 181,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '补齐 YUTONG_MQTT 来源' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/coverage?limit=20&offset=0&missingProtocol=YUTONG_MQTT'), undefined);
});
expect(window.location.hash).toBe('#/vehicles?missingProtocol=YUTONG_MQTT');
});
test('filters vehicle list from action queue', async () => {
window.history.replaceState(null, '', '/#/vehicles');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 181,
onlineVehicles: 73,
singleSourceVehicles: 0,
multiSourceVehicles: 181,
noDataVehicles: 4,
unboundVehicles: 9,
missingSources: [{ protocol: 'YUTONG_MQTT', count: 181 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '确认平台转发 4' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/coverage?limit=20&offset=0&serviceStatus=no_data'), undefined);
});
expect(window.location.hash).toBe('#/vehicles?serviceStatus=no_data');
});
test('shows and clears current vehicle service filters', async () => {
window.history.replaceState(null, '', '/#/vehicles?keyword=%E7%B2%A4A&protocol=JT808&coverage=multi&missingProtocol=YUTONG_MQTT&serviceStatus=degraded&online=online&bindingStatus=bound&archiveStatus=incomplete');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1,
onlineVehicles: 1,
singleSourceVehicles: 0,
multiSourceVehicles: 1,
noDataVehicles: 0,
unboundVehicles: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 1, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前车辆筛选')).toBeInTheDocument();
expect(screen.getByText('关键词粤A')).toBeInTheDocument();
expect(screen.getByText('数据来源JT808')).toBeInTheDocument();
expect(screen.getByText('来源覆盖:多源')).toBeInTheDocument();
expect(screen.getByText('缺失来源YUTONG_MQTT')).toBeInTheDocument();
expect(screen.getByText('服务状态:来源不完整')).toBeInTheDocument();
expect(screen.getByText('在线:在线')).toBeInTheDocument();
expect(screen.getByText('绑定:已绑定')).toBeInTheDocument();
expect(screen.getByText('档案:不完整')).toBeInTheDocument();
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('archiveStatus=incomplete'), undefined);
});
fireEvent.click(screen.getByRole('button', { name: '清空筛选' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/coverage?limit=20&offset=0'), undefined);
});
expect(window.location.hash).toBe('#/vehicles');
});
test('filters vehicle list from result summary actions', async () => {
window.history.replaceState(null, '', '/#/vehicles');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: path.includes('online=online') ? 73 : 181,
onlineVehicles: 73,
singleSourceVehicles: 108,
multiSourceVehicles: 73,
unboundVehicles: 9
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [],
total: path.includes('online=online') ? 73 : 181,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: /在线车辆 73/ }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/coverage?limit=20&offset=0&online=online'), undefined);
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/coverage/summary?online=online'), undefined);
expect(window.location.hash).toBe('#/vehicles?online=online');
});
test('filters vehicle list by missing source evidence', async () => {
window.history.replaceState(null, '', '/#/vehicles');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1,
onlineVehicles: 0,
singleSourceVehicles: 0,
multiSourceVehicles: 1,
noDataVehicles: 0,
unboundVehicles: 0,
missingSources: [{ protocol: 'YUTONG_MQTT', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
missingProtocols: ['YUTONG_MQTT'],
sourceCount: 2,
onlineSourceCount: 0,
online: false,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
await waitFor(() => {
expect(screen.getAllByText('缺失来源').length).toBeGreaterThanOrEqual(2);
});
expect(screen.getAllByText('缺 YUTONG_MQTT').length).toBeGreaterThanOrEqual(1);
fireEvent.click(screen.getByRole('button', { name: '缺 YUTONG_MQTT 1' }));
expect(window.location.hash).toBe('#/vehicles?missingProtocol=YUTONG_MQTT');
fireEvent.click(screen.getByRole('button', { name: '缺 YUTONG_MQTT' }));
expect(window.location.hash).toBe('#/vehicles?missingProtocol=YUTONG_MQTT');
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=YUTONG_MQTT'), undefined);
});
fireEvent.click(screen.getByTestId('missing-protocol-filter'));
const mqttOptions = await screen.findAllByText('缺 YUTONG_MQTT');
fireEvent.click(mqttOptions[mqttOptions.length - 1]);
fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=YUTONG_MQTT'), undefined);
});
});
test('copies shareable vehicle service filter link', async () => {
window.history.replaceState(null, '', '/#/vehicles?keyword=%E7%B2%A4A&coverage=multi&serviceStatus=degraded');
const writeText = vi.fn(() => Promise.resolve());
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText }
});
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 181,
onlineVehicles: 73,
singleSourceVehicles: 0,
multiSourceVehicles: 181,
noDataVehicles: 12,
unboundVehicles: 9
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 181, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: /复制筛选链接/ }));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('/#/vehicles?keyword=%E7%B2%A4A&coverage=multi&serviceStatus=degraded'));
});
test('shows resolved vehicle service status after topbar search', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: { onlineVehicles: 3, activeToday: 4, frameToday: 1286320, issueVehicles: 7, kafkaLag: 0, protocols: [], serviceStatuses: [], linkHealth: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'LB9A32A24R0LS1426',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
primaryProtocol: 'JT808',
coverageStatus: 'partial',
sourceCount: 2,
onlineSourceCount: 1,
lastSeen: '2026-07-03 20:12:10',
realtimeCount: 2,
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 0,
sourceConsistency: {
sourceCount: 2,
onlineSourceCount: 1,
locatedSourceCount: 2,
missingProtocols: ['YUTONG_MQTT'],
mileageDeltaKm: 0,
sourceTimeDeltaSeconds: 0,
scope: 'all_sources',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '1/2 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。'
}
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'LB9A32A24R0LS1426',
lookupKey: 'LB9A32A24R0LS1426',
lookupResolved: true,
sources: ['GB32960', 'JT808'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.change(screen.getByPlaceholderText('搜索 VIN / 车牌 / 手机号'), { target: { value: '粤AG18312' } });
fireEvent.click(screen.getByRole('button', { name: '查询车辆' }));
expect(await screen.findByText('当前车辆:来源不完整')).toBeInTheDocument();
expect(screen.getByText('粤AG18312 / LB9A32A24R0LS1426')).toBeInTheDocument();
expect(screen.getByText('一致性:来源不完整')).toBeInTheDocument();
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=%E7%B2%A4AG18312'), undefined);
expect(fetchMock).not.toHaveBeenCalledWith(expect.stringContaining('/api/vehicles/resolve'), undefined);
});
test('shows row service status in dashboard vehicle previews', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-COVERAGE-WARN',
plate: '粤A预警1',
phone: '',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
missingProtocols: ['YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'JT808', online: false, lastSeen: '2026-07-03 20:10:00', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '', hasRealtime: false, hasHistory: false, hasRaw: false, hasMileage: false }
],
sourceCount: 2,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '覆盖部分离线',
detail: '覆盖预览由 API 判定',
sourceCount: 2,
onlineSourceCount: 1
}
}],
total: 1,
limit: 8,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-REALTIME-OFFLINE',
plate: '粤A离线1',
phone: '',
oem: 'G7s',
protocols: ['JT808'],
sourceCount: 1,
onlineSourceCount: 0,
online: false,
bindingStatus: 'bound',
serviceStatus: {
status: 'offline',
severity: 'error',
title: '实时车辆离线',
detail: '实时预览由 API 判定',
sourceCount: 1,
onlineSourceCount: 0
},
primaryProtocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 0,
socPercent: 0,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
}],
total: 1,
limit: 8,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-COVERAGE-WARN')).toBeInTheDocument();
expect(screen.getAllByText('来源证据').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('GB32960 在线')).toBeInTheDocument();
expect(screen.getByText('JT808 离线')).toBeInTheDocument();
expect(screen.getByText('YUTONG_MQTT 未接入')).toBeInTheDocument();
expect(screen.getAllByText('1/2 来源在线').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('覆盖部分离线')).toBeInTheDocument();
expect(screen.getByText('VIN-REALTIME-OFFLINE')).toBeInTheDocument();
expect(screen.getByText('实时车辆离线')).toBeInTheDocument();
});
test('filters dashboard coverage from source consistency diagnosis', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1,
boundVehicles: 1,
onlineVehicles: 1,
singleSourceVehicles: 1,
multiSourceVehicles: 0,
noDataVehicles: 0,
identityRequiredVehicles: 0,
serviceStatuses: [],
protocols: [],
missingSources: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-DASH-SINGLE',
plate: '粤A总览',
phone: '',
oem: '',
protocols: ['GB32960'],
missingProtocols: ['JT808', 'YUTONG_MQTT'],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-04 07:15:28',
bindingStatus: 'bound',
sourceConsistency: {
sourceCount: 1,
onlineSourceCount: 1,
locatedSourceCount: 0,
missingProtocols: ['JT808', 'YUTONG_MQTT'],
mileageDeltaKm: 0,
sourceTimeDeltaSeconds: 0,
scope: 'coverage',
status: 'single_source',
severity: 'warning',
title: '单一来源',
detail: '当前车辆只有一个数据来源,无法做跨来源一致性校验。'
}
}],
total: 1,
limit: 8,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-DASH-SINGLE')).toBeInTheDocument();
expect(screen.getByText('来源一致性')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '单一来源' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('serviceStatus=degraded'), undefined);
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=JT808'), undefined);
expect(screen.getByText('当前筛选:来源不完整 / 缺 JT808')).toBeInTheDocument();
});
test('opens full vehicle service list from dashboard coverage filters', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1,
boundVehicles: 1,
onlineVehicles: 1,
singleSourceVehicles: 1,
multiSourceVehicles: 0,
noDataVehicles: 0,
identityRequiredVehicles: 0,
serviceStatuses: [],
protocols: [],
missingSources: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-DASH-FULL-LIST',
plate: '粤A全量',
phone: '',
oem: '',
protocols: ['GB32960'],
missingProtocols: ['JT808', 'YUTONG_MQTT'],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-04 07:20:14',
bindingStatus: 'bound',
sourceConsistency: {
sourceCount: 1,
onlineSourceCount: 1,
locatedSourceCount: 0,
missingProtocols: ['JT808', 'YUTONG_MQTT'],
mileageDeltaKm: 0,
sourceTimeDeltaSeconds: 0,
scope: 'coverage',
status: 'single_source',
severity: 'warning',
title: '单一来源',
detail: '当前车辆只有一个数据来源,无法做跨来源一致性校验。'
}
}],
total: 1,
limit: path.includes('limit=20') ? 20 : 8,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-DASH-FULL-LIST')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '单一来源' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=JT808'), undefined);
});
fireEvent.click(screen.getByRole('button', { name: '查看全部车辆' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/vehicles?serviceStatus=degraded&missingProtocol=JT808');
});
const vehicleCoverageCall = fetchMock.mock.calls.find(([input]) => String(input).startsWith('/api/vehicles/coverage?limit=20&offset=0'));
expect(vehicleCoverageCall).toBeTruthy();
const vehicleCoverageParams = new URLSearchParams(String(vehicleCoverageCall?.[0]).split('?')[1]);
expect(vehicleCoverageParams.get('serviceStatus')).toBe('degraded');
expect(vehicleCoverageParams.get('missingProtocol')).toBe('JT808');
});
test('opens vehicle service from dashboard realtime preview with source evidence', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: { onlineVehicles: 1, activeToday: 1, frameToday: 10, issueVehicles: 0, kafkaLag: 0, protocols: [], serviceStatuses: [], linkHealth: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: { totalVehicles: 1, boundVehicles: 1, onlineVehicles: 1, singleSourceVehicles: 1, multiSourceVehicles: 0, noDataVehicles: 0, identityRequiredVehicles: 0, serviceStatuses: [], protocols: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-DASH-RT',
plate: '粤A实时1',
phone: '',
oem: 'G7s',
protocols: ['JT808'],
primaryProtocol: 'JT808',
sourceCount: 1,
onlineSourceCount: 1,
online: true,
bindingStatus: 'bound',
longitude: 113.2,
latitude: 23.1,
speedKmh: 12,
socPercent: 80,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
}],
total: 1,
limit: 8,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-DASH-RT',
plate: '粤A实时1',
sourceCount: 1,
onlineSourceCount: 1,
coverageStatus: 'online',
primaryProtocol: 'JT808',
lastSeen: '2026-07-03 20:12:10',
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-DASH-RT')).toBeInTheDocument();
const vehicleButtons = screen.getAllByRole('button', { name: '车辆服务' });
fireEvent.click(vehicleButtons[vehicleButtons.length - 1]);
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-DASH-RT&protocol=JT808');
});
});
test('opens vehicle service from dashboard quality preview with issue source evidence', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: { onlineVehicles: 1, activeToday: 1, frameToday: 10, issueVehicles: 1, kafkaLag: 0, protocols: [], serviceStatuses: [], linkHealth: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: '',
plate: '粤A质量1',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'VIN_MISSING',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 数据缺少 VIN 映射'
}],
total: 1,
limit: 5,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-DASH-QUALITY',
plate: '粤A质量1',
sourceCount: 1,
onlineSourceCount: 1,
coverageStatus: 'online',
primaryProtocol: 'JT808',
lastSeen: '2026-07-03 20:12:10',
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 1
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/vehicle-service/summary')
? { totalVehicles: 1, boundVehicles: 1, onlineVehicles: 1, singleSourceVehicles: 1, multiSourceVehicles: 0, noDataVehicles: 0, identityRequiredVehicles: 0, serviceStatuses: [], protocols: [] }
: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('13307795425')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '按车牌查车' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-DASH-QUALITY&protocol=JT808');
});
});
test('filters dashboard coverage by service status', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务覆盖')).toBeInTheDocument();
fireEvent.click(screen.getByTestId('dashboard-service-status-filter'));
fireEvent.click(await screen.findByText('来源不完整'));
fireEvent.click(screen.getByRole('button', { name: '筛选' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('serviceStatus=degraded'), undefined);
});
expect(screen.getByText('当前筛选:来源不完整')).toBeInTheDocument();
});
test('filters dashboard coverage by missing source evidence', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务覆盖')).toBeInTheDocument();
fireEvent.click(screen.getByTestId('dashboard-missing-protocol-filter'));
fireEvent.click(await screen.findByText('缺 YUTONG_MQTT'));
fireEvent.click(screen.getByRole('button', { name: '筛选' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=YUTONG_MQTT'), undefined);
});
expect(screen.getByText('当前筛选:缺 YUTONG_MQTT')).toBeInTheDocument();
});
test('opens dashboard coverage from service status distribution', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [
{ status: 'degraded', title: '来源不完整', count: 39 }
],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '查看来源不完整' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('serviceStatus=degraded'), undefined);
});
});
test('renders quality issues as vehicle-service governance labels', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 0,
warningCount: 1,
protocols: [{ name: 'VEHICLE_SERVICE', count: 1 }],
issueTypes: [{ name: 'NO_SOURCE', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-NO-SOURCE-001',
plate: '粤A无源1',
phone: '13300000002',
sourceEndpoint: 'vehicle_identity_binding',
protocol: 'VEHICLE_SERVICE',
issueType: 'NO_SOURCE',
severity: 'warning',
lastSeen: '',
detail: '车辆已绑定,但暂无 32960、808 或 MQTT 数据来源'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-NO-SOURCE-001')).toBeInTheDocument();
expect(screen.getAllByText('暂无数据来源').length).toBeGreaterThanOrEqual(1);
expect(screen.getAllByText('车辆服务').length).toBeGreaterThanOrEqual(1);
expect(screen.getAllByText('确认平台转发').length).toBeGreaterThan(0);
expect(screen.getByText('车辆已绑定但没有任何来源证据,先确认平台转发、端口和订阅。')).toBeInTheDocument();
});
test('shows alert rule and notification policy workspace on quality page', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: {
linkHealth: [{ name: 'tdengine', status: 'error', detail: 'write unavailable' }],
kafkaLag: 42,
activeConnections: 120000,
capacityFindings: ['kafka lag 42'],
redisOnlineKeys: 368,
tdengineWritable: false,
mysqlWritable: true,
runtime: { requestTimeoutMs: 5000 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 3,
issueRecordCount: 5,
errorCount: 1,
warningCount: 4,
protocols: [{ name: 'VEHICLE_SERVICE', count: 3 }],
issueTypes: [
{ name: 'NO_SOURCE', count: 2 },
{ name: 'VIN_MISSING', count: 1 },
{ name: 'FIELD_MISSING', count: 2 }
]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [],
total: 0,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('告警触发规则')).toBeInTheDocument();
expect(screen.getByText('4 类活跃')).toBeInTheDocument();
expect(screen.getByText('3 类 P0')).toBeInTheDocument();
expect(screen.getByText('容量与存储风险')).toBeInTheDocument();
expect(screen.getByText('15 分钟恢复')).toBeInTheDocument();
expect(screen.getByText('通知策略')).toBeInTheDocument();
expect(screen.getByText('P0 实时中断')).toBeInTheDocument();
expect(screen.getByText('接入运维 + 业务责任人')).toBeInTheDocument();
expect(screen.getByText('站内告警 / 邮件 / 企业微信')).toBeInTheDocument();
});
test('shows actionable priority queue on quality page', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 120000, capacityFindings: [], redisOnlineKeys: 368, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 2,
issueRecordCount: 2,
errorCount: 1,
warningCount: 1,
protocols: [{ name: 'VEHICLE_SERVICE', count: 1 }, { name: 'JT808', count: 1 }],
issueTypes: [{ name: 'NO_SOURCE', count: 1 }, { name: 'VIN_MISSING', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [
{
vin: 'VIN-P0-001',
plate: '粤A优先1',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'VEHICLE_SERVICE',
issueType: 'NO_SOURCE',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: '车辆无任何来源'
},
{
vin: '',
plate: '粤A优先2',
phone: '13307795426',
sourceEndpoint: '115.231.168.135:43626',
protocol: 'JT808',
issueType: 'VIN_MISSING',
severity: 'warning',
lastSeen: '2026-07-03 20:10:10',
detail: '手机号未映射 VIN'
}
],
total: 2,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-P0-001',
plate: '粤A优先1',
sourceCount: 0,
onlineSourceCount: 0,
coverageStatus: 'no_data',
primaryProtocol: 'VEHICLE_SERVICE',
lastSeen: '2026-07-03 20:12:10',
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 1
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('处置优先队列')).toBeInTheDocument();
expect(screen.getAllByText('P0').length).toBeGreaterThan(0);
expect(screen.getByText('粤A优先1 / VIN-P0-001')).toBeInTheDocument();
expect(screen.getAllByText('确认平台转发').length).toBeGreaterThan(0);
expect(screen.getAllByText('30 分钟确认').length).toBeGreaterThan(0);
expect(screen.getAllByText('P1').length).toBeGreaterThan(0);
expect(screen.getByText('粤A优先2 / 13307795426')).toBeInTheDocument();
fireEvent.click(screen.getAllByRole('button', { name: '进入车辆服务' })[0]);
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-P0-001&protocol=VEHICLE_SERVICE');
});
});
test('copies notification text from quality priority queue', async () => {
window.history.replaceState(null, '', '/#/quality');
const writeText = vi.fn(() => Promise.resolve());
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText }
});
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 120000, capacityFindings: [], redisOnlineKeys: 368, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 1,
warningCount: 0,
protocols: [{ name: 'JT808', count: 1 }],
issueTypes: [{ name: 'VIN_MISSING', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: '',
plate: '粤A通知1',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'VIN_MISSING',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: '手机号未映射 VIN需要维护 binding'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('处置优先队列')).toBeInTheDocument();
fireEvent.click(await screen.findByRole('button', { name: '复制通知' }));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('【P0 告警通知】'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('车辆粤A通知1 / 13307795425'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('问题VIN 缺失'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('SLA2 小时修复'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('最后时间2026-07-03 20:12:10'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('详情:手机号未映射 VIN需要维护 binding'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('实时定位http://localhost:3000/#/realtime?keyword=%E7%B2%A4A%E9%80%9A%E7%9F%A51&protocol=JT808'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('轨迹证据http://localhost:3000/#/history?keyword=%E7%B2%A4A%E9%80%9A%E7%9F%A51&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('RAW证据http://localhost:3000/#/history?keyword=%E7%B2%A4A%E9%80%9A%E7%9F%A51&protocol=JT808&tab=raw&dateFrom=2026-07-03&dateTo=2026-07-04&includeFields=true'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('车辆服务http://localhost:3000/#/detail?keyword=%E7%B2%A4A%E9%80%9A%E7%9F%A51&protocol=JT808'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('告警筛选http://localhost:3000/#/quality'));
});
test('opens realtime map context from quality priority queue', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 120000, capacityFindings: [], redisOnlineKeys: 368, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 1,
warningCount: 0,
protocols: [{ name: 'JT808', count: 1 }],
issueTypes: [{ name: 'LINK_GAP', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-ALERT-MAP',
plate: '粤A地图告警',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'LINK_GAP',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 来源间断,需要定位当前车辆'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/realtime/locations')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-ALERT-MAP',
plate: '粤A地图告警',
primaryProtocol: 'JT808',
longitude: 113.24567,
latitude: 23.12345,
online: true,
sourceCount: 1,
onlineSourceCount: 1,
lastSeen: '2026-07-03 20:12:11'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('处置优先队列')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '实时定位' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/realtime?keyword=VIN-ALERT-MAP&protocol=JT808');
});
expect(await screen.findByRole('heading', { name: '实时监控' })).toBeInTheDocument();
});
test('opens same-day trajectory evidence from quality priority queue', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 120000, capacityFindings: [], redisOnlineKeys: 368, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 1,
warningCount: 0,
protocols: [{ name: 'GB32960', count: 1 }],
issueTypes: [{ name: 'FIELD_MISSING', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-ALERT-TRACK',
plate: '粤A轨迹告警',
phone: '13307795425',
sourceEndpoint: '115.29.187.205:32960',
protocol: 'GB32960',
issueType: 'FIELD_MISSING',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: 'GB32960 位置字段缺失,需要核对轨迹'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/locations') || path.includes('/api/history/raw-frames')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('处置优先队列')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '轨迹证据' }));
await waitFor(() => {
expect(window.location.hash.startsWith('#/history?')).toBe(true);
});
const params = new URLSearchParams(window.location.hash.slice('#/history?'.length));
expect(params.get('keyword')).toBe('VIN-ALERT-TRACK');
expect(params.get('protocol')).toBe('GB32960');
expect(params.get('dateFrom')).toBe('2026-07-03');
expect(params.get('dateTo')).toBe('2026-07-04');
expect(params.get('tab')).toBeNull();
expect(await screen.findByRole('heading', { name: '轨迹回放' })).toBeInTheDocument();
});
test('opens same-day raw evidence from quality priority queue', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 120000, capacityFindings: [], redisOnlineKeys: 368, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 1,
warningCount: 0,
protocols: [{ name: 'JT808', count: 1 }],
issueTypes: [{ name: 'LINK_GAP', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-ALERT-RAW',
plate: '粤ARAW告警',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'LINK_GAP',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 来源间断,需要核对 RAW'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/locations') || path.includes('/api/history/raw-frames')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('处置优先队列')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: 'RAW证据' }));
await waitFor(() => {
expect(window.location.hash.startsWith('#/history?')).toBe(true);
});
const params = new URLSearchParams(window.location.hash.slice('#/history?'.length));
expect(params.get('keyword')).toBe('VIN-ALERT-RAW');
expect(params.get('protocol')).toBe('JT808');
expect(params.get('dateFrom')).toBe('2026-07-03');
expect(params.get('dateTo')).toBe('2026-07-04');
expect(params.get('includeFields')).toBe('true');
expect(params.get('tab')).toBe('raw');
expect(await screen.findByRole('heading', { name: '轨迹回放' })).toBeInTheDocument();
});
test('opens vehicle service from quality issue with issue source evidence', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 1,
warningCount: 0,
protocols: [{ name: 'JT808', count: 1 }],
issueTypes: [{ name: 'VIN_MISSING', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: '',
plate: '粤AG18312',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'VIN_MISSING',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 数据缺少 VIN 映射'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-JT808-QUALITY',
plate: '粤AG18312',
sourceCount: 1,
onlineSourceCount: 1,
coverageStatus: 'online',
primaryProtocol: 'JT808',
lastSeen: '2026-07-03 20:12:10',
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 1
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('13307795425')).toBeInTheDocument();
expect(screen.getAllByText('维护身份绑定').length).toBeGreaterThan(0);
expect(screen.getByText('数据已有来源但无法归并到 VIN优先用车牌/手机号补齐绑定。')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '按车牌查车' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-JT808-QUALITY&protocol=JT808');
});
});
test('opens same-day history evidence from quality issue row', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 0,
warningCount: 1,
protocols: [{ name: 'JT808', count: 1 }],
issueTypes: [{ name: 'LINK_GAP', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-QUALITY-HISTORY',
plate: '粤A告警证',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'LINK_GAP',
severity: 'warning',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 来源存在上报间断'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-QUALITY-HISTORY')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '核对历史' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/history?keyword=VIN-QUALITY-HISTORY&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04');
});
});
test('opens same-day raw evidence from quality issue row', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 0,
warningCount: 1,
protocols: [{ name: 'GB32960', count: 1 }],
issueTypes: [{ name: 'FIELD_MISSING', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-QUALITY-RAW',
plate: '粤A告警RAW',
phone: '',
sourceEndpoint: '115.29.187.205:32960',
protocol: 'GB32960',
issueType: 'FIELD_MISSING',
severity: 'warning',
lastSeen: '2026-07-03 20:12:10',
detail: 'GB32960 实时帧缺少氢耗字段'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/locations') || path.includes('/api/history/raw-frames')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-QUALITY-RAW')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '核对 RAW' }));
await waitFor(() => {
expect(window.location.hash.startsWith('#/history?')).toBe(true);
});
const params = new URLSearchParams(window.location.hash.slice('#/history?'.length));
expect(params.get('keyword')).toBe('VIN-QUALITY-RAW');
expect(params.get('protocol')).toBe('GB32960');
expect(params.get('dateFrom')).toBe('2026-07-03');
expect(params.get('dateTo')).toBe('2026-07-04');
expect(params.get('includeFields')).toBe('true');
expect(params.get('tab')).toBe('raw');
expect(await screen.findByRole('heading', { name: '轨迹回放' })).toBeInTheDocument();
});
test('opens same-day mileage statistics from quality issue row', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 0,
warningCount: 1,
protocols: [{ name: 'JT808', count: 1 }],
issueTypes: [{ name: 'FIELD_MISSING', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-QUALITY-MILEAGE',
plate: '粤A告警里',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'FIELD_MISSING',
severity: 'warning',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 位置帧缺少总里程字段'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 18.8, averageMileagePerVin: 18.8 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-QUALITY-MILEAGE',
plate: '粤A告警里',
source: 'JT808',
date: '2026-07-03',
startMileageKm: 200,
endMileageKm: 218.8,
dailyMileageKm: 18.8,
anomalySeverity: 'warning'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-QUALITY-MILEAGE')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '核对里程' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/mileage?keyword=VIN-QUALITY-MILEAGE&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04');
});
});
test('drills into quality issues by issue type', async () => {
window.history.replaceState(null, '', '/#/quality');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 0,
warningCount: 1,
protocols: [{ name: 'VEHICLE_SERVICE', count: 1 }],
issueTypes: [{ name: 'NO_SOURCE', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: /主要问题 暂无数据来源 1/ }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/issues?issueType=NO_SOURCE&limit=20&offset=0'), undefined);
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/summary?issueType=NO_SOURCE'), undefined);
});
test('drills into quality issues by protocol bucket', async () => {
window.history.replaceState(null, '', '/#/quality');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 2,
issueRecordCount: 3,
errorCount: 1,
warningCount: 2,
protocols: [
{ name: 'JT808', count: 2 },
{ name: 'VEHICLE_SERVICE', count: 1 }
],
issueTypes: [{ name: 'VIN_MISSING', count: 2 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [],
total: 3,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '查看 JT808 质量问题' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/issues?protocol=JT808&limit=20&offset=0'), undefined);
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/summary?protocol=JT808'), undefined);
expect(window.location.hash).toBe('#/quality?protocol=JT808');
});
test('drills into quality issues by issue type bucket', async () => {
window.history.replaceState(null, '', '/#/quality');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 2,
issueRecordCount: 4,
errorCount: 2,
warningCount: 2,
protocols: [{ name: 'JT808', count: 4 }],
issueTypes: [
{ name: 'VIN_MISSING', count: 2 },
{ name: 'LINK_GAP', count: 2 }
]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [],
total: 4,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '查看 VIN 缺失质量问题' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/issues?issueType=VIN_MISSING&limit=20&offset=0'), undefined);
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/summary?issueType=VIN_MISSING'), undefined);
expect(window.location.hash).toBe('#/quality?issueType=VIN_MISSING');
});
test('applies shareable quality filters from hash', async () => {
window.history.replaceState(null, '', '/#/quality?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 0,
warningCount: 1,
protocols: [{ name: 'VEHICLE_SERVICE', count: 1 }],
issueTypes: [{ name: 'NO_SOURCE', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 1, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/issues?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE&limit=20&offset=0'), undefined);
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/summary?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE'), undefined);
});
test('shows and clears current quality filters', async () => {
window.history.replaceState(null, '', '/#/quality?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 0,
warningCount: 1,
protocols: [{ name: 'VEHICLE_SERVICE', count: 1 }],
issueTypes: [{ name: 'NO_SOURCE', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 1, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前筛选')).toBeInTheDocument();
expect(screen.getByText('关键词粤A')).toBeInTheDocument();
expect(screen.getByText('数据来源:车辆服务')).toBeInTheDocument();
expect(screen.getByText('问题类型:暂无数据来源')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '清空筛选' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/issues?limit=20&offset=0'), undefined);
});
expect(window.location.hash).toBe('#/quality');
});
test('copies shareable quality filter link', async () => {
window.history.replaceState(null, '', '/#/quality?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE');
const writeText = vi.fn().mockResolvedValue(undefined);
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText }
});
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 0,
warningCount: 1,
protocols: [{ name: 'VEHICLE_SERVICE', count: 1 }],
issueTypes: [{ name: 'NO_SOURCE', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 1, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: /复制筛选链接/ }));
await waitFor(() => {
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('/#/quality?keyword=%E7%B2%A4A&protocol=VEHICLE_SERVICE&issueType=NO_SOURCE'));
});
});
test('opens vehicle detail from shareable hash', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=%E7%B2%A4AG18312');
vi.spyOn(globalThis, 'fetch').mockResolvedValue({
ok: true,
json: async () => ({
data: {
vin: 'LB9A32A24R0LS1426',
lookupKey: '粤AG18312',
lookupResolved: true,
resolution: {
lookupKey: '粤AG18312',
resolved: true,
vin: 'LB9A32A24R0LS1426',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
sources: ['GB32960', 'JT808'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response);
render(<App />);
expect(await screen.findByDisplayValue('粤AG18312')).toBeInTheDocument();
expect(screen.getAllByText('车辆服务').length).toBeGreaterThanOrEqual(1);
});
test('shows vehicle context when opening detail from shareable hash', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
primaryProtocol: 'JT808',
coverageStatus: 'partial',
sourceCount: 2,
onlineSourceCount: 1,
lastSeen: '2026-07-03 20:12:10',
realtimeCount: 2,
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
sources: ['GB32960', 'JT808'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('粤AG18312 / VIN001')).toBeInTheDocument();
expect(screen.getByText('当前车辆:来源不完整')).toBeInTheDocument();
});
test('refreshes vehicle context when hash changes to another detail vehicle', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN002',
plate: '粤B20002',
phone: '',
oem: 'G7s',
protocols: ['JT808'],
primaryProtocol: 'JT808',
coverageStatus: 'offline',
sourceCount: 1,
onlineSourceCount: 0,
lastSeen: '2026-07-03 20:10:10',
realtimeCount: 1,
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: { onlineVehicles: 3, activeToday: 4, frameToday: 1286320, issueVehicles: 7, kafkaLag: 0, protocols: [], serviceStatuses: [], linkHealth: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN002',
lookupKey: 'VIN002',
lookupResolved: true,
sources: ['JT808'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
window.history.pushState(null, '', '/#/detail?keyword=VIN002');
window.dispatchEvent(new HashChangeEvent('hashchange'));
expect(await screen.findByText('粤B20002 / VIN002')).toBeInTheDocument();
expect(screen.getByText('当前车辆:车辆离线')).toBeInTheDocument();
});
test('shows vehicle context when opening detail from sidebar navigation', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'LB9A32A24R0LS1426',
plate: '粤AGQ8398',
phone: '',
oem: 'G7s',
protocols: ['JT808'],
primaryProtocol: 'JT808',
coverageStatus: 'offline',
sourceCount: 1,
onlineSourceCount: 0,
lastSeen: '2026-07-03 20:10:10',
realtimeCount: 1,
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: { onlineVehicles: 3, activeToday: 4, frameToday: 1286320, issueVehicles: 7, kafkaLag: 0, protocols: [], serviceStatuses: [], linkHealth: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'LB9A32A24R0LS1426',
lookupKey: 'LB9A32A24R0LS1426',
lookupResolved: true,
sources: ['JT808'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(screen.getAllByText('车辆档案')[0]);
expect(await screen.findByText('粤AGQ8398 / LB9A32A24R0LS1426')).toBeInTheDocument();
expect(screen.getByText('当前车辆:车辆离线')).toBeInTheDocument();
});
test('applies protocol from shareable history hash to API requests', async () => {
window.history.replaceState(null, '', '/#/history?keyword=%E7%B2%A4AG18312&protocol=JT808');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/history/locations?'), undefined);
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('protocol=JT808'), undefined);
expect(fetchMock).toHaveBeenCalledWith('/api/history/raw-frames/query', expect.objectContaining({
method: 'POST',
body: expect.stringContaining('"protocol":"JT808"')
}));
expect(screen.getByText('当前车辆粤AG18312')).toBeInTheDocument();
expect(screen.getByText('当前来源JT808')).toBeInTheDocument();
});
test('shows and clears current history filters while keeping vehicle scope', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-HISTORY-001&protocol=JT808&dateFrom=2026-07-01+00%3A00%3A00&dateTo=2026-07-01+23%3A59%3A59&includeFields=true&fields=jt808.location.longitude%2Cjt808.location.latitude&tab=raw');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/raw-frames/query')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前历史筛选')).toBeInTheDocument();
expect(screen.getByText('车辆VIN-HISTORY-001')).toBeInTheDocument();
expect(screen.getByText('数据来源JT808')).toBeInTheDocument();
expect(screen.getByText('开始时间2026-07-01 00:00:00')).toBeInTheDocument();
expect(screen.getByText('结束时间2026-07-01 23:59:59')).toBeInTheDocument();
expect(screen.getAllByText('返回解析字段').length).toBeGreaterThanOrEqual(2);
expect(screen.getByText('字段裁剪2 个')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '清空筛选' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/history/locations?limit=10&offset=0&keyword=VIN-HISTORY-001'), undefined);
});
expect(window.location.hash).toBe('#/history?keyword=VIN-HISTORY-001&tab=raw');
});
test('updates history hash when vehicle history filters are submitted', async () => {
window.history.replaceState(null, '', '/#/history');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
await screen.findByRole('heading', { name: '轨迹回放' });
fireEvent.change(screen.getByPlaceholderText('VIN / 车牌 / 手机号'), { target: { value: '粤AG18312' } });
fireEvent.click(screen.getAllByText('全部来源')[0]);
fireEvent.click(await screen.findByText('JT808'));
fireEvent.change(screen.getByPlaceholderText('2026-07-03 00:00:00'), { target: { value: '2026-07-01 00:00:00' } });
fireEvent.change(screen.getByPlaceholderText('2026-07-03 23:59:59'), { target: { value: '2026-07-01 23:59:59' } });
fireEvent.click(screen.getByRole('button', { name: 'search 查询' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/history?keyword=%E7%B2%A4AG18312&protocol=JT808&dateFrom=2026-07-01+00%3A00%3A00&dateTo=2026-07-01+23%3A59%3A59');
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/history/locations?'), undefined);
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('dateFrom=2026-07-01+00%3A00%3A00'), undefined);
expect(fetchMock).toHaveBeenCalledWith('/api/history/raw-frames/query', expect.objectContaining({
method: 'POST',
body: expect.stringContaining('"dateFrom":"2026-07-01 00:00:00"')
}));
});
test('prevents unscoped raw parsed-field query from history form', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-SAFE-RAW');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
await screen.findByRole('heading', { name: '轨迹回放' });
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith('/api/history/raw-frames/query', expect.objectContaining({
body: expect.stringContaining('VIN-SAFE-RAW')
}));
});
fetchMock.mockClear();
const keywordInput = screen.getByPlaceholderText('VIN / 车牌 / 手机号');
fireEvent.change(keywordInput, { target: { value: '' } });
fireEvent.input(keywordInput, { target: { value: '' } });
await waitFor(() => {
expect(keywordInput).toHaveValue('');
});
fireEvent.click(screen.getByRole('checkbox', { name: '返回解析字段' }));
fireEvent.click(screen.getByRole('button', { name: 'search 查询' }));
expect((await screen.findAllByText('RAW 解析字段查询需要车辆、时间范围或字段裁剪')).length).toBeGreaterThanOrEqual(1);
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/history/locations?'), undefined);
expect(fetchMock).not.toHaveBeenCalledWith('/api/history/raw-frames/query', expect.anything());
});
test('shows trajectory playback workspace from history locations', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-TRACK-001&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: {
items: [
{ vin: 'VIN-TRACK-001', plate: '粤A轨迹1', protocol: 'JT808', longitude: 113.2, latitude: 23.1, speedKmh: 10, socPercent: 0, totalMileageKm: 100, lastSeen: '2026-07-03 10:00:00', deviceTime: '2026-07-03 10:00:00', serverTime: '2026-07-03 10:00:01' },
{ vin: 'VIN-TRACK-001', plate: '粤A轨迹1', protocol: 'JT808', longitude: 113.3, latitude: 23.2, speedKmh: 42, socPercent: 0, totalMileageKm: 112.4, lastSeen: '2026-07-03 10:10:00', deviceTime: '2026-07-03 10:10:00', serverTime: '2026-07-03 10:10:01' }
],
total: 2,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/raw-frames/query')) {
expect(init?.method).toBe('POST');
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByRole('heading', { name: '轨迹回放' })).toBeInTheDocument();
expect(screen.getByText('轨迹回放作业台')).toBeInTheDocument();
expect(screen.getByText('2 个有效轨迹点')).toBeInTheDocument();
expect(screen.getByText('区间里程')).toBeInTheDocument();
expect(screen.getAllByText('12.4 km').length).toBeGreaterThan(0);
expect(screen.getByText('最高速度')).toBeInTheDocument();
expect(screen.getByText('42 km/h')).toBeInTheDocument();
expect(screen.getByText('起点')).toBeInTheDocument();
expect(screen.getByText('终点')).toBeInTheDocument();
});
test('controls trajectory playback current point from history locations', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-TRACK-CONTROL&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
const path = String(input);
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: {
items: [
{ vin: 'VIN-TRACK-CONTROL', plate: '粤A回放1', protocol: 'JT808', longitude: 113.2, latitude: 23.1, speedKmh: 10, socPercent: 0, totalMileageKm: 100, lastSeen: '2026-07-03 10:00:00', deviceTime: '2026-07-03 10:00:00', serverTime: '2026-07-03 10:00:01' },
{ vin: 'VIN-TRACK-CONTROL', plate: '粤A回放1', protocol: 'JT808', longitude: 113.3, latitude: 23.2, speedKmh: 42, socPercent: 0, totalMileageKm: 112.4, lastSeen: '2026-07-03 10:10:00', deviceTime: '2026-07-03 10:10:00', serverTime: '2026-07-03 10:10:01' },
{ vin: 'VIN-TRACK-CONTROL', plate: '粤A回放1', protocol: 'JT808', longitude: 113.4, latitude: 23.3, speedKmh: 28, socPercent: 0, totalMileageKm: 119.9, lastSeen: '2026-07-03 10:20:00', deviceTime: '2026-07-03 10:20:00', serverTime: '2026-07-03 10:20:01' }
],
total: 3,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/raw-frames/query')) {
expect(init?.method).toBe('POST');
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-TRACK-CONTROL',
plate: '粤A回放1',
sourceCount: 1,
onlineSourceCount: 1,
coverageStatus: 'healthy',
primaryProtocol: 'JT808',
lastSeen: '2026-07-03 10:20:00',
historyCount: 3,
rawCount: 0,
mileageCount: 1,
qualityIssueCount: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前回放点')).toBeInTheDocument();
expect(screen.getByText('点 1 / 3')).toBeInTheDocument();
expect(screen.getAllByText('2026-07-03 10:00:00').length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '下一点' }));
expect(screen.getByText('点 2 / 3')).toBeInTheDocument();
expect(screen.getAllByText('2026-07-03 10:10:00').length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '上一点' }));
expect(screen.getByText('点 1 / 3')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '回放点车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-TRACK-CONTROL&protocol=JT808');
});
});
test('exports current history location page as csv', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-EXPORT-LOC&protocol=JT808');
const createObjectURL = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:history-location');
const revokeObjectURL = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined);
vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => undefined);
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-EXPORT-LOC',
plate: '粤A导出1',
protocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 0,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10',
deviceTime: '2026-07-03 20:12:10',
serverTime: '2026-07-03 20:12:11'
}],
total: 1,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/raw-frames/query')) {
expect(init?.method).toBe('POST');
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-EXPORT-LOC')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '导出位置当前页 CSV' }));
expect(createObjectURL).toHaveBeenCalled();
expect(revokeObjectURL).toHaveBeenCalledWith('blob:history-location');
});
test('exports current raw frame page as csv with parsed fields', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-EXPORT-RAW&protocol=GB32960&includeFields=true&tab=raw');
const createObjectURL = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:history-raw');
const revokeObjectURL = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined);
vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => undefined);
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/raw-frames/query')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
id: 'raw-export-001',
vin: 'VIN-EXPORT-RAW',
plate: '粤A导出2',
protocol: 'GB32960',
frameType: 'REALTIME',
deviceTime: '2026-07-03 20:12:10',
serverTime: '2026-07-03 20:12:11',
rawSizeBytes: 256,
parsedFields: { 'gb32960.vehicle.speed_kmh': 42 }
}],
total: 1,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('raw-export-001')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '导出 RAW 当前页 CSV' }));
expect(createObjectURL).toHaveBeenCalled();
expect(revokeObjectURL).toHaveBeenCalledWith('blob:history-raw');
});
test('shows vehicle and source scope on mileage hash', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-001&protocol=GB32960');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 2, sourceCount: 1, totalMileageKm: 12.3, averageMileagePerVin: 12.3 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前车辆VIN-MILEAGE-001')).toBeInTheDocument();
expect(screen.getByText('当前来源GB32960')).toBeInTheDocument();
});
test('applies mileage date range from shareable hash to API requests', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-002&protocol=JT808&dateFrom=2026-07-01&dateTo=2026-07-03');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 2, sourceCount: 1, totalMileageKm: 12.3, averageMileagePerVin: 12.3 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/mileage/summary?'), undefined);
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('dateFrom=2026-07-01'), undefined);
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('dateTo=2026-07-03'), undefined);
expect(screen.getByText('当前车辆VIN-MILEAGE-002')).toBeInTheDocument();
expect(screen.getByText('当前来源JT808')).toBeInTheDocument();
});
test('shows and clears current mileage filters while keeping vehicle scope', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-002&protocol=JT808&dateFrom=2026-07-01&dateTo=2026-07-03');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 2, sourceCount: 1, totalMileageKm: 12.3, averageMileagePerVin: 12.3 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前里程筛选')).toBeInTheDocument();
expect(screen.getByText('车辆VIN-MILEAGE-002')).toBeInTheDocument();
expect(screen.getByText('数据来源JT808')).toBeInTheDocument();
expect(screen.getByText('开始日期2026-07-01')).toBeInTheDocument();
expect(screen.getByText('结束日期2026-07-03')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '清空筛选' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/mileage/summary?keyword=VIN-MILEAGE-002'), undefined);
});
expect(window.location.hash).toBe('#/mileage?keyword=VIN-MILEAGE-002');
});
test('updates mileage hash when mileage filters are submitted', async () => {
window.history.replaceState(null, '', '/#/mileage');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 2, sourceCount: 1, totalMileageKm: 12.3, averageMileagePerVin: 12.3 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
await screen.findByRole('heading', { name: '里程统计' });
fireEvent.change(screen.getByPlaceholderText('VIN / 车牌 / 手机号 / OEM'), { target: { value: '粤AG18312' } });
fireEvent.click(screen.getByText('全部来源'));
fireEvent.click(await screen.findByText('JT808'));
fireEvent.change(screen.getByPlaceholderText('2026-07-01'), { target: { value: '2026-07-01' } });
fireEvent.change(screen.getByPlaceholderText('2026-07-03'), { target: { value: '2026-07-03' } });
fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/mileage?keyword=%E7%B2%A4AG18312&protocol=JT808&dateFrom=2026-07-01&dateTo=2026-07-03');
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/mileage/summary?'), undefined);
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('dateFrom=2026-07-01'), undefined);
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('dateTo=2026-07-03'), undefined);
});
test('opens current vehicle service from mileage header with current source evidence', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-HEADER&protocol=GB32960');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 0, sourceCount: 1, totalMileageKm: 0, averageMileagePerVin: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/resolve')) {
return {
ok: true,
json: async () => ({
data: {
lookupKey: 'VIN-MILEAGE-HEADER',
resolved: true,
vin: 'VIN-MILEAGE-HEADER',
plate: '',
phone: '',
oem: '',
protocols: ['GB32960'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前来源GB32960')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '当前车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-MILEAGE-HEADER&protocol=GB32960');
});
});
test('opens vehicle service from mileage row with row source evidence', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-ROW&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 12.3, averageMileagePerVin: 12.3 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-MILEAGE-ROW',
plate: '粤AG18312',
source: 'JT808',
date: '2026-07-03',
startMileageKm: 100,
endMileageKm: 112.3,
dailyMileageKm: 12.3,
anomalySeverity: ''
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/resolve')) {
return {
ok: true,
json: async () => ({
data: {
lookupKey: 'VIN-MILEAGE-ROW',
resolved: true,
vin: 'VIN-MILEAGE-ROW',
plate: '粤AG18312',
phone: '',
oem: 'G7s',
protocols: ['JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-MILEAGE-ROW')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-MILEAGE-ROW&protocol=JT808');
});
});
test('opens same-day trajectory playback from mileage row for evidence review', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-TRACK&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 18.8, averageMileagePerVin: 18.8 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-MILEAGE-TRACK',
plate: '粤A轨迹核',
source: 'JT808',
date: '2026-07-03',
startMileageKm: 200,
endMileageKm: 218.8,
dailyMileageKm: 18.8,
anomalySeverity: 'warning'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-MILEAGE-TRACK')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '核对轨迹' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/history?keyword=VIN-MILEAGE-TRACK&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04');
});
});
test('opens same-day raw frame evidence from mileage row', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-RAW&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 18.8, averageMileagePerVin: 18.8 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-MILEAGE-RAW',
plate: '粤ARAW核',
source: 'JT808',
date: '2026-07-03',
startMileageKm: 200,
endMileageKm: 218.8,
dailyMileageKm: 18.8,
anomalySeverity: 'warning'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/locations') || path.includes('/api/history/raw-frames')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-MILEAGE-RAW')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '核对 RAW' }));
await waitFor(() => {
expect(window.location.hash.startsWith('#/history?')).toBe(true);
});
const params = new URLSearchParams(window.location.hash.slice('#/history?'.length));
expect(params.get('keyword')).toBe('VIN-MILEAGE-RAW');
expect(params.get('protocol')).toBe('JT808');
expect(params.get('dateFrom')).toBe('2026-07-03');
expect(params.get('dateTo')).toBe('2026-07-04');
expect(params.get('tab')).toBe('raw');
expect(await screen.findByRole('heading', { name: '轨迹回放' })).toBeInTheDocument();
});
test('shows mileage anomaly action guidance', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-ANOMALY&protocol=GB32960');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: -3.2, averageMileagePerVin: -3.2 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-MILEAGE-ANOMALY',
plate: '粤A异常1',
source: 'GB32960',
date: '2026-07-03',
startMileageKm: 100,
endMileageKm: 96.8,
dailyMileageKm: -3.2,
anomalySeverity: 'warning'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-MILEAGE-ANOMALY')).toBeInTheDocument();
expect(screen.getByText('核对里程来源')).toBeInTheDocument();
expect(screen.getByText('日里程异常,优先核对当天首末总里程、来源断链和补传数据。')).toBeInTheDocument();
});
test('shows mileage statistics workspace with trend source and definition', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-STATS');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 2, recordCount: 4, sourceCount: 2, totalMileageKm: 140, averageMileagePerVin: 70 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [
{ vin: 'VIN-MILEAGE-STATS', plate: '粤A统计1', source: 'JT808', date: '2026-07-01', startMileageKm: 100, endMileageKm: 140, dailyMileageKm: 40, anomalySeverity: '' },
{ vin: 'VIN-MILEAGE-STATS', plate: '粤A统计1', source: 'GB32960', date: '2026-07-01', startMileageKm: 200, endMileageKm: 230, dailyMileageKm: 30, anomalySeverity: '' },
{ vin: 'VIN-MILEAGE-STATS-2', plate: '粤A统计2', source: 'JT808', date: '2026-07-02', startMileageKm: 300, endMileageKm: 360, dailyMileageKm: 60, anomalySeverity: 'warning' },
{ vin: 'VIN-MILEAGE-STATS-2', plate: '粤A统计2', source: 'GB32960', date: '2026-07-02', startMileageKm: 400, endMileageKm: 410, dailyMileageKm: 10, anomalySeverity: '' }
],
total: 4,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('区间趋势')).toBeInTheDocument();
expect(screen.getByText('来源贡献')).toBeInTheDocument();
expect(screen.getAllByText('2026-07-01').length).toBeGreaterThanOrEqual(1);
expect(screen.getAllByText('2026-07-02').length).toBeGreaterThanOrEqual(1);
expect(screen.getAllByText('JT808').length).toBeGreaterThanOrEqual(1);
expect(screen.getAllByText('GB32960').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('当前页里程')).toBeInTheDocument();
expect(screen.getByText('140 km')).toBeInTheDocument();
expect(screen.getByText('异常记录')).toBeInTheDocument();
expect(screen.getAllByText('1').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('最大单日')).toBeInTheDocument();
expect(screen.getByText('60 km')).toBeInTheDocument();
expect(screen.getByText('统计口径')).toBeInTheDocument();
expect(screen.getByText((content) => content.includes('区间总值应等于各日里程之和'))).toBeInTheDocument();
});
test('opens vehicle service from history results with row source evidence', async () => {
window.history.replaceState(null, '', '/#/history?keyword=%E7%B2%A4AG18312&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-JT808-001',
plate: '粤AG18312',
protocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 0,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10',
deviceTime: '2026-07-03 20:12:10',
serverTime: '2026-07-03 20:12:11'
}],
total: 1,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/resolve')) {
return {
ok: true,
json: async () => ({
data: {
lookupKey: 'VIN-JT808-001',
resolved: true,
vin: 'VIN-JT808-001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-JT808-001')).toBeInTheDocument();
fireEvent.click(screen.getAllByRole('button', { name: '车辆服务' })[0]);
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-JT808-001&protocol=JT808');
});
});
test('opens same-day mileage statistics from history location row', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-HISTORY-MILEAGE&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-HISTORY-MILEAGE',
plate: '粤A历史账',
protocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 0,
totalMileageKm: 218.8,
lastSeen: '2026-07-03 20:12:10',
deviceTime: '2026-07-03 20:12:10',
serverTime: '2026-07-03 20:12:11'
}],
total: 1,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 18.8, averageMileagePerVin: 18.8 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-HISTORY-MILEAGE',
plate: '粤A历史账',
source: 'JT808',
date: '2026-07-03',
startMileageKm: 200,
endMileageKm: 218.8,
dailyMileageKm: 18.8,
anomalySeverity: 'normal'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-HISTORY-MILEAGE')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '核对里程' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/mileage?keyword=VIN-HISTORY-MILEAGE&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04');
});
});
test('opens same-day raw evidence from history location row', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-HISTORY-RAW&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-HISTORY-RAW',
plate: '粤A原帧核',
protocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 0,
totalMileageKm: 218.8,
lastSeen: '2026-07-03 20:12:10',
deviceTime: '2026-07-03 20:12:10',
serverTime: '2026-07-03 20:12:11'
}],
total: 1,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/raw-frames/query')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
id: 'raw-from-location-001',
vin: 'VIN-HISTORY-RAW',
plate: '粤A原帧核',
protocol: 'JT808',
frameType: '0x0200',
deviceTime: '2026-07-03 20:12:10',
serverTime: '2026-07-03 20:12:11',
rawSizeBytes: 128,
parsedFields: { 'jt808.location.longitude': 113.2 }
}],
total: 1,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect((await screen.findAllByText('VIN-HISTORY-RAW')).length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '核对 RAW' }));
await waitFor(() => {
expect(window.location.hash.startsWith('#/history?')).toBe(true);
});
const params = new URLSearchParams(window.location.hash.slice('#/history?'.length));
expect(params.get('keyword')).toBe('VIN-HISTORY-RAW');
expect(params.get('protocol')).toBe('JT808');
expect(params.get('dateFrom')).toBe('2026-07-03');
expect(params.get('dateTo')).toBe('2026-07-04');
expect(params.get('includeFields')).toBe('true');
expect(params.get('tab')).toBe('raw');
expect(await screen.findByRole('tab', { name: 'RAW 帧' })).toHaveAttribute('aria-selected', 'true');
expect(await screen.findByText('raw-from-location-001')).toBeInTheDocument();
});
test('opens vehicle service from raw history rows with row source evidence', async () => {
window.history.replaceState(null, '', '/#/history?keyword=%E7%B2%A4AG18312&protocol=GB32960');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/raw-frames/query')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
id: 'raw-gb32960-001',
vin: 'VIN-GB32960-001',
plate: '粤AG18312',
protocol: 'GB32960',
frameType: 'REALTIME',
deviceTime: '2026-07-03 20:12:10',
serverTime: '2026-07-03 20:12:11',
rawSizeBytes: 256,
parsedFields: {}
}],
total: 1,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/resolve')) {
return {
ok: true,
json: async () => ({
data: {
lookupKey: 'VIN-GB32960-001',
resolved: true,
vin: 'VIN-GB32960-001',
plate: '粤AG18312',
phone: '',
oem: 'G7s',
protocols: ['GB32960'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('tab', { name: 'RAW 帧' }));
expect(await screen.findByText('raw-gb32960-001')).toBeInTheDocument();
fireEvent.click(screen.getAllByRole('button', { name: '车辆服务' })[0]);
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-GB32960-001&protocol=GB32960');
});
});
test('opens same-day mileage statistics from raw history row', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-RAW-MILEAGE&protocol=JT808&tab=raw');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/raw-frames/query')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
id: 'raw-jt808-mileage-001',
vin: 'VIN-RAW-MILEAGE',
plate: '粤ARAW里',
protocol: 'JT808',
frameType: '0x0200',
deviceTime: '2026-07-03 20:12:10',
serverTime: '2026-07-03 20:12:11',
rawSizeBytes: 128,
parsedFields: { 'jt808.location.total_mileage_km': 218.8 }
}],
total: 1,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 18.8, averageMileagePerVin: 18.8 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-RAW-MILEAGE',
plate: '粤ARAW里',
source: 'JT808',
date: '2026-07-03',
startMileageKm: 200,
endMileageKm: 218.8,
dailyMileageKm: 18.8,
anomalySeverity: ''
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('raw-jt808-mileage-001')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '核对里程' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/mileage?keyword=VIN-RAW-MILEAGE&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04');
});
expect(await screen.findByRole('heading', { name: '里程统计' })).toBeInTheDocument();
});
test('opens current vehicle service from history header with current source evidence', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-JT808-HEADER&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/vehicles/resolve')) {
return {
ok: true,
json: async () => ({
data: {
lookupKey: 'VIN-JT808-HEADER',
resolved: true,
vin: 'VIN-JT808-HEADER',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前来源JT808')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '当前车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-JT808-HEADER&protocol=JT808');
});
});
test('opens vehicle service from realtime vehicles with primary source evidence', async () => {
window.history.replaceState(null, '', '/#/realtime');
const fetchMock = 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-MQTT-001',
plate: '川AHTWO1',
phone: '',
oem: '宇通',
protocols: ['GB32960', 'YUTONG_MQTT'],
sourceCount: 2,
onlineSourceCount: 1,
online: true,
primaryProtocol: 'YUTONG_MQTT',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10'
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-MQTT-001',
plate: '川AHTWO1',
sourceCount: 2,
onlineSourceCount: 1,
coverageStatus: 'online',
primaryProtocol: 'YUTONG_MQTT',
lastSeen: '2026-07-03 20:12:10',
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect((await screen.findAllByText('VIN-MQTT-001')).length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-MQTT-001&protocol=YUTONG_MQTT');
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=VIN-MQTT-001&protocol=YUTONG_MQTT'), undefined);
});
test('opens vehicle service from realtime vehicles with current source filter', async () => {
window.history.replaceState(null, '', '/#/realtime?keyword=VIN-RT-FILTER&protocol=JT808');
const fetchMock = 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-RT-FILTER',
plate: '粤ART808',
phone: '',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:11:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '', hasRealtime: false, hasHistory: false, hasRaw: false, hasMileage: false }
],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10'
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-RT-FILTER',
plate: '粤ART808',
sourceCount: 2,
onlineSourceCount: 2,
coverageStatus: 'online',
primaryProtocol: 'GB32960',
lastSeen: '2026-07-03 20:12:10',
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect((await screen.findAllByText('VIN-RT-FILTER')).length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-RT-FILTER&protocol=JT808');
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=VIN-RT-FILTER&protocol=JT808'), undefined);
});
test('shows canonical service status in realtime vehicles', async () => {
window.history.replaceState(null, '', '/#/realtime');
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-RT-DEGRADED',
plate: '粤ART001',
phone: '',
oem: 'G7s',
protocols: ['GB32960'],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '由实时车辆 API 统一判定',
sourceCount: 2,
onlineSourceCount: 1
}
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect((await screen.findAllByText('VIN-RT-DEGRADED')).length).toBeGreaterThan(0);
expect(screen.getAllByText('来源不完整').length).toBeGreaterThan(0);
});
test('frames realtime page as one vehicle service with source evidence', async () => {
window.history.replaceState(null, '', '/#/realtime');
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-RT-SERVICE',
plate: '粤ART002',
phone: '',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:11:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '', hasRealtime: false, hasHistory: false, hasRaw: false, hasMileage: false }
],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'healthy',
severity: 'ok',
title: '服务正常',
detail: '2/2 来源在线',
sourceCount: 2,
onlineSourceCount: 2
}
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByRole('heading', { name: '实时监控' })).toBeInTheDocument();
expect(screen.getByText('高德地图待配置')).toBeInTheDocument();
expect(screen.getByText('定位有效')).toBeInTheDocument();
expect(screen.getByText('车辆核心数据')).toBeInTheDocument();
expect(screen.getByText('来源证据')).toBeInTheDocument();
expect(screen.getByText('GB32960 在线')).toBeInTheDocument();
expect(screen.getByText('JT808 在线')).toBeInTheDocument();
expect(screen.getByText('YUTONG_MQTT 未接入')).toBeInTheDocument();
expect(screen.getAllByText('2/2 来源在线').length).toBeGreaterThan(0);
});
test('opens vehicle service from realtime map service queue', async () => {
window.history.replaceState(null, '', '/#/realtime');
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-MAP-001',
plate: '粤AMAP01',
phone: '',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'JT808', online: false, lastSeen: '2026-07-03 19:12:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false }
],
sourceCount: 2,
onlineSourceCount: 1,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: 'JT808 离线GB32960 仍可支撑车辆服务',
sourceCount: 2,
onlineSourceCount: 1
}
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-MAP-001',
plate: '粤AMAP01',
sourceCount: 2,
onlineSourceCount: 1,
coverageStatus: 'degraded',
primaryProtocol: 'GB32960',
lastSeen: '2026-07-03 20:12:10',
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('地图车辆服务队列')).toBeInTheDocument();
expect(screen.getAllByText('粤AMAP01').length).toBeGreaterThan(0);
expect(screen.getByText('JT808 离线GB32960 仍可支撑车辆服务')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '地图车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-MAP-001&protocol=GB32960');
});
});
test('opens amap coordinate and trajectory playback from realtime map service queue', async () => {
window.history.replaceState(null, '', '/#/realtime');
const openSpy = vi.spyOn(window, 'open').mockImplementation(() => null);
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-MAP-LINK',
plate: '粤AMAP02',
phone: '',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:11:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.24567,
latitude: 23.12345,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'healthy',
severity: 'ok',
title: '服务正常',
detail: '2/2 来源在线',
sourceCount: 2,
onlineSourceCount: 2
}
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('地图车辆服务队列')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '高德坐标' }));
expect(openSpy).toHaveBeenCalledWith(
expect.stringContaining('https://uri.amap.com/marker?position=113.24567,23.12345'),
'_blank',
'noopener,noreferrer'
);
fireEvent.click(screen.getByRole('button', { name: '轨迹回放' }));
expect(window.location.hash).toBe('#/history?keyword=VIN-MAP-LINK&protocol=GB32960');
});
test('surfaces multi-source realtime consistency issues with quality drilldown', async () => {
window.history.replaceState(null, '', '/#/realtime');
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-RT-CONSISTENCY',
plate: '粤A一致监控',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:05', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '2026-07-03 20:01:40', hasRealtime: true, hasHistory: false, hasRaw: true, hasMileage: false }
],
sourceCount: 3,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: 'YUTONG_MQTT 离线GB32960/JT808 仍可支撑车辆服务',
sourceCount: 3,
onlineSourceCount: 2
}
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: { issueVehicleCount: 0, issueRecordCount: 0, errorCount: 0, warningCount: 0, protocols: [], issueTypes: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 50, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/ops/health')) {
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;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('多来源一致性检查')).toBeInTheDocument();
expect(screen.getAllByText('粤A一致监控').length).toBeGreaterThan(0);
expect(screen.getByText('一致性诊断YUTONG_MQTT 离线GB32960/JT808 仍可支撑车辆服务')).toBeInTheDocument();
expect(screen.getByText('一致性YUTONG_MQTT 离线')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '检查质量' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/quality?keyword=VIN-RT-CONSISTENCY&protocol=GB32960');
});
});
test('opens quality issues from realtime vehicle row with source evidence', async () => {
window.history.replaceState(null, '', '/#/realtime?protocol=JT808');
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-RT-QUALITY',
plate: '粤A质量1',
phone: '13307795425',
oem: 'G7s',
protocols: ['JT808'],
sourceStatus: [
{ protocol: 'JT808', online: false, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: false }
],
sourceCount: 1,
onlineSourceCount: 0,
online: false,
primaryProtocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 0,
socPercent: 70,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'offline',
severity: 'error',
title: '车辆离线',
detail: 'JT808 离线',
sourceCount: 1,
onlineSourceCount: 0
}
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 1,
warningCount: 0,
protocols: [{ name: 'JT808', count: 1 }],
issueTypes: [{ name: 'LINK_GAP', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-RT-QUALITY',
plate: '粤A质量1',
phone: '13307795425',
sourceEndpoint: '115.29.187.205:808',
protocol: 'JT808',
issueType: 'LINK_GAP',
severity: 'error',
title: 'JT808 离线',
detail: '实时来源不可用',
firstSeen: '2026-07-03 20:12:10',
lastSeen: '2026-07-03 20:12:10'
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: {
linkHealth: [],
kafkaLag: 0,
activeConnections: 1,
capacityFindings: [],
redisOnlineKeys: 1,
tdengineWritable: true,
mysqlWritable: true,
runtime: { requestTimeoutMs: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect((await screen.findAllByText('VIN-RT-QUALITY')).length).toBeGreaterThan(0);
fireEvent.click(screen.getAllByRole('button', { name: '质量问题' })[0]);
await waitFor(() => {
expect(window.location.hash).toBe('#/quality?keyword=VIN-RT-QUALITY&protocol=JT808');
});
expect(await screen.findByRole('heading', { name: '告警通知' })).toBeInTheDocument();
});
test('loads realtime vehicles from shareable source filter hash', async () => {
window.history.replaceState(null, '', '/#/realtime?keyword=%E7%B2%A4ART002&protocol=JT808&online=online&serviceStatus=degraded');
const fetchMock = 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-RT-FILTERED',
plate: '粤ART002',
phone: '',
oem: 'G7s',
protocols: ['JT808'],
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: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect((await screen.findAllByText('VIN-RT-FILTERED')).length).toBeGreaterThan(0);
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/realtime/vehicles?limit=50&offset=0&keyword=%E7%B2%A4ART002&protocol=JT808&online=online&serviceStatus=degraded'), undefined);
});
test('opens realtime status from quality issue row with source evidence', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
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;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 1,
warningCount: 0,
protocols: [{ name: 'JT808', count: 1 }],
issueTypes: [{ name: 'VIN_MISSING', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: '',
plate: '粤AG18312',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'VIN_MISSING',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 数据缺少 VIN 映射'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 50, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('13307795425')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '实时状态' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/realtime?keyword=%E7%B2%A4AG18312&protocol=JT808');
});
expect(await screen.findByRole('heading', { name: '实时监控' })).toBeInTheDocument();
});
test('shows and clears current realtime service filters', async () => {
window.history.replaceState(null, '', '/#/realtime?keyword=%E7%B2%A4ART002&protocol=JT808&online=online&serviceStatus=degraded');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 1, limit: 50, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前实时筛选')).toBeInTheDocument();
expect(screen.getByText('关键词粤ART002')).toBeInTheDocument();
expect(screen.getByText('数据来源JT808')).toBeInTheDocument();
expect(screen.getByText('在线:在线')).toBeInTheDocument();
expect(screen.getByText('服务状态:来源不完整')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '清空筛选' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/realtime/vehicles?limit=50&offset=0'), undefined);
});
expect(window.location.hash).toBe('#/realtime');
});
test('updates realtime hash when source filters are submitted', async () => {
window.history.replaceState(null, '', '/#/realtime');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 50, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
await screen.findByRole('heading', { name: '实时监控' });
fireEvent.change(screen.getByPlaceholderText('VIN / 车牌 / 手机号 / OEM'), { target: { value: '粤ART002' } });
fireEvent.click(screen.getByText('全部来源'));
fireEvent.click(await screen.findByText('JT808'));
fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/realtime?keyword=%E7%B2%A4ART002&protocol=JT808');
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/realtime/vehicles?limit=50&offset=0&keyword=%E7%B2%A4ART002&protocol=JT808'), undefined);
});
test('shows vehicle service status in vehicle list', async () => {
window.history.replaceState(null, '', '/#/vehicles');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-DEGRADED-001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '由车辆服务 API 统一判定',
sourceCount: 2,
onlineSourceCount: 1
}
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-DEGRADED-001')).toBeInTheDocument();
expect(screen.getByText('车辆服务状态')).toBeInTheDocument();
expect(screen.getByText('来源不完整')).toBeInTheDocument();
});
test('shows source consistency diagnosis in vehicle service list', async () => {
window.history.replaceState(null, '', '/#/vehicles');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1,
onlineVehicles: 1,
singleSourceVehicles: 0,
multiSourceVehicles: 1,
noDataVehicles: 0,
unboundVehicles: 0,
missingSources: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-CONSISTENCY-LIST',
plate: '粤A一致',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
missingProtocols: ['YUTONG_MQTT'],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
sourceConsistency: {
sourceCount: 2,
onlineSourceCount: 2,
locatedSourceCount: 0,
missingProtocols: ['YUTONG_MQTT'],
mileageDeltaKm: 0,
sourceTimeDeltaSeconds: 0,
scope: 'coverage',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/2 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。'
}
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-CONSISTENCY-LIST')).toBeInTheDocument();
expect(screen.getByText('来源一致性')).toBeInTheDocument();
expect(screen.getByText('来源不完整')).toBeInTheDocument();
});
test('filters vehicle list from source consistency diagnosis', async () => {
window.history.replaceState(null, '', '/#/vehicles');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1,
onlineVehicles: 1,
singleSourceVehicles: 0,
multiSourceVehicles: 1,
noDataVehicles: 0,
unboundVehicles: 0,
missingSources: [{ protocol: 'YUTONG_MQTT', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-CONSISTENCY-ACTION',
plate: '粤A动作',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
missingProtocols: ['YUTONG_MQTT'],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
sourceConsistency: {
sourceCount: 2,
onlineSourceCount: 2,
locatedSourceCount: 0,
missingProtocols: ['YUTONG_MQTT'],
mileageDeltaKm: 0,
sourceTimeDeltaSeconds: 0,
scope: 'coverage',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/2 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。'
}
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-CONSISTENCY-ACTION')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '来源不完整' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/vehicles?serviceStatus=degraded&missingProtocol=YUTONG_MQTT');
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('serviceStatus=degraded'), undefined);
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=YUTONG_MQTT'), undefined);
});
test('filters vehicle list from single-source consistency diagnosis', async () => {
window.history.replaceState(null, '', '/#/vehicles');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1,
onlineVehicles: 1,
singleSourceVehicles: 1,
multiSourceVehicles: 0,
noDataVehicles: 0,
unboundVehicles: 0,
missingSources: [{ protocol: 'JT808', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-SINGLE-SOURCE',
plate: '粤A单源',
phone: '',
oem: '',
protocols: ['GB32960'],
missingProtocols: ['JT808', 'YUTONG_MQTT'],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-04 07:15:28',
bindingStatus: 'bound',
sourceConsistency: {
sourceCount: 1,
onlineSourceCount: 1,
locatedSourceCount: 0,
missingProtocols: ['JT808', 'YUTONG_MQTT'],
mileageDeltaKm: 0,
sourceTimeDeltaSeconds: 0,
scope: 'coverage',
status: 'single_source',
severity: 'warning',
title: '单一来源',
detail: '当前车辆只有一个数据来源,无法做跨来源一致性校验。'
}
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-SINGLE-SOURCE')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '单一来源' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/vehicles?serviceStatus=degraded&missingProtocol=JT808');
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=JT808'), undefined);
});
test('opens vehicle service from source-filtered vehicle list with source evidence', async () => {
window.history.replaceState(null, '', '/#/vehicles?protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-LIST-JT808',
plate: '粤A列表1',
phone: '13307795425',
oem: 'G7s',
protocols: ['JT808'],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-LIST-JT808',
plate: '粤A列表1',
sourceCount: 1,
onlineSourceCount: 1,
coverageStatus: 'online',
primaryProtocol: 'JT808',
lastSeen: '2026-07-03 20:12:10',
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-LIST-JT808')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-LIST-JT808&protocol=JT808');
});
});
test('opens quality issues from source-filtered vehicle list with source evidence', async () => {
window.history.replaceState(null, '', '/#/vehicles?protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-LIST-QUALITY',
plate: '粤A列表质',
phone: '13307795425',
oem: 'G7s',
protocols: ['JT808'],
sourceCount: 1,
onlineSourceCount: 0,
online: false,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'offline',
severity: 'error',
title: '车辆离线',
detail: 'JT808 来源离线',
sourceCount: 1,
onlineSourceCount: 0
}
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: {
issueVehicleCount: 1,
issueRecordCount: 1,
errorCount: 1,
warningCount: 0,
protocols: [{ name: 'JT808', count: 1 }],
issueTypes: [{ name: 'LINK_GAP', count: 1 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-LIST-QUALITY',
plate: '粤A列表质',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'LINK_GAP',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 来源离线'
}],
total: 1,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-LIST-QUALITY')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '质量问题' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/quality?keyword=VIN-LIST-QUALITY&protocol=JT808');
});
expect(await screen.findByRole('heading', { name: '告警通知' })).toBeInTheDocument();
});
test('filters vehicle list by service status', async () => {
window.history.replaceState(null, '', '/#/vehicles');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
await screen.findByRole('heading', { name: '车辆服务' });
fireEvent.click(screen.getByTestId('service-status-filter'));
fireEvent.click(await screen.findByText('来源不完整'));
fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('serviceStatus=degraded'), undefined);
});
});
test('switches vehicle detail to a source from the source matrix', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN001',
resolved: true,
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
realtimeSummary: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceCount: 3,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:08', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '', hasRealtime: false, hasHistory: false, hasRaw: false, hasMileage: false }
],
realtime: [
{
vin: 'VIN001',
plate: '粤AG18312',
protocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
},
{
vin: 'VIN001',
plate: '粤AG18312',
protocol: 'JT808',
longitude: 113.21,
latitude: 23.11,
speedKmh: 28,
socPercent: 0,
totalMileageKm: 99.5,
lastSeen: '2026-07-03 20:12:08'
}
],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN001')).toBeInTheDocument();
expect(screen.getAllByText('GB32960 在线').length).toBeGreaterThanOrEqual(1);
expect(screen.getAllByText('JT808 在线').length).toBeGreaterThanOrEqual(1);
expect(screen.getAllByText('YUTONG_MQTT 未接入').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('车辆服务角色')).toBeInTheDocument();
expect(screen.getByText('主来源')).toBeInTheDocument();
expect(screen.getByText('在线证据')).toBeInTheDocument();
expect(screen.getByText('暂无来源')).toBeInTheDocument();
expect(screen.getByText('最新位置')).toBeInTheDocument();
expect(screen.getAllByText('113.2, 23.1').length).toBeGreaterThan(0);
expect(screen.getByText(/100\s*km/)).toBeInTheDocument();
expect(screen.getByText(/30\s*km\/h/)).toBeInTheDocument();
expect(screen.getAllByText('YUTONG_MQTT').length).toBeGreaterThan(0);
expect(screen.getAllByText('无上报').length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '仅看 JT808' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN001&protocol=JT808');
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service?keyword=VIN001&protocol=JT808'), undefined);
});
test('shows unified service overview on vehicle detail', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
serviceOverview: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
primaryProtocol: 'GB32960',
coverageStatus: 'partial',
sourceCount: 3,
onlineSourceCount: 2,
lastSeen: '2026-07-03 20:12:10',
realtimeCount: 3,
historyCount: 12,
rawCount: 34,
mileageCount: 7,
qualityIssueCount: 1
},
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/3 个来源在线',
sourceCount: 3,
onlineSourceCount: 2
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 12, limit: 20, offset: 0 },
raw: { items: [], total: 34, limit: 10, offset: 0 },
mileage: { items: [], total: 7, limit: 20, offset: 0 },
quality: { items: [], total: 1, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务概览')).toBeInTheDocument();
expect(screen.getByText('2/3')).toBeInTheDocument();
expect(screen.getByText('历史 12 / RAW 34 / 里程 7')).toBeInTheDocument();
});
test('opens quality governance from vehicle detail overview', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
serviceOverview: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
primaryProtocol: 'GB32960',
coverageStatus: 'partial',
sourceCount: 2,
onlineSourceCount: 1,
lastSeen: '2026-07-03 20:12:10',
realtimeCount: 2,
historyCount: 12,
rawCount: 34,
mileageCount: 7,
qualityIssueCount: 3
},
sources: ['GB32960', 'JT808'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 12, limit: 20, offset: 0 },
raw: { items: [], total: 34, limit: 10, offset: 0 },
mileage: { items: [], total: 7, limit: 20, offset: 0 },
quality: { items: [], total: 3, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: path.includes('/api/quality/summary')
? { issueVehicleCount: 1, issueRecordCount: 3, errorCount: 0, warningCount: 3, protocols: [], issueTypes: [] }
: { items: [], total: 3, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务概览')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '查看质量问题 3 项' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/quality?keyword=VIN001');
});
expect(await screen.findByRole('heading', { name: '告警通知' })).toBeInTheDocument();
expect(screen.getByText('告警通知闭环')).toBeInTheDocument();
expect(screen.getByText('事件触发')).toBeInTheDocument();
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/quality/issues?keyword=VIN001&limit=20&offset=0'), undefined);
});
test('quality health storage card stays pending before ops health loads', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return new Promise<Response>(() => undefined);
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/quality/summary')
? { issueVehicleCount: 0, issueRecordCount: 0, errorCount: 0, warningCount: 0, protocols: [], issueTypes: [] }
: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByRole('heading', { name: '告警通知' })).toBeInTheDocument();
expect(screen.getByText('存储读取')).toBeInTheDocument();
expect(screen.getByText('检测中')).toBeInTheDocument();
expect(screen.queryByText('异常')).not.toBeInTheDocument();
});
test('quality health shows active connection capacity metric', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, activeConnections: 120000, redisOnlineKeys: 368, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: path.includes('/api/quality/summary')
? { issueVehicleCount: 0, issueRecordCount: 0, errorCount: 0, warningCount: 0, protocols: [], issueTypes: [] }
: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByRole('heading', { name: '告警通知' })).toBeInTheDocument();
expect(await screen.findByText('活跃连接')).toBeInTheDocument();
expect(screen.getByText('120,000')).toBeInTheDocument();
});
test('quality health shows structured capacity findings', async () => {
window.history.replaceState(null, '', '/#/quality');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 42, activeConnections: 120000, capacityFindings: ['kafka lag 42'], redisOnlineKeys: 368, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: path.includes('/api/quality/summary')
? { issueVehicleCount: 0, issueRecordCount: 0, errorCount: 0, warningCount: 0, protocols: [], issueTypes: [] }
: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByRole('heading', { name: '告警通知' })).toBeInTheDocument();
expect(await screen.findByText('容量检查发现')).toBeInTheDocument();
expect(screen.getByText('kafka lag 42')).toBeInTheDocument();
});
test('shows vehicle service evidence chain before source details', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
serviceOverview: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
primaryProtocol: 'GB32960',
coverageStatus: 'partial',
sourceCount: 3,
onlineSourceCount: 2,
lastSeen: '2026-07-03 20:12:10',
realtimeCount: 3,
historyCount: 12,
rawCount: 34,
mileageCount: 7,
qualityIssueCount: 1
},
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/3 个来源在线',
sourceCount: 3,
onlineSourceCount: 2
},
sourceConsistency: {
sourceCount: 3,
onlineSourceCount: 2,
locatedSourceCount: 2,
mileageDeltaKm: 1.4,
sourceTimeDeltaSeconds: 125,
scope: 'vehicle',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: 'MQTT 离线32960 与 808 仍可支撑车辆服务'
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:08', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '2026-07-03 20:10:05', hasRealtime: true, hasHistory: false, hasRaw: true, hasMileage: false }
],
realtime: [],
history: { items: [], total: 12, limit: 20, offset: 0 },
raw: { items: [], total: 34, limit: 10, offset: 0 },
mileage: { items: [], total: 7, limit: 20, offset: 0 },
quality: { items: [], total: 1, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务证据链')).toBeInTheDocument();
expect(screen.getByText('2/3 来源在线')).toBeInTheDocument();
expect(screen.getAllByText('2 个来源有位置').length).toBeGreaterThan(0);
expect(screen.getAllByText('1.4 km').length).toBeGreaterThan(0);
expect(screen.getAllByText('125 秒').length).toBeGreaterThan(0);
expect(screen.getAllByText('MQTT 离线32960 与 808 仍可支撑车辆服务').length).toBeGreaterThan(0);
});
test('copies shareable vehicle service detail link', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001&protocol=JT808');
const writeText = vi.fn(() => Promise.resolve());
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText }
});
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
sources: ['GB32960', 'JT808'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: /复制服务链接/ }));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('/#/detail?keyword=VIN001&protocol=JT808'));
});
test('exports vehicle detail service dossier as csv', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN-REPORT-001&protocol=GB32960');
const createObjectURL = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:vehicle-report');
const revokeObjectURL = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined);
const click = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => undefined);
const appendChild = vi.spyOn(document.body, 'appendChild');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-REPORT-001',
lookupKey: 'VIN-REPORT-001',
lookupResolved: true,
serviceOverview: {
vin: 'VIN-REPORT-001',
plate: '粤A档案导出',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
primaryProtocol: 'GB32960',
coverageStatus: 'partial',
sourceCount: 3,
onlineSourceCount: 2,
lastSeen: '2026-07-03 20:12:10',
realtimeCount: 3,
historyCount: 12,
rawCount: 34,
mileageCount: 7,
qualityIssueCount: 1
},
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/3 个来源在线',
sourceCount: 3,
onlineSourceCount: 2
},
sourceConsistency: {
sourceCount: 3,
onlineSourceCount: 2,
locatedSourceCount: 2,
missingProtocols: ['YUTONG_MQTT'],
mileageDeltaKm: 1.4,
sourceTimeDeltaSeconds: 125,
scope: 'vehicle',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: 'MQTT 离线32960 与 808 仍可支撑车辆服务'
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:08', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '2026-07-03 20:10:05', hasRealtime: true, hasHistory: false, hasRaw: true, hasMileage: false }
],
realtime: [],
history: { items: [], total: 12, limit: 20, offset: 0 },
raw: { items: [], total: 34, limit: 10, offset: 0 },
mileage: { items: [], total: 7, limit: 20, offset: 0 },
quality: { items: [], total: 1, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务结论')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /导出档案 CSV/ }));
expect(createObjectURL).toHaveBeenCalled();
expect(click).toHaveBeenCalled();
expect(revokeObjectURL).toHaveBeenCalledWith('blob:vehicle-report');
const link = appendChild.mock.calls.find(([node]) => node instanceof HTMLAnchorElement)?.[0] as HTMLAnchorElement | undefined;
expect(link?.download).toBe('vehicle-service-VIN-REPORT-001-GB32960.csv');
});
test('opens history with the currently selected vehicle detail source', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN001',
resolved: true,
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
realtimeSummary: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
},
sources: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:08', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '仅看 JT808' }));
fireEvent.click(screen.getByRole('button', { name: '查看历史' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/history?keyword=VIN001&protocol=JT808');
});
});
test('opens raw history with the currently selected vehicle detail source', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN001',
resolved: true,
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
realtimeSummary: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
},
sources: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:08', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '仅看 JT808' }));
fireEvent.click(screen.getByRole('button', { name: '查看 RAW' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/history?keyword=VIN001&protocol=JT808&tab=raw');
});
});
test('opens realtime with the currently selected vehicle detail source', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN001',
resolved: true,
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
realtimeSummary: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
},
sources: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:08', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '仅看 JT808' }));
fireEvent.click(screen.getByRole('button', { name: '查看实时' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/realtime?keyword=VIN001&protocol=JT808');
});
});
test('opens source-specific history directly from vehicle detail source card', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN001',
resolved: true,
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
realtimeSummary: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
},
sources: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:08', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '查看 JT808 历史' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/history?keyword=VIN001&protocol=JT808');
});
});
test('opens source-specific raw history directly from vehicle detail source evidence', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN001',
resolved: true,
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
realtimeSummary: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
},
sources: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:08', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '查看 JT808 RAW' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/history?keyword=VIN001&protocol=JT808&tab=raw');
});
});
test('opens vehicle service from an empty history query with current source evidence', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN404&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/resolve')) {
return {
ok: true,
json: async () => ({
data: {
lookupKey: 'VIN404',
resolved: true,
vin: 'VIN404',
plate: '',
phone: '',
oem: '',
protocols: ['JT808'],
online: false,
lastSeen: ''
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
fireEvent.click(await screen.findByRole('button', { name: '当前车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN404&protocol=JT808');
});
});
test('shows selected source scope on vehicle detail', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001&protocol=JT808');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN001',
resolved: true,
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
realtimeSummary: {
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceCount: 2,
onlineSourceCount: 1,
online: true,
primaryProtocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
},
sources: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: false, lastSeen: '2026-07-03 20:11:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '1/2 个来源在线,车辆服务可用但需要关注离线来源。',
sourceCount: 2,
onlineSourceCount: 1
},
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前查看范围')).toBeInTheDocument();
expect(screen.getByText('单一来源JT808')).toBeInTheDocument();
expect(screen.getByText('车辆服务状态')).toBeInTheDocument();
expect(screen.getByText('来源不完整')).toBeInTheDocument();
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service?keyword=VIN001&protocol=JT808'), undefined);
});
test('shows cross-source consistency for one vehicle service', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN-CONSISTENCY-001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-CONSISTENCY-001',
lookupKey: 'VIN-CONSISTENCY-001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN-CONSISTENCY-001',
resolved: true,
vin: 'VIN-CONSISTENCY-001',
plate: '粤A一致1',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
realtimeSummary: {
vin: 'VIN-CONSISTENCY-001',
plate: '粤A一致1',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceCount: 3,
onlineSourceCount: 2,
online: true,
bindingStatus: 'bound',
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 32,
socPercent: 78,
totalMileageKm: 1000.5,
lastSeen: '2026-07-03T20:12:10+08:00'
},
sourceConsistency: {
sourceCount: 3,
onlineSourceCount: 2,
locatedSourceCount: 3,
missingProtocols: ['YUTONG_MQTT'],
mileageDeltaKm: 0.4,
sourceTimeDeltaSeconds: 35,
scope: 'all_sources',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/3 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。'
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03T20:12:10+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03T20:12:05+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '2026-07-03T20:11:40+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
realtime: [
{ vin: 'VIN-CONSISTENCY-001', plate: '粤A一致1', protocol: 'GB32960', longitude: 113.2, latitude: 23.1, speedKmh: 32, socPercent: 78, totalMileageKm: 1000.5, lastSeen: '2026-07-03T20:12:10+08:00' },
{ vin: 'VIN-CONSISTENCY-001', plate: '粤A一致1', protocol: 'JT808', longitude: 113.201, latitude: 23.101, speedKmh: 30, socPercent: 0, totalMileageKm: 1000.8, lastSeen: '2026-07-03T20:12:05+08:00' },
{ vin: 'VIN-CONSISTENCY-001', plate: '粤A一致1', protocol: 'YUTONG_MQTT', longitude: 113.2, latitude: 23.1, speedKmh: 31, socPercent: 77, totalMileageKm: 1000.7, lastSeen: '2026-07-03T20:11:40+08:00' }
],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('跨来源一致性')).toBeInTheDocument();
expect(screen.getAllByText('来源不完整').length).toBeGreaterThanOrEqual(1);
expect(screen.getAllByText('2/3 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。').length).toBeGreaterThan(0);
expect(screen.getByText('3 个来源')).toBeInTheDocument();
expect(screen.getByText('2/3 在线')).toBeInTheDocument();
expect(screen.getByText('缺失来源')).toBeInTheDocument();
expect(screen.getAllByText('3 个来源有位置').length).toBeGreaterThan(0);
expect(screen.getAllByText('0.4 km').length).toBeGreaterThan(0);
expect(screen.getAllByText('35 秒').length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '查看缺 YUTONG_MQTT 车辆' }));
expect(window.location.hash).toBe('#/vehicles?serviceStatus=degraded&missingProtocol=YUTONG_MQTT');
});
test('shows actionable vehicle service recommendations on detail', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN-ACTION-001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-ACTION-001',
lookupKey: 'VIN-ACTION-001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN-ACTION-001',
resolved: true,
vin: 'VIN-ACTION-001',
plate: '粤A处置1',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
online: true,
lastSeen: '2026-07-03T20:12:10+08:00'
},
realtimeSummary: {
vin: 'VIN-ACTION-001',
plate: '粤A处置1',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceCount: 3,
onlineSourceCount: 2,
online: true,
bindingStatus: 'bound',
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 32,
socPercent: 78,
totalMileageKm: 1000.5,
lastSeen: '2026-07-03T20:12:10+08:00'
},
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/3 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。',
sourceCount: 3,
onlineSourceCount: 2
},
sourceConsistency: {
sourceCount: 3,
onlineSourceCount: 2,
locatedSourceCount: 2,
missingProtocols: ['YUTONG_MQTT'],
mileageDeltaKm: 0.4,
sourceTimeDeltaSeconds: 35,
scope: 'all_sources',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/3 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。'
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03T20:12:10+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03T20:12:05+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '2026-07-03T20:11:40+08:00', hasRealtime: true, hasHistory: false, hasRaw: true, hasMileage: false }
],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 2, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 3, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务结论')).toBeInTheDocument();
expect(screen.getByText('降级可服务')).toBeInTheDocument();
expect(screen.getByText('3 项质量问题影响可信度')).toBeInTheDocument();
expect(screen.getByText('先处理质量问题,再将该车用于 BI、告警或对外查询。')).toBeInTheDocument();
expect(await screen.findByText('服务处置建议')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '补齐 YUTONG_MQTT 来源' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '处理质量问题 3 项' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '排查 YUTONG_MQTT 离线' })).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '补齐 YUTONG_MQTT 来源' }));
expect(window.location.hash).toBe('#/vehicles?serviceStatus=degraded&missingProtocol=YUTONG_MQTT');
});
test('shows canonical vehicle archive on detail', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN-ARCHIVE-001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-ARCHIVE-001',
lookupKey: 'VIN-ARCHIVE-001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN-ARCHIVE-001',
resolved: true,
vin: 'VIN-ARCHIVE-001',
plate: '粤A档案1',
phone: '',
oem: '',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
online: true,
lastSeen: '2026-07-03T20:12:10+08:00'
},
realtimeSummary: {
vin: 'VIN-ARCHIVE-001',
plate: '粤A档案1',
phone: '',
oem: '',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceCount: 3,
onlineSourceCount: 2,
online: true,
bindingStatus: 'bound',
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 32,
socPercent: 78,
totalMileageKm: 1000.5,
lastSeen: '2026-07-03T20:12:10+08:00'
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect((await screen.findAllByText('车辆档案')).length).toBeGreaterThan(0);
expect(screen.getByText('车辆主键')).toBeInTheDocument();
expect(screen.getAllByText('VIN-ARCHIVE-001').length).toBeGreaterThan(0);
expect(screen.getByText('档案完整度')).toBeInTheDocument();
expect(screen.getByText('2/4')).toBeInTheDocument();
expect(screen.getByText('缺手机号')).toBeInTheDocument();
expect(screen.getByText('缺OEM')).toBeInTheDocument();
expect(screen.getByText('归并来源数')).toBeInTheDocument();
expect(screen.getByText('3')).toBeInTheDocument();
});