import assert from 'node:assert/strict' import test from 'node:test' import { analysisPresentation, canEditDeviceObservability, eventStatusLabel, eventTypeLabel, relationPathLabel, relationTypeLabel, toGraphData } from '../src/views/dataGovernance/development/deviceObservabilityModel.js' test('presents operational event and relation labels for business users', () => { assert.equal(eventTypeLabel('alarm'), '告警') assert.equal(eventTypeLabel('fault'), '故障') assert.equal(eventTypeLabel('maintenance'), '维修') assert.equal(eventTypeLabel('downtime'), '停机') assert.equal(eventStatusLabel('resolved'), '已恢复') assert.equal(relationTypeLabel('triggered'), '触发') assert.equal( relationPathLabel(['indicates', 'triggered']), '表征 → 触发' ) }) test('converts bounded canonical graph into directed chart data', () => { const result = toGraphData({ anchor_kind: 'event', anchor_uid: 'event-downtime', nodes: [ { kind: 'event', uid: 'event-alarm', node_type: 'alarm', label: '轴承温度高' }, { kind: 'event', uid: 'event-downtime', node_type: 'downtime', label: '一号泵停机' }, { kind: 'asset', uid: 'asset-pump', node_type: 'device', label: '一号泵' } ], relations: [ { uid: 'relation-1', from_kind: 'event', from_uid: 'event-alarm', relation_type: 'triggered', to_kind: 'event', to_uid: 'event-downtime' } ] }) assert.equal(result.nodes.length, 3) assert.equal(result.links[0].source, 'event:event-alarm') assert.equal(result.links[0].target, 'event:event-downtime') assert.equal(result.links[0].name, '触发') assert.equal( result.nodes.find(item => item.id === 'event:event-downtime').itemStyle .borderWidth, 4 ) assert.ok(result.categories.some(item => item.name === '设备')) }) test('makes evidence sufficiency explicit and never presents a verdict', () => { assert.deepEqual(analysisPresentation('supported_candidates'), { color: 'warning', icon: 'mdi-alert-decagram-outline', title: '发现有证据支持的候选,等待专家确认' }) assert.deepEqual(analysisPresentation('insufficient_evidence'), { color: 'info', icon: 'mdi-information-outline', title: '证据不足,无法确认根因' }) }) test('separates observability import permission from read access', () => { assert.equal( canEditDeviceObservability(['governance:read']), false ) assert.equal( canEditDeviceObservability([ 'governance:read', 'device-observability:edit' ]), true ) })