feat(platform): save reusable customer views
This commit is contained in:
@@ -5,6 +5,7 @@ import App from '../App';
|
||||
afterEach(() => {
|
||||
cleanup();
|
||||
vi.useRealTimers();
|
||||
window.localStorage.clear();
|
||||
window.history.replaceState(null, '', '/');
|
||||
delete window.__LINGNIU_APP_CONFIG__;
|
||||
vi.restoreAllMocks();
|
||||
@@ -6742,6 +6743,76 @@ test('topbar copies customer vehicle service scope links', async () => {
|
||||
expect(copied).toContain('告警通知:http://localhost:3000/#/alert-events?keyword=VIN-SHARE-SCOPE&protocol=JT808&dateFrom=2026-06-29&dateTo=2026-07-05');
|
||||
});
|
||||
|
||||
test('topbar saves and restores reusable customer vehicle views', async () => {
|
||||
vi.setSystemTime(new Date('2026-07-05T10:00:00+08:00'));
|
||||
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: 'VIN-SAVED-SCOPE',
|
||||
plate: '粤A复用窗',
|
||||
primaryProtocol: 'GB32960',
|
||||
protocols: ['GB32960'],
|
||||
coverageStatus: 'online',
|
||||
sourceCount: 1,
|
||||
onlineSourceCount: 1,
|
||||
realtimeCount: 1,
|
||||
historyCount: 8,
|
||||
rawCount: 20,
|
||||
mileageCount: 3,
|
||||
qualityIssueCount: 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 />);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '顶部时间窗 近7天' }));
|
||||
fireEvent.change(screen.getByPlaceholderText('搜索 VIN / 车牌 / 手机号'), { target: { value: '粤A复用窗' } });
|
||||
fireEvent.click(screen.getByRole('button', { name: '查询车辆' }));
|
||||
expect(await screen.findByText('粤A复用窗 / VIN-SAVED-SCOPE')).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '顶部保存客户视图' }));
|
||||
expect(screen.getByRole('button', { name: '客户视图 粤A复用窗 / VIN-SAVED-SCOPE 2026-06-29 至 2026-07-05' })).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '顶部时间窗 清空' }));
|
||||
fireEvent.click(screen.getByRole('button', { name: '顶部地图态势' }));
|
||||
expect(window.location.hash).toBe('#/map?keyword=VIN-SAVED-SCOPE&protocol=GB32960');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '客户视图 粤A复用窗 / VIN-SAVED-SCOPE 2026-06-29 至 2026-07-05' }));
|
||||
expect(screen.getByLabelText('顶部时间窗开始')).toHaveValue('2026-06-29');
|
||||
expect(screen.getByLabelText('顶部时间窗结束')).toHaveValue('2026-07-05');
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: '顶部统计查询' }));
|
||||
expect(window.location.hash).toBe('#/mileage?keyword=VIN-SAVED-SCOPE&protocol=GB32960&dateFrom=2026-06-29&dateTo=2026-07-05');
|
||||
});
|
||||
|
||||
test('shows and clears current history filters while keeping vehicle scope', async () => {
|
||||
window.history.replaceState(null, '', '/#/history-query?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) => {
|
||||
|
||||
Reference in New Issue
Block a user