t13-locate-reveal.test.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /**
  2. * #13 回归:定位揭示目标由**选择**派生、揭示行必须发布到地图服务、
  3. * 独立设备的详情锚点必须认设备图层标记。
  4. *
  5. * 这三条分别对应 .scratch/cockpit-emergency-detail/research/13-locate-reveal-and-anchor.md
  6. * 里的根因 A / B / C,都是纯逻辑可断言的,不依赖网络与浏览器。
  7. */
  8. import assert from 'node:assert/strict'
  9. import { after, test } from 'node:test'
  10. import { createPinia, setActivePinia } from 'pinia'
  11. import { deriveLocateReveal } from '../src/modules/cockpit/domain/locateReveal.js'
  12. import { mergeRevealRow } from '../src/modules/cockpit/domain/deviceLayer.js'
  13. import { resolveDetailAnchor } from '../src/modules/cockpit/domain/detailAnchor.js'
  14. import { planModeLayers, MODE_LAYER } from '../src/modules/cockpit/domain/modeLayerPlan.js'
  15. import { __setInstanceForTest } from '../src/modules/cockpit/services/mapService.js'
  16. import { useDeviceLayerStore } from '../src/modules/cockpit/stores/deviceLayerStore.js'
  17. const DEVICE_CODE = '2607230190000022'
  18. const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' }
  19. /** 独立设备:出现在地图摘要里,自己是地图对象(没有宿主监测点)。 */
  20. const independent = {
  21. kind: 'unassociated-equipment',
  22. code: DEVICE_CODE,
  23. name: '可燃气体-022',
  24. status: 'NORMAL',
  25. industry: 'GAS',
  26. longitude: 110.361206,
  27. latitude: 28.45557,
  28. coordinate,
  29. }
  30. const equipmentSelection = { level: 'equipment', pointCode: '', deviceCode: DEVICE_CODE }
  31. const pointCode = 'MP-T13'
  32. const pointSelection = { level: 'equipment', pointCode, deviceCode: 'DEV-T13' }
  33. const pointDetail = { code: pointCode, industry: 'DRAINAGE', devices: [{ code: 'DEV-T13', name: '排水设备', status: 'NORMAL', longitude: 110.4, latitude: 28.4 }] }
  34. after(() => __setInstanceForTest(null))
  35. test('揭示目标:独立设备由选择派生,取摘要里的自身坐标', () => {
  36. const reveal = deriveLocateReveal({ selection: equipmentSelection, objects: [independent] })
  37. assert.ok(reveal, '设备级选择应派生揭示目标')
  38. assert.equal(reveal.code, DEVICE_CODE)
  39. assert.equal(reveal.deviceCode, '', '独立设备的 deviceCode 留空(与 #131 同一口径)')
  40. assert.equal(reveal.device.longitude, independent.longitude)
  41. assert.equal(reveal.device.latitude, independent.latitude)
  42. })
  43. test('揭示目标:关联设备由点位设备卡派生,行业继承点位', () => {
  44. const reveal = deriveLocateReveal({ selection: pointSelection, pointDetail })
  45. assert.ok(reveal)
  46. assert.equal(reveal.code, pointCode, '关联设备的 code 仍是宿主点位')
  47. assert.equal(reveal.deviceCode, 'DEV-T13')
  48. assert.equal(reveal.device.industry, 'DRAINAGE', '设备卡没有 industry 时继承点位(#135)')
  49. })
  50. test('类型徽标不复发(#135):点位详情没给 industry 时继承摘要里的宿主点位', () => {
  51. const hostPoint = {
  52. kind: 'monitoring-point',
  53. code: pointCode,
  54. name: '城北排水监测点01',
  55. industry: 'DRAINAGE',
  56. deviceCodes: ['DEV-T13'],
  57. longitude: 110.4,
  58. latitude: 28.4,
  59. coordinate,
  60. }
  61. // 真实数据形态:点位详情不带 industry,设备卡也不带(契约如此)。
  62. const detailWithoutIndustry = { code: pointCode, devices: [{ code: 'DEV-T13', name: '排水设备', longitude: 110.4, latitude: 28.4 }] }
  63. const reveal = deriveLocateReveal({ selection: pointSelection, objects: [hostPoint], pointDetail: detailWithoutIndustry })
  64. assert.ok(reveal)
  65. assert.equal(reveal.device.industry, 'DRAINAGE', '行业必须继承摘要里的宿主点位,否则图标中心徽标为空')
  66. })
  67. test('类型徽标不复发(#135):揭示行缺可视字段时从被顶掉的计划行继承', () => {
  68. const forced = { code: DEVICE_CODE, pointCode: DEVICE_CODE, industry: '', typeName: '', placement: 'drawn' }
  69. const replaced = { code: DEVICE_CODE, pointCode: 'MP-T13', industry: 'GAS', typeName: '可燃气体检测终端', placement: 'hidden' }
  70. const merged = mergeRevealRow(forced, replaced)
  71. assert.equal(merged.industry, 'GAS', '隐含行业不能让揭示行把带徽标的行换成空徽标')
  72. assert.equal(merged.typeName, '可燃气体检测终端')
  73. assert.equal(merged.placement, 'drawn', '揭示行自己的可上图事实不能被覆盖')
  74. // 揭示行自带行业时以它为准;没有被顶掉的行时原样返回。
  75. assert.equal(mergeRevealRow({ ...forced, industry: 'WATER_SUPPLY' }, replaced).industry, 'WATER_SUPPLY')
  76. assert.equal(mergeRevealRow(forced, null).industry, '')
  77. })
  78. test('揭示目标:选择关闭 / 非设备级 / 无坐标都不派生', () => {
  79. assert.equal(deriveLocateReveal({ selection: { level: 'none', pointCode: '', deviceCode: '' }, objects: [independent] }), null)
  80. assert.equal(deriveLocateReveal({ selection: { level: 'point', pointCode: 'MP-1', deviceCode: '' }, objects: [independent] }), null)
  81. assert.equal(deriveLocateReveal({ selection: equipmentSelection, objects: [] }), null)
  82. const noCoordinate = { ...independent, longitude: null }
  83. assert.equal(deriveLocateReveal({ selection: equipmentSelection, objects: [noCoordinate] }), null)
  84. })
  85. test('锚点:独立设备优先认设备图层揭示行,没有行才退回摘要标记', () => {
  86. const revealRow = {
  87. code: DEVICE_CODE,
  88. pointCode: DEVICE_CODE,
  89. longitude: independent.longitude,
  90. latitude: independent.latitude,
  91. coordinate,
  92. placement: 'drawn',
  93. }
  94. const anchored = resolveDetailAnchor({
  95. selection: equipmentSelection,
  96. objects: [independent],
  97. devices: [revealRow],
  98. })
  99. assert.equal(anchored.kind, 'monitoring-device', '揭示行是设备图层标记,锚点必须同一族')
  100. assert.equal(anchored.code, DEVICE_CODE)
  101. assert.equal(anchored.pointCode, DEVICE_CODE)
  102. const fallback = resolveDetailAnchor({ selection: equipmentSelection, objects: [independent], devices: [] })
  103. assert.equal(fallback.kind, 'unassociated-equipment', '没有揭示行时保持原口径')
  104. })
  105. test('设备级可见性:独立设备的揭示行不会被误判成"宿主点位缺失的关联设备"', () => {
  106. const revealRow = {
  107. code: DEVICE_CODE,
  108. pointCode: DEVICE_CODE,
  109. status: 'NORMAL',
  110. longitude: independent.longitude,
  111. latitude: independent.latitude,
  112. coordinate,
  113. placement: 'drawn',
  114. }
  115. const plan = planModeLayers({
  116. mode: MODE_LAYER.OVERVIEW,
  117. objects: [independent],
  118. abnormalDevices: [],
  119. associatedDevices: [revealRow],
  120. deviceFilter: null,
  121. deviceFacts: null,
  122. locateTarget: null,
  123. selection: equipmentSelection,
  124. entered: true,
  125. })
  126. assert.equal(plan.selection.visible, true, '揭示行的 pointCode 不是宿主点位,不该让面板整体隐藏')
  127. })
  128. test('揭示行必须发布到地图服务(只写 store 不发布 = 图标永远不出现)', () => {
  129. setActivePinia(createPinia())
  130. const published = []
  131. __setInstanceForTest({
  132. viewer: {},
  133. host: null,
  134. engine: {
  135. syncAssociatedDevices(viewer, devices) {
  136. published.push(devices)
  137. return { rendered: devices.length, skipped: 0 }
  138. },
  139. applyDeviceReactions() {},
  140. applyDeviceEffects() { return false },
  141. clearDeviceLead() {},
  142. syncDeviceLead() { return true },
  143. },
  144. })
  145. const store = useDeviceLayerStore()
  146. const result = store.syncForSelection({
  147. revealDevice: { code: DEVICE_CODE, deviceCode: '', device: independent },
  148. })
  149. assert.equal(published.length, 1, '揭示行必须交给地图服务')
  150. assert.equal(published[0].length, 1)
  151. assert.equal(published[0][0].code, DEVICE_CODE)
  152. assert.equal(published[0][0].placement, 'drawn')
  153. assert.equal(store.rows.length, 1)
  154. assert.equal(result.total, 1)
  155. assert.equal(result.drawn, 1)
  156. __setInstanceForTest(null)
  157. })