| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import assert from 'node:assert/strict'
- import { createPinia, setActivePinia } from 'pinia'
- import { planPipeEnhancement } from '../../../src/modules/cockpit/domain/pipeEnhancement.js'
- import { planEnhancementDevices } from '../../../src/modules/cockpit/domain/enhancementDevices.js'
- import { useEnhancementDevicesStore } from '../../../src/modules/cockpit/stores/enhancementDevicesStore.js'
- const pipe = { code: 'P', networkId: 'real-id', industry: 'WATER_SUPPLY', positions: [[110, 28], [110.001, 28]] }
- const plan = planPipeEnhancement({ selected: { kind: 'pipe', code: 'P' }, visiblePipes: [pipe] })
- const base = { industry: 'WATER_SUPPLY', longitude: 110.0005, latitude: 28.0001, coordinate: { renderable: true } }
- const rows = [{ ...base, code: 'near' }, { ...base, code: 'linked', networkId: 'real-id' },
- { ...base, code: 'wrong-id', networkId: 'P' }, { ...base, code: 'no-position', longitude: null },
- { ...base, code: 'gas', industry: 'GAS' }, { ...base, code: 'denied', coordinate: { renderable: false } }]
- const original = JSON.stringify(rows)
- const result = planEnhancementDevices(plan, rows)
- assert.equal(result.devices.find((d) => d.code === 'linked').placement, 'linked')
- assert.equal(result.devices.find((d) => d.code === 'wrong-id').placement, 'nearby')
- assert.equal(result.devices.find((d) => d.code === 'near').placementText, '邻近设备 · 示意安装')
- assert.equal(result.devices.find((d) => d.code === 'gas').placement, 'standalone')
- assert.equal(result.deviceList.find((d) => d.code === 'no-position').placement, 'list-only')
- assert.ok(!result.devices.some((d) => d.code === 'denied'))
- assert.equal(new Set(result.devices.filter((d) => d.pipeCode === 'P').map((d) => d.slot)).size, 3)
- assert.equal(JSON.stringify(rows), original)
- setActivePinia(createPinia())
- const store = useEnhancementDevicesStore()
- let finishA
- const a = store.open({ code: 'A' }, { fetchDetail: () => new Promise((resolve) => { finishA = resolve }) })
- await store.open({ code: 'B' }, { fetchDetail: async () => ({ state: 'success', data: { deviceCode: 'B', sections: {} } }) })
- finishA({ state: 'success', data: { deviceCode: 'A', sections: {} } })
- await a
- assert.equal(store.aggregate.data.deviceCode, 'B')
- assert.equal(store.selected.code, 'B')
- store.clear()
- assert.equal(store.aggregate, null)
- assert.equal(store.selected, null)
- let finishOutside
- const pending = store.open({ code: 'outside' }, { fetchDetail: () => new Promise((resolve) => { finishOutside = resolve }) })
- store.reconcile([])
- finishOutside({ state: 'success', data: { deviceCode: 'outside' } })
- await pending
- assert.equal(store.selected, null)
- assert.equal(store.aggregate, null)
- store.invalidate()
- assert.equal(store.source.loading, true)
- assert.deepEqual(store.source.rows, [])
- assert.equal(planEnhancementDevices(plan, rows, { mode: 'infrastructure' }).devices.length, 0)
- const alertRows = [{ ...base, code: 'ok', status: 'NORMAL' }, { ...base, code: 'alarm', status: 'ALARM' }]
- const warnings = planEnhancementDevices(plan, alertRows, { mode: 'warningResponse', abnormalDevices: [{ code: 'alarm', status: 'ALARM' }] })
- assert.deepEqual(warnings.devices.map((d) => d.code), ['alarm'])
- const linkedManhole = planEnhancementDevices(plan, [{ ...base, industry: 'MANHOLE', code: 'MH-device', networkId: 'real-id', longitude: null }])
- assert.equal(linkedManhole.devices[0].placement, 'linked')
- console.log('PASS 范围移除取消详情/在途响应、刷新失效、模式过滤及真实跨行业关联')
- console.log('PASS 真实ID关联优先、邻近示意、无位置清单、行业分离、不改源及内部详情旧响应隔离')
|