refine Semi UI vehicle evidence
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import { protocolDisplayLabel, protocolSourceLabel } from './protocols';
|
||||
|
||||
describe('protocol display vocabulary', () => {
|
||||
test('uses one user-facing label for every supported vehicle protocol', () => {
|
||||
expect(protocolDisplayLabel('GB32960')).toBe('GB/T 32960');
|
||||
expect(protocolDisplayLabel('JT808')).toBe('JT/T 808');
|
||||
expect(protocolDisplayLabel('YUTONG_MQTT')).toBe('宇通 MQTT');
|
||||
});
|
||||
|
||||
test('keeps unknown protocols intact and explains qualified sources', () => {
|
||||
expect(protocolDisplayLabel('CUSTOM')).toBe('CUSTOM');
|
||||
expect(protocolSourceLabel('YUTONG_MQTT:canonical')).toBe('宇通 MQTT · canonical');
|
||||
expect(protocolSourceLabel('CUSTOM:gateway')).toBe('CUSTOM:gateway');
|
||||
});
|
||||
});
|
||||
21
vehicle-data-platform/apps/web/src/v2/domain/protocols.ts
Normal file
21
vehicle-data-platform/apps/web/src/v2/domain/protocols.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
const PROTOCOL_LABELS: Record<string, string> = {
|
||||
GB32960: 'GB/T 32960',
|
||||
JT808: 'JT/T 808',
|
||||
YUTONG_MQTT: '宇通 MQTT'
|
||||
};
|
||||
|
||||
export function protocolDisplayLabel(protocol?: string) {
|
||||
const normalized = protocol?.trim() ?? '';
|
||||
return normalized ? PROTOCOL_LABELS[normalized] ?? normalized : '—';
|
||||
}
|
||||
|
||||
export function protocolSourceLabel(source?: string) {
|
||||
const normalized = source?.trim() ?? '';
|
||||
if (!normalized) return '';
|
||||
const separator = normalized.indexOf(':');
|
||||
if (separator < 0) return protocolDisplayLabel(normalized);
|
||||
const protocol = normalized.slice(0, separator);
|
||||
const qualifier = normalized.slice(separator + 1);
|
||||
const label = protocolDisplayLabel(protocol);
|
||||
return label === protocol ? normalized : qualifier ? `${label} · ${qualifier}` : label;
|
||||
}
|
||||
Reference in New Issue
Block a user