/** * #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' 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 = { openPoint: [], selectDevice: [] } const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, { objects: [point], mapReady: true, flyPoint: async () => 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.deepEqual(calls.openPoint[0], { code: 'MP-131', options: undefined }) assert.deepEqual(calls.selectDevice[0], { code: 'DEV-131', options: { locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' } }, }) }) 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')) })