|
|
@@ -10,6 +10,7 @@ import assert from 'node:assert/strict'
|
|
|
import { test } from 'node:test'
|
|
|
|
|
|
import { deviceStatusStats, DEVICE_POOL_KEYS } from '../src/modules/cockpit/domain/deviceStatusStats.js'
|
|
|
+import { toMonitoringOverview } from '../src/modules/cockpit/domain/monitoringPanels.js'
|
|
|
|
|
|
test('标签可叠加:一台设备可同时进报警/预警/工单三个池', () => {
|
|
|
const { available, total, counts } = deviceStatusStats([
|
|
|
@@ -68,3 +69,24 @@ test('逐设备事实供详情/筛选消费:deviceCode + base + tags', () => {
|
|
|
test('计数桶顺序固定(环图与图例共用一份行序)', () => {
|
|
|
assert.deepEqual(DEVICE_POOL_KEYS, ['ALARM', 'WARNING', 'WORK_ORDER', 'NORMAL', 'OFFLINE'])
|
|
|
})
|
|
|
+
|
|
|
+test('适配层把后端 tags 带进 devices,计数函数才算得出报警/预警(防「映射漏字段」假绿)', () => {
|
|
|
+ const raw = {
|
|
|
+ counts: { equipmentCount: 3 },
|
|
|
+ devices: [
|
|
|
+ { deviceCode: 'A', deviceName: '甲', monitoringState: 'ONLINE', tags: ['ALARM'] },
|
|
|
+ { deviceCode: 'B', monitoringState: 'OFFLINE', tags: ['ALARM', 'WARNING'] },
|
|
|
+ { deviceCode: 'C', monitoringState: 'ONLINE', tags: [] },
|
|
|
+ { deviceCode: 'D', monitoringState: 'ONLINE' },
|
|
|
+ ],
|
|
|
+ }
|
|
|
+ const domain = toMonitoringOverview(raw)
|
|
|
+ assert.deepEqual(domain.devices.map((device) => device.tags), [['ALARM'], ['ALARM', 'WARNING'], [], []],
|
|
|
+ '缺失 tags 必须落空数组,而不是 undefined')
|
|
|
+
|
|
|
+ const { counts } = deviceStatusStats(domain.devices)
|
|
|
+ assert.equal(counts.ALARM, 2)
|
|
|
+ assert.equal(counts.WARNING, 1)
|
|
|
+ assert.equal(counts.NORMAL, 3)
|
|
|
+ assert.equal(counts.OFFLINE, 1)
|
|
|
+})
|