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(); 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(); 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, serviceStatuses: [ { status: 'healthy', title: '服务正常', count: 161 }, { status: 'degraded', title: '部分来源离线', count: 41 } ], protocols: [{ protocol: 'JT808', online: 157, total: 388 }] }, 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(); expect(await screen.findByText('总车辆')).toBeInTheDocument(); expect(screen.getByText('1,033')).toBeInTheDocument(); 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(fetchMock).toHaveBeenCalledWith('/api/vehicle-service/summary', undefined); }); 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(); 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(); 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, unboundVehicles: 9 }, 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'], 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 } }], 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(); 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('VIN-MULTI-001')).toBeInTheDocument(); expect(screen.getAllByText('来源证据').length).toBeGreaterThanOrEqual(1); expect(screen.getByText('1/2 来源在线')).toBeInTheDocument(); }); 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(); 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 }, 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'], 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(); expect(await screen.findByText('缺失来源')).toBeInTheDocument(); fireEvent.click(screen.getByTestId('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); }); }); 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(); 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, serviceStatus: { status: 'degraded', severity: 'warning', title: '后端判定部分离线', detail: '后端统一车辆服务状态', sourceCount: 2, onlineSourceCount: 1 }, sourceConsistency: { sourceCount: 2, onlineSourceCount: 1, locatedSourceCount: 2, mileageDeltaKm: 0, sourceTimeDeltaSeconds: 0, scope: 'all_sources', status: 'degraded', severity: 'warning', title: '部分来源离线', detail: '1/2 个来源在线,车辆服务可用但需要关注离线来源。' } }, 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(); 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'], 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(); expect(await screen.findByText('VIN-COVERAGE-WARN')).toBeInTheDocument(); expect(screen.getAllByText('来源证据').length).toBeGreaterThanOrEqual(1); 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 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(); 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(); 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(); 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(); expect(await screen.findByText('VIN-NO-SOURCE-001')).toBeInTheDocument(); expect(screen.getAllByText('暂无数据来源').length).toBeGreaterThanOrEqual(1); expect(screen.getAllByText('车辆服务').length).toBeGreaterThanOrEqual(1); }); 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(); 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('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(); 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('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(); 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(); 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(); 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(); 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(); 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(); 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 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(); expect(await screen.findByText('当前车辆:VIN-MILEAGE-001')).toBeInTheDocument(); expect(screen.getByText('当前来源:GB32960')).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(); 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 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(); 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 unified vehicle service from realtime vehicles without primary protocol', 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-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/vehicles/resolve')) { return { ok: true, json: async () => ({ data: { lookupKey: 'VIN-MQTT-001', resolved: true, vin: 'VIN-MQTT-001', plate: '川AHTWO1', phone: '', oem: '宇通', protocols: ['GB32960', 'YUTONG_MQTT'], 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(); expect(await screen.findByText('VIN-MQTT-001')).toBeInTheDocument(); fireEvent.click(screen.getByRole('button', { name: '车辆服务' })); await waitFor(() => { expect(window.location.hash).toBe('#/detail?keyword=VIN-MQTT-001'); }); }); 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(); expect(await screen.findByText('VIN-RT-DEGRADED')).toBeInTheDocument(); expect(screen.getByText('部分来源离线')).toBeInTheDocument(); }); 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'], 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(); expect(await screen.findByRole('heading', { name: '车辆服务实时态' })).toBeInTheDocument(); expect(screen.getByText('车辆核心数据')).toBeInTheDocument(); expect(screen.getByText('来源证据')).toBeInTheDocument(); expect(screen.getByText('2/2 来源在线')).toBeInTheDocument(); }); 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(); expect(await screen.findByText('VIN-DEGRADED-001')).toBeInTheDocument(); expect(screen.getByText('车辆服务状态')).toBeInTheDocument(); expect(screen.getByText('部分来源离线')).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(); 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: [], 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(); expect(await screen.findByText('VIN001')).toBeInTheDocument(); expect(screen.getByText('车辆服务角色')).toBeInTheDocument(); expect(screen.getByText('主来源')).toBeInTheDocument(); expect(screen.getByText('在线证据')).toBeInTheDocument(); expect(screen.getByText('暂无来源')).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(); expect(await screen.findByText('车辆服务概览')).toBeInTheDocument(); expect(screen.getByText('2/3')).toBeInTheDocument(); expect(screen.getByText('历史 12 / RAW 34 / 里程 7')).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(); 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(); fireEvent.click(await screen.findByRole('button', { name: /复制服务链接/ })); expect(writeText).toHaveBeenCalledWith(expect.stringContaining('/#/detail?keyword=VIN001&protocol=JT808')); }); 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(); 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 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(); fireEvent.click(await screen.findByRole('button', { name: '查看 JT808 历史' })); await waitFor(() => { expect(window.location.hash).toBe('#/history?keyword=VIN001&protocol=JT808'); }); }); test('opens unified vehicle service from an empty history query', 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(); fireEvent.click(await screen.findByRole('button', { name: '当前车辆服务' })); await waitFor(() => { expect(window.location.hash).toBe('#/detail?keyword=VIN404'); }); }); 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(); 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, mileageDeltaKm: 0.4, sourceTimeDeltaSeconds: 35, scope: 'all_sources', status: 'degraded', severity: 'warning', title: '部分来源离线', detail: '2/3 个来源在线,车辆服务可用但需要关注离线来源。' }, 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(); expect(await screen.findByText('跨来源一致性')).toBeInTheDocument(); expect(screen.getAllByText('部分来源离线').length).toBeGreaterThanOrEqual(1); expect(screen.getAllByText('2/3 个来源在线,车辆服务可用但需要关注离线来源。').length).toBeGreaterThan(0); expect(screen.getByText('3 个来源')).toBeInTheDocument(); expect(screen.getByText('2/3 在线')).toBeInTheDocument(); expect(screen.getAllByText('3 个来源有位置').length).toBeGreaterThan(0); expect(screen.getAllByText('0.4 km').length).toBeGreaterThan(0); expect(screen.getAllByText('35 秒').length).toBeGreaterThan(0); });