point-locate.test.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. assert.deepEqual(calls.openDevice[0], { code: 'DEV-131', options: { locateTarget: { code: 'DEV-131', deviceCode: '' } } })
  47. })
  48. test('关联设备定位:越过宿主点位飞到设备自身坐标,再进设备级', async () => {
  49. setActivePinia(createPinia())
  50. const locator = usePointLocateStore()
  51. const calls = { fly: [], openPoint: [], selectDevice: [] }
  52. const deviceTarget = {
  53. kind: 'monitoring-device',
  54. code: 'DEV-131',
  55. name: '测试设备',
  56. typeName: '环境监测终端(污水)',
  57. industry: 'DRAINAGE',
  58. status: 'NORMAL',
  59. longitude: device.longitude,
  60. latitude: device.latitude,
  61. coordinate,
  62. }
  63. const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
  64. objects: [point],
  65. mapReady: true,
  66. device: deviceTarget,
  67. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  68. openPoint: async (code, options) => { calls.openPoint.push({ code, options }) },
  69. selectDevice: async (code, options) => { calls.selectDevice.push({ code, options }) },
  70. })
  71. assert.equal(result.result, 'ok')
  72. assert.equal(calls.fly[0].object.code, 'DEV-131', '应飞设备自身坐标,而不是宿主点位')
  73. assert.equal(calls.fly[0].options.tier, 'device')
  74. assert.deepEqual(calls.openPoint[0], { code: 'MP-131', options: undefined })
  75. assert.equal(calls.selectDevice[0].code, 'DEV-131')
  76. assert.equal(calls.selectDevice[0].options.locateTarget.code, 'MP-131')
  77. assert.equal(calls.selectDevice[0].options.locateTarget.deviceCode, 'DEV-131')
  78. assert.equal(calls.selectDevice[0].options.locateTarget.device.industry, 'DRAINAGE')
  79. assert.deepEqual(calls.selectDevice[0].options.locateTarget.device, deviceTarget)
  80. })
  81. test('关联设备卡没有 industry 时继承点位,类型徽标不空', async () => {
  82. setActivePinia(createPinia())
  83. const detail = useDetailStore()
  84. detail.setSection('pointDetail', {
  85. state: 'success',
  86. data: {
  87. code: 'MP-131',
  88. devices: [{
  89. code: 'DEV-131',
  90. name: '测试设备',
  91. typeName: '环境监测终端(污水)',
  92. status: 'NORMAL',
  93. longitude: device.longitude,
  94. latitude: device.latitude,
  95. coordinate,
  96. }],
  97. },
  98. })
  99. const locator = usePointLocateStore()
  100. let flown = null
  101. const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
  102. objects: [point],
  103. mapReady: true,
  104. openPoint: async () => {},
  105. flyPoint: async (object) => { flown = object; return true },
  106. selectDevice: async () => {},
  107. })
  108. assert.equal(result.result, 'ok')
  109. assert.equal(flown.code, 'DEV-131')
  110. assert.equal(flown.industry, 'DRAINAGE', '设备卡无 industry 时必须继承点位行业')
  111. assert.equal(flown.typeName, '环境监测终端(污水)')
  112. })
  113. test('事件回联:走完整视角飞行 + 高亮,不再只换中心', async () => {
  114. setActivePinia(createPinia())
  115. const locator = usePointLocateStore()
  116. const calls = { fly: [], highlight: [] }
  117. const event = { code: 'E-131', deviceCode: 'DEV-131', monitoringPointCode: null, coordinate: { validated: true, renderable: true } }
  118. const result = await locator.locateTarget({ kind: 'event', event }, {
  119. objects: [device],
  120. mapReady: true,
  121. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  122. highlight: (codes) => { calls.highlight.push(codes); return 1 },
  123. })
  124. assert.equal(result.result, 'ok')
  125. assert.equal(calls.fly.length, 1)
  126. assert.equal(calls.fly[0].object.code, 'DEV-131')
  127. assert.ok(calls.highlight[0].includes('DEV-131'))
  128. })
  129. test('工单行保留设备编码,供工单卡定位按钮使用', () => {
  130. const rows = workOrderRows([{ code: 'WO-131', deviceName: '测试设备', deviceCode: 'DEV-131', stateCode: 3 }])
  131. assert.equal(rows[0].deviceCode, 'DEV-131')
  132. assert.ok(rows[0].deviceLabel.includes('DEV-131'))
  133. })
  134. test('关联设备 NORMAL:定位揭示必须让详情越过模式暂停', () => {
  135. const host = {
  136. kind: 'monitoring-point',
  137. code: 'MP-131',
  138. name: '测试点位',
  139. status: 'NORMAL',
  140. deviceCodes: ['DEV-131'],
  141. longitude: device.longitude,
  142. latitude: device.latitude,
  143. coordinate,
  144. }
  145. const row = { code: 'DEV-131', pointCode: 'MP-131', status: 'NORMAL', placement: 'drawn' }
  146. const selection = { level: 'equipment', pointCode: 'MP-131', deviceCode: 'DEV-131' }
  147. const base = {
  148. mode: 'warningResponse',
  149. objects: [host],
  150. abnormalDevices: [],
  151. deviceFacts: [{ deviceCode: 'DEV-131', base: 'NORMAL', tags: [] }],
  152. associatedDevices: [row],
  153. selection,
  154. entered: true,
  155. }
  156. assert.equal(planModeLayers(base).selection.visible, false, '未定位时 NORMAL 关联设备在预警处置应暂停')
  157. const located = planModeLayers({ ...base, locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' } })
  158. assert.equal(located.markers.some((marker) => marker.code === 'MP-131'), false, '不应强行补宿主点位标记(会盖住设备图标)')
  159. assert.equal(located.selection.visible, true, '定位揭示必须让 NORMAL 关联设备的详情可见')
  160. // 即使宿主点位本身在预警处置可见(ALARM),定位设备期间也要让位,避免点图标盖住设备图标。
  161. const attentionLocated = planModeLayers({
  162. ...base,
  163. objects: [{ ...host, status: 'ALARM' }],
  164. locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' },
  165. })
  166. assert.equal(attentionLocated.markers.some((marker) => marker.code === 'MP-131'), false, '定位设备时应隐藏宿主点位标记')
  167. assert.equal(attentionLocated.selection.visible, true)
  168. })