point-locate.test.js 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /**
  2. * #131 通用点位定位回归:设备/监测点/事件回联都从 `pointLocateStore.locateTarget` 进入;
  3. * 工单行保留 deviceCode 供定位按钮使用。
  4. */
  5. import assert from 'node:assert/strict'
  6. import { test } from 'node:test'
  7. import { createPinia, setActivePinia } from 'pinia'
  8. import { usePointLocateStore } from '../src/modules/cockpit/stores/pointLocateStore.js'
  9. import { useDetailStore } from '../src/modules/cockpit/stores/detailStore.js'
  10. import { workOrderRows } from '../src/modules/cockpit/domain/equipmentDetailView.js'
  11. import { planModeLayers } from '../src/modules/cockpit/domain/modeLayerPlan.js'
  12. const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' }
  13. const device = {
  14. kind: 'unassociated-equipment',
  15. code: 'DEV-131',
  16. name: '测试设备',
  17. status: 'ALARM',
  18. longitude: 110.410194,
  19. latitude: 28.445044,
  20. coordinate,
  21. }
  22. const point = {
  23. kind: 'monitoring-point',
  24. code: 'MP-131',
  25. name: '测试点位',
  26. status: 'ALARM',
  27. industry: 'DRAINAGE',
  28. deviceCodes: ['DEV-131'],
  29. longitude: device.longitude,
  30. latitude: device.latitude,
  31. coordinate,
  32. }
  33. test('设备定位:走完整视角、打开设备详情并写揭示目标', async () => {
  34. setActivePinia(createPinia())
  35. const locator = usePointLocateStore()
  36. const calls = { fly: [], openDevice: [] }
  37. const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
  38. objects: [device],
  39. mapReady: true,
  40. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  41. openDevice: async (code, options) => { calls.openDevice.push({ code, options }) },
  42. })
  43. assert.equal(result.result, 'ok')
  44. assert.equal(calls.fly.length, 1)
  45. assert.equal(calls.fly[0].object.code, 'DEV-131')
  46. // 独立设备:detail 仍然按设备编码打开;揭示目标带上设备行本身(deviceCode 保持空,
  47. // 由 modeLayerPlan 区分「关联设备」与「独立设备」,设备图层用 code + device 行揭示)。
  48. assert.equal(calls.openDevice[0].code, 'DEV-131')
  49. assert.equal(calls.openDevice[0].options.locateTarget.code, 'DEV-131')
  50. assert.equal(calls.openDevice[0].options.locateTarget.deviceCode, '')
  51. assert.equal(calls.openDevice[0].options.locateTarget.device.code, 'DEV-131')
  52. })
  53. test('关联设备定位:越过宿主点位飞到设备自身坐标,再进设备级', async () => {
  54. setActivePinia(createPinia())
  55. const locator = usePointLocateStore()
  56. const calls = { fly: [], openPoint: [], selectDevice: [] }
  57. const deviceTarget = {
  58. kind: 'monitoring-device',
  59. code: 'DEV-131',
  60. name: '测试设备',
  61. typeName: '环境监测终端(污水)',
  62. industry: 'DRAINAGE',
  63. status: 'NORMAL',
  64. longitude: device.longitude,
  65. latitude: device.latitude,
  66. coordinate,
  67. }
  68. const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
  69. objects: [point],
  70. mapReady: true,
  71. device: deviceTarget,
  72. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  73. openPoint: async (code, options) => { calls.openPoint.push({ code, options }) },
  74. selectDevice: async (code, options) => { calls.selectDevice.push({ code, options }) },
  75. })
  76. assert.equal(result.result, 'ok')
  77. assert.equal(calls.fly[0].object.code, 'DEV-131', '应飞设备自身坐标,而不是宿主点位')
  78. assert.equal(calls.fly[0].options.tier, 'device')
  79. assert.deepEqual(calls.openPoint[0], { code: 'MP-131', options: undefined })
  80. assert.equal(calls.selectDevice[0].code, 'DEV-131')
  81. assert.equal(calls.selectDevice[0].options.locateTarget.code, 'MP-131')
  82. assert.equal(calls.selectDevice[0].options.locateTarget.deviceCode, 'DEV-131')
  83. assert.equal(calls.selectDevice[0].options.locateTarget.device.industry, 'DRAINAGE')
  84. assert.deepEqual(calls.selectDevice[0].options.locateTarget.device, deviceTarget)
  85. })
  86. test('关联设备卡没有 industry 时继承点位,类型徽标不空', async () => {
  87. setActivePinia(createPinia())
  88. const detail = useDetailStore()
  89. detail.setSection('pointDetail', {
  90. state: 'success',
  91. data: {
  92. code: 'MP-131',
  93. devices: [{
  94. code: 'DEV-131',
  95. name: '测试设备',
  96. typeName: '环境监测终端(污水)',
  97. status: 'NORMAL',
  98. longitude: device.longitude,
  99. latitude: device.latitude,
  100. coordinate,
  101. }],
  102. },
  103. })
  104. const locator = usePointLocateStore()
  105. let flown = null
  106. const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
  107. objects: [point],
  108. mapReady: true,
  109. openPoint: async () => {},
  110. flyPoint: async (object) => { flown = object; return true },
  111. selectDevice: async () => {},
  112. })
  113. assert.equal(result.result, 'ok')
  114. assert.equal(flown.code, 'DEV-131')
  115. assert.equal(flown.industry, 'DRAINAGE', '设备卡无 industry 时必须继承点位行业')
  116. assert.equal(flown.typeName, '环境监测终端(污水)')
  117. })
  118. test('事件回联:走完整视角飞行 + 高亮,不再只换中心', async () => {
  119. setActivePinia(createPinia())
  120. const locator = usePointLocateStore()
  121. const calls = { fly: [], highlight: [] }
  122. const event = { code: 'E-131', deviceCode: 'DEV-131', monitoringPointCode: null, coordinate: { validated: true, renderable: true } }
  123. const result = await locator.locateTarget({ kind: 'event', event }, {
  124. objects: [device],
  125. mapReady: true,
  126. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  127. highlight: (codes) => { calls.highlight.push(codes); return 1 },
  128. })
  129. assert.equal(result.result, 'ok')
  130. assert.equal(calls.fly.length, 1)
  131. assert.equal(calls.fly[0].object.code, 'DEV-131')
  132. assert.ok(calls.highlight[0].includes('DEV-131'))
  133. })
  134. test('工单行保留设备编码,供工单卡定位按钮使用', () => {
  135. const rows = workOrderRows([{ code: 'WO-131', deviceName: '测试设备', deviceCode: 'DEV-131', stateCode: 3 }])
  136. assert.equal(rows[0].deviceCode, 'DEV-131')
  137. assert.ok(rows[0].deviceLabel.includes('DEV-131'))
  138. })
  139. test('关联设备 NORMAL:定位揭示必须让详情越过模式暂停', () => {
  140. const host = {
  141. kind: 'monitoring-point',
  142. code: 'MP-131',
  143. name: '测试点位',
  144. status: 'NORMAL',
  145. deviceCodes: ['DEV-131'],
  146. longitude: device.longitude,
  147. latitude: device.latitude,
  148. coordinate,
  149. }
  150. const row = { code: 'DEV-131', pointCode: 'MP-131', status: 'NORMAL', placement: 'drawn' }
  151. const selection = { level: 'equipment', pointCode: 'MP-131', deviceCode: 'DEV-131' }
  152. const base = {
  153. mode: 'warningResponse',
  154. objects: [host],
  155. abnormalDevices: [],
  156. deviceFacts: [{ deviceCode: 'DEV-131', base: 'NORMAL', tags: [] }],
  157. associatedDevices: [row],
  158. selection,
  159. entered: true,
  160. }
  161. assert.equal(planModeLayers(base).selection.visible, false, '未定位时 NORMAL 关联设备在预警处置应暂停')
  162. const located = planModeLayers({ ...base, locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' } })
  163. assert.equal(located.markers.some((marker) => marker.code === 'MP-131'), false, '不应强行补宿主点位标记(会盖住设备图标)')
  164. assert.equal(located.selection.visible, true, '定位揭示必须让 NORMAL 关联设备的详情可见')
  165. // 即使宿主点位本身在预警处置可见(ALARM),定位设备期间也要让位,避免点图标盖住设备图标。
  166. const attentionLocated = planModeLayers({
  167. ...base,
  168. objects: [{ ...host, status: 'ALARM' }],
  169. locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' },
  170. })
  171. assert.equal(attentionLocated.markers.some((marker) => marker.code === 'MP-131'), false, '定位设备时应隐藏宿主点位标记')
  172. assert.equal(attentionLocated.selection.visible, true)
  173. })