/** * 定位计划闸门(#13 收尾重构): * 一次定位最终都落成三件事 —— ① 相机到目标坐标 ② 目标点可见(揭示)③ 详情面板展开。 * 本测试钉住**计划层**对三种目标的判定,执行侧(pointLocateStore)只按计划做事。 */ import assert from 'node:assert/strict' import { test } from 'node:test' import { DETAIL_STEP, planMapObjectLocate } from '../src/modules/cockpit/domain/locateSteps.js' const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' } const point = { kind: 'monitoring-point', code: 'MP-T', name: '测试点位', status: 'NORMAL', industry: 'DRAINAGE', deviceCodes: ['DEV-A'], longitude: 110.4, latitude: 28.4, coordinate, } const independent = { kind: 'unassociated-equipment', code: 'DEV-FREE', name: '独立设备', status: 'NORMAL', longitude: 110.41, latitude: 28.41, coordinate, } test('监测点:飞到点位档、开点位级详情、揭示点位自身', () => { const plan = planMapObjectLocate({ code: 'MP-T', objects: [point], mapReady: true }) assert.equal(plan.result, 'ok') assert.equal(plan.cameraTier, '', '点位按点位档(不带 device 档)') assert.equal(plan.needsDevice, false, '点位不需要解析设备行') assert.deepEqual(plan.open, { level: DETAIL_STEP.POINT, pointCode: 'MP-T', deviceCode: '' }) assert.deepEqual(plan.reveal, { code: 'MP-T', deviceCode: '' }) }) test('关联设备:越过宿主点位飞设备档、开设备级详情(保留宿主点位)、揭示宿主+设备', () => { const plan = planMapObjectLocate({ code: 'DEV-A', objects: [point], mapReady: true }) assert.equal(plan.result, 'ok') assert.equal(plan.cameraTier, 'device') assert.equal(plan.needsDevice, true, '关联设备坐标要先去设备卡/档案解析') assert.equal(plan.devicePointCode, 'MP-T', '解析设备时要知道宿主点位') assert.deepEqual(plan.open, { level: DETAIL_STEP.DEVICE, pointCode: 'MP-T', deviceCode: 'DEV-A' }) assert.deepEqual(plan.reveal, { code: 'MP-T', deviceCode: 'DEV-A' }) }) test('未关联设备:它自己就是相机目标与揭示来源,设备级的点位编码为空', () => { const plan = planMapObjectLocate({ code: 'DEV-FREE', objects: [independent], mapReady: true }) assert.equal(plan.result, 'ok') assert.equal(plan.cameraTier, 'device') assert.equal(plan.needsDevice, true) assert.equal(plan.devicePointCode, '') assert.deepEqual(plan.open, { level: DETAIL_STEP.DEVICE, pointCode: '', deviceCode: 'DEV-FREE' }) assert.deepEqual(plan.reveal, { code: 'DEV-FREE', deviceCode: '' }) }) test('目标不在摘要里:保留原因,并给出「退设备档案取坐标」的计划', () => { const plan = planMapObjectLocate({ code: 'DEV-NOT-LOADED', objects: [point], mapReady: true }) assert.equal(plan.result, 'missing') assert.equal(plan.archiveCode, 'DEV-NOT-LOADED', '执行侧据此去设备档案兜底') assert.equal(plan.open, null, '计划层不假装能开详情') assert.equal(plan.reveal, null) }) test('地图未就绪:结果如实为不可用,不改判定为可定位', () => { const plan = planMapObjectLocate({ code: 'MP-T', objects: [point], mapReady: false }) assert.equal(plan.result, 'unavailable') assert.equal(plan.open, null) assert.equal(plan.needsDevice, true) })