| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130 |
- /**
- * #131 通用点位定位回归:设备/监测点/事件回联都从 `pointLocateStore.locateTarget` 进入;
- * 工单行保留 deviceCode 供定位按钮使用。
- */
- import assert from 'node:assert/strict'
- import { test } from 'node:test'
- import { createPinia, setActivePinia } from 'pinia'
- import { usePointLocateStore } from '../src/modules/cockpit/stores/pointLocateStore.js'
- import { workOrderRows } from '../src/modules/cockpit/domain/equipmentDetailView.js'
- import { planModeLayers } from '../src/modules/cockpit/domain/modeLayerPlan.js'
- const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' }
- const device = {
- kind: 'unassociated-equipment',
- code: 'DEV-131',
- name: '测试设备',
- status: 'ALARM',
- longitude: 110.410194,
- latitude: 28.445044,
- coordinate,
- }
- const point = {
- kind: 'monitoring-point',
- code: 'MP-131',
- name: '测试点位',
- status: 'ALARM',
- deviceCodes: ['DEV-131'],
- longitude: device.longitude,
- latitude: device.latitude,
- coordinate,
- }
- test('设备定位:走完整视角、打开设备详情并写揭示目标', async () => {
- setActivePinia(createPinia())
- const locator = usePointLocateStore()
- const calls = { fly: [], openDevice: [] }
- const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
- objects: [device],
- mapReady: true,
- flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
- openDevice: async (code, options) => { calls.openDevice.push({ code, options }) },
- })
- assert.equal(result.result, 'ok')
- assert.equal(calls.fly.length, 1)
- assert.equal(calls.fly[0].object.code, 'DEV-131')
- assert.deepEqual(calls.openDevice[0], { code: 'DEV-131', options: { locateTarget: { code: 'DEV-131', deviceCode: '' } } })
- })
- test('关联设备定位:越过宿主点位飞到设备自身坐标,再进设备级', async () => {
- setActivePinia(createPinia())
- const locator = usePointLocateStore()
- const calls = { fly: [], openPoint: [], selectDevice: [] }
- const deviceTarget = {
- kind: 'monitoring-device',
- code: 'DEV-131',
- name: '测试设备',
- status: 'NORMAL',
- longitude: device.longitude,
- latitude: device.latitude,
- coordinate,
- }
- const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
- objects: [point],
- mapReady: true,
- device: deviceTarget,
- flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
- openPoint: async (code, options) => { calls.openPoint.push({ code, options }) },
- selectDevice: async (code, options) => { calls.selectDevice.push({ code, options }) },
- })
- assert.equal(result.result, 'ok')
- assert.equal(calls.fly[0].object.code, 'DEV-131', '应飞设备自身坐标,而不是宿主点位')
- assert.equal(calls.fly[0].options.tier, 'device')
- assert.deepEqual(calls.openPoint[0], { code: 'MP-131', options: undefined })
- assert.equal(calls.selectDevice[0].code, 'DEV-131')
- assert.equal(calls.selectDevice[0].options.locateTarget.code, 'MP-131')
- assert.equal(calls.selectDevice[0].options.locateTarget.deviceCode, 'DEV-131')
- assert.deepEqual(calls.selectDevice[0].options.locateTarget.device, deviceTarget)
- })
- test('事件回联:走完整视角飞行 + 高亮,不再只换中心', async () => {
- setActivePinia(createPinia())
- const locator = usePointLocateStore()
- const calls = { fly: [], highlight: [] }
- const event = { code: 'E-131', deviceCode: 'DEV-131', monitoringPointCode: null, coordinate: { validated: true, renderable: true } }
- const result = await locator.locateTarget({ kind: 'event', event }, {
- objects: [device],
- mapReady: true,
- flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
- highlight: (codes) => { calls.highlight.push(codes); return 1 },
- })
- assert.equal(result.result, 'ok')
- assert.equal(calls.fly.length, 1)
- assert.equal(calls.fly[0].object.code, 'DEV-131')
- assert.ok(calls.highlight[0].includes('DEV-131'))
- })
- test('工单行保留设备编码,供工单卡定位按钮使用', () => {
- const rows = workOrderRows([{ code: 'WO-131', deviceName: '测试设备', deviceCode: 'DEV-131', stateCode: 3 }])
- assert.equal(rows[0].deviceCode, 'DEV-131')
- assert.ok(rows[0].deviceLabel.includes('DEV-131'))
- })
- test('关联设备 NORMAL:定位揭示必须让详情越过模式暂停', () => {
- const host = {
- kind: 'monitoring-point',
- code: 'MP-131',
- name: '测试点位',
- status: 'NORMAL',
- deviceCodes: ['DEV-131'],
- longitude: device.longitude,
- latitude: device.latitude,
- coordinate,
- }
- const row = { code: 'DEV-131', pointCode: 'MP-131', status: 'NORMAL', placement: 'drawn' }
- const selection = { level: 'equipment', pointCode: 'MP-131', deviceCode: 'DEV-131' }
- const base = {
- mode: 'warningResponse',
- objects: [host],
- abnormalDevices: [],
- deviceFacts: [{ deviceCode: 'DEV-131', base: 'NORMAL', tags: [] }],
- associatedDevices: [row],
- selection,
- entered: true,
- }
- assert.equal(planModeLayers(base).selection.visible, false, '未定位时 NORMAL 关联设备在预警处置应暂停')
- const located = planModeLayers({ ...base, locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' } })
- assert.ok(located.markers.some((marker) => marker.code === 'MP-131'), '定位揭示应把宿主点位标记临时放行')
- assert.equal(located.selection.visible, true, '定位揭示必须让 NORMAL 关联设备的详情可见')
- })
|