/** * #13 回归:定位揭示目标由**选择**派生、揭示行必须发布到地图服务、 * 独立设备的详情锚点必须认设备图层标记。 * * 这三条分别对应 .scratch/cockpit-emergency-detail/research/13-locate-reveal-and-anchor.md * 里的根因 A / B / C,都是纯逻辑可断言的,不依赖网络与浏览器。 */ import assert from 'node:assert/strict' import { after, test } from 'node:test' import { createPinia, setActivePinia } from 'pinia' import { deriveLocateReveal } from '../src/modules/cockpit/domain/locateReveal.js' import { mergeRevealRow } from '../src/modules/cockpit/domain/deviceLayer.js' import { resolveDetailAnchor } from '../src/modules/cockpit/domain/detailAnchor.js' import { planModeLayers, MODE_LAYER } from '../src/modules/cockpit/domain/modeLayerPlan.js' import { __setInstanceForTest } from '../src/modules/cockpit/services/mapService.js' import { useDeviceLayerStore } from '../src/modules/cockpit/stores/deviceLayerStore.js' const DEVICE_CODE = '2607230190000022' const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' } /** 独立设备:出现在地图摘要里,自己是地图对象(没有宿主监测点)。 */ const independent = { kind: 'unassociated-equipment', code: DEVICE_CODE, name: '可燃气体-022', status: 'NORMAL', industry: 'GAS', longitude: 110.361206, latitude: 28.45557, coordinate, } const equipmentSelection = { level: 'equipment', pointCode: '', deviceCode: DEVICE_CODE } const pointCode = 'MP-T13' const pointSelection = { level: 'equipment', pointCode, deviceCode: 'DEV-T13' } const pointDetail = { code: pointCode, industry: 'DRAINAGE', devices: [{ code: 'DEV-T13', name: '排水设备', status: 'NORMAL', longitude: 110.4, latitude: 28.4 }] } after(() => __setInstanceForTest(null)) test('揭示目标:独立设备由选择派生,取摘要里的自身坐标', () => { const reveal = deriveLocateReveal({ selection: equipmentSelection, objects: [independent] }) assert.ok(reveal, '设备级选择应派生揭示目标') assert.equal(reveal.code, DEVICE_CODE) assert.equal(reveal.deviceCode, '', '独立设备的 deviceCode 留空(与 #131 同一口径)') assert.equal(reveal.device.longitude, independent.longitude) assert.equal(reveal.device.latitude, independent.latitude) }) test('揭示目标:关联设备由点位设备卡派生,行业继承点位', () => { const reveal = deriveLocateReveal({ selection: pointSelection, pointDetail }) assert.ok(reveal) assert.equal(reveal.code, pointCode, '关联设备的 code 仍是宿主点位') assert.equal(reveal.deviceCode, 'DEV-T13') assert.equal(reveal.device.industry, 'DRAINAGE', '设备卡没有 industry 时继承点位(#135)') }) test('类型徽标不复发(#135):点位详情没给 industry 时继承摘要里的宿主点位', () => { const hostPoint = { kind: 'monitoring-point', code: pointCode, name: '城北排水监测点01', industry: 'DRAINAGE', deviceCodes: ['DEV-T13'], longitude: 110.4, latitude: 28.4, coordinate, } // 真实数据形态:点位详情不带 industry,设备卡也不带(契约如此)。 const detailWithoutIndustry = { code: pointCode, devices: [{ code: 'DEV-T13', name: '排水设备', longitude: 110.4, latitude: 28.4 }] } const reveal = deriveLocateReveal({ selection: pointSelection, objects: [hostPoint], pointDetail: detailWithoutIndustry }) assert.ok(reveal) assert.equal(reveal.device.industry, 'DRAINAGE', '行业必须继承摘要里的宿主点位,否则图标中心徽标为空') }) test('类型徽标不复发(#135):揭示行缺可视字段时从被顶掉的计划行继承', () => { const forced = { code: DEVICE_CODE, pointCode: DEVICE_CODE, industry: '', typeName: '', placement: 'drawn' } const replaced = { code: DEVICE_CODE, pointCode: 'MP-T13', industry: 'GAS', typeName: '可燃气体检测终端', placement: 'hidden' } const merged = mergeRevealRow(forced, replaced) assert.equal(merged.industry, 'GAS', '隐含行业不能让揭示行把带徽标的行换成空徽标') assert.equal(merged.typeName, '可燃气体检测终端') assert.equal(merged.placement, 'drawn', '揭示行自己的可上图事实不能被覆盖') // 揭示行自带行业时以它为准;没有被顶掉的行时原样返回。 assert.equal(mergeRevealRow({ ...forced, industry: 'WATER_SUPPLY' }, replaced).industry, 'WATER_SUPPLY') assert.equal(mergeRevealRow(forced, null).industry, '') }) test('揭示目标:选择关闭 / 非设备级 / 无坐标都不派生', () => { assert.equal(deriveLocateReveal({ selection: { level: 'none', pointCode: '', deviceCode: '' }, objects: [independent] }), null) assert.equal(deriveLocateReveal({ selection: { level: 'point', pointCode: 'MP-1', deviceCode: '' }, objects: [independent] }), null) assert.equal(deriveLocateReveal({ selection: equipmentSelection, objects: [] }), null) const noCoordinate = { ...independent, longitude: null } assert.equal(deriveLocateReveal({ selection: equipmentSelection, objects: [noCoordinate] }), null) }) test('锚点:独立设备优先认设备图层揭示行,没有行才退回摘要标记', () => { const revealRow = { code: DEVICE_CODE, pointCode: DEVICE_CODE, longitude: independent.longitude, latitude: independent.latitude, coordinate, placement: 'drawn', } const anchored = resolveDetailAnchor({ selection: equipmentSelection, objects: [independent], devices: [revealRow], }) assert.equal(anchored.kind, 'monitoring-device', '揭示行是设备图层标记,锚点必须同一族') assert.equal(anchored.code, DEVICE_CODE) assert.equal(anchored.pointCode, DEVICE_CODE) const fallback = resolveDetailAnchor({ selection: equipmentSelection, objects: [independent], devices: [] }) assert.equal(fallback.kind, 'unassociated-equipment', '没有揭示行时保持原口径') }) test('设备级可见性:独立设备的揭示行不会被误判成"宿主点位缺失的关联设备"', () => { const revealRow = { code: DEVICE_CODE, pointCode: DEVICE_CODE, status: 'NORMAL', longitude: independent.longitude, latitude: independent.latitude, coordinate, placement: 'drawn', } const plan = planModeLayers({ mode: MODE_LAYER.OVERVIEW, objects: [independent], abnormalDevices: [], associatedDevices: [revealRow], deviceFilter: null, deviceFacts: null, locateTarget: null, selection: equipmentSelection, entered: true, }) assert.equal(plan.selection.visible, true, '揭示行的 pointCode 不是宿主点位,不该让面板整体隐藏') }) test('揭示行必须发布到地图服务(只写 store 不发布 = 图标永远不出现)', () => { setActivePinia(createPinia()) const published = [] __setInstanceForTest({ viewer: {}, host: null, engine: { syncAssociatedDevices(viewer, devices) { published.push(devices) return { rendered: devices.length, skipped: 0 } }, applyDeviceReactions() {}, applyDeviceEffects() { return false }, clearDeviceLead() {}, syncDeviceLead() { return true }, }, }) const store = useDeviceLayerStore() const result = store.syncForSelection({ revealDevice: { code: DEVICE_CODE, deviceCode: '', device: independent }, }) assert.equal(published.length, 1, '揭示行必须交给地图服务') assert.equal(published[0].length, 1) assert.equal(published[0][0].code, DEVICE_CODE) assert.equal(published[0][0].placement, 'drawn') assert.equal(store.rows.length, 1) assert.equal(result.total, 1) assert.equal(result.drawn, 1) __setInstanceForTest(null) })