feat(platform): show active history filters

This commit is contained in:
lingniu
2026-07-04 08:30:12 +08:00
parent 208d48115d
commit 7c81285be8
3 changed files with 95 additions and 3 deletions

View File

@@ -2294,6 +2294,67 @@ test('applies protocol from shareable history hash to API requests', async () =>
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) => {