feat(platform): surface amap operations shortcuts

This commit is contained in:
lingniu
2026-07-04 13:12:44 +08:00
parent 2cff1637ae
commit 47dfd18462
2 changed files with 39 additions and 0 deletions

View File

@@ -12,6 +12,7 @@ import {
import type { ReactNode } from 'react';
import { useState } from 'react';
import type { VehicleSourceConsistency, VehicleServiceStatus } from '../api/types';
import { isAMapConfigured } from '../config/appConfig';
export type PageKey = 'dashboard' | 'vehicles' | 'realtime' | 'detail' | 'history' | 'mileage' | 'quality';
@@ -53,6 +54,7 @@ export function AppShell({
}) {
const [keyword, setKeyword] = useState('');
const [searching, setSearching] = useState(false);
const amapConfigured = isAMapConfigured();
const search = () => {
const value = keyword.trim();
@@ -106,6 +108,9 @@ export function AppShell({
) : null}
<Tag color="blue"></Tag>
<Tag color="grey"> / </Tag>
<Tag color={amapConfigured ? 'green' : 'orange'}>{amapConfigured ? '地图就绪' : '地图待配置'}</Tag>
<Button size="small" onClick={() => onChange('realtime')}></Button>
<Button size="small" onClick={() => onChange('history')}></Button>
<Button size="small" className={linkHealthClassName(linkIssueCount)} onClick={() => onChange('quality')}>
{linkIssueCount == null ? '链路监控' : linkIssueCount > 0 ? `链路 ${linkIssueCount} 项关注` : '链路正常'}
</Button>

View File

@@ -5,6 +5,7 @@ import App from '../App';
afterEach(() => {
cleanup();
window.history.replaceState(null, '', '/');
delete window.__LINGNIU_APP_CONFIG__;
vi.restoreAllMocks();
});
@@ -14,6 +15,39 @@ test('renders vehicle platform shell', () => {
expect(screen.getAllByText('总览工作台').length).toBeGreaterThanOrEqual(1);
});
test('exposes AMap operations shortcuts when map key is configured', async () => {
window.__LINGNIU_APP_CONFIG__ = { amapWebJsKey: 'amap-web-key' };
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: 50, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('地图就绪')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '实时地图' }));
expect(window.location.hash).toBe('#/realtime');
fireEvent.click(screen.getByRole('button', { name: '地图回放' }));
expect(window.location.hash.startsWith('#/history')).toBe(true);
});
test('shows vehicle service status distribution on dashboard', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {