Files
lingniu-vehicle-ingest/vehicle-data-platform/apps/web/src/v2/domain/alert.test.ts
2026-07-18 11:24:24 +08:00

31 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import { alertValue, canAct, formatAlertTime, ruleCondition, thresholdText } from './alert';
describe('alert domain helpers', () => {
it('keeps trigger evidence and duration explicit', () => {
const event = { triggerValue: 96, threshold: 80, thresholdHigh: 0, operator: 'gt', unit: 'km/h', durationSec: 60 };
expect(alertValue(event)).toBe('96 km/h');
expect(thresholdText(event)).toBe('> 80 km/h持续 60 秒');
});
it('enforces valid workflow transitions', () => {
expect(canAct('unprocessed', 'acknowledge')).toBe(true);
expect(canAct('processing', 'acknowledge')).toBe(false);
expect(canAct('recovered', 'close')).toBe(true);
expect(canAct('closed', 'ignore')).toBe(false);
});
it('renders boolean rules without numeric fiction', () => {
expect(ruleCondition({ valueType: 'boolean', booleanThreshold: true, metric: 'alarm_active', durationSec: 0 } as never)).toBe('协议告警位 是');
});
it('renders range and state-change semantics', () => {
expect(thresholdText({ threshold: 20, thresholdHigh: 80, operator: 'between', unit: '%', durationSec: 30 })).toBe('区间内 2080 %,持续 30 秒');
expect(ruleCondition({ valueType: 'boolean', metric: 'alarm_active', operator: 'changed', durationSec: 0 } as never)).toBe('协议告警位 状态变化');
});
it('renders operational timestamps in the shared Shanghai timezone', () => {
expect(formatAlertTime('2026-07-18T02:33:00Z')).toBe('07-18 10:33:00');
});
});