point-locate.test.js 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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 { workOrderRows } from '../src/modules/cockpit/domain/equipmentDetailView.js'
  10. import { planModeLayers } from '../src/modules/cockpit/domain/modeLayerPlan.js'
  11. const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' }
  12. const device = {
  13. kind: 'unassociated-equipment',
  14. code: 'DEV-131',
  15. name: '测试设备',
  16. status: 'ALARM',
  17. longitude: 110.410194,
  18. latitude: 28.445044,
  19. coordinate,
  20. }
  21. const point = {
  22. kind: 'monitoring-point',
  23. code: 'MP-131',
  24. name: '测试点位',
  25. status: 'ALARM',
  26. deviceCodes: ['DEV-131'],
  27. longitude: device.longitude,
  28. latitude: device.latitude,
  29. coordinate,
  30. }
  31. test('设备定位:走完整视角、打开设备详情并写揭示目标', async () => {
  32. setActivePinia(createPinia())
  33. const locator = usePointLocateStore()
  34. const calls = { fly: [], openDevice: [] }
  35. const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
  36. objects: [device],
  37. mapReady: true,
  38. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  39. openDevice: async (code, options) => { calls.openDevice.push({ code, options }) },
  40. })
  41. assert.equal(result.result, 'ok')
  42. assert.equal(calls.fly.length, 1)
  43. assert.equal(calls.fly[0].object.code, 'DEV-131')
  44. assert.deepEqual(calls.openDevice[0], { code: 'DEV-131', options: { locateTarget: { code: 'DEV-131', deviceCode: '' } } })
  45. })
  46. test('关联设备定位:越过宿主点位飞到设备自身坐标,再进设备级', async () => {
  47. setActivePinia(createPinia())
  48. const locator = usePointLocateStore()
  49. const calls = { fly: [], openPoint: [], selectDevice: [] }
  50. const deviceTarget = {
  51. kind: 'monitoring-device',
  52. code: 'DEV-131',
  53. name: '测试设备',
  54. status: 'NORMAL',
  55. longitude: device.longitude,
  56. latitude: device.latitude,
  57. coordinate,
  58. }
  59. const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
  60. objects: [point],
  61. mapReady: true,
  62. device: deviceTarget,
  63. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  64. openPoint: async (code, options) => { calls.openPoint.push({ code, options }) },
  65. selectDevice: async (code, options) => { calls.selectDevice.push({ code, options }) },
  66. })
  67. assert.equal(result.result, 'ok')
  68. assert.equal(calls.fly[0].object.code, 'DEV-131', '应飞设备自身坐标,而不是宿主点位')
  69. assert.equal(calls.fly[0].options.tier, 'device')
  70. assert.deepEqual(calls.openPoint[0], { code: 'MP-131', options: undefined })
  71. assert.equal(calls.selectDevice[0].code, 'DEV-131')
  72. assert.equal(calls.selectDevice[0].options.locateTarget.code, 'MP-131')
  73. assert.equal(calls.selectDevice[0].options.locateTarget.deviceCode, 'DEV-131')
  74. assert.deepEqual(calls.selectDevice[0].options.locateTarget.device, deviceTarget)
  75. })
  76. test('事件回联:走完整视角飞行 + 高亮,不再只换中心', async () => {
  77. setActivePinia(createPinia())
  78. const locator = usePointLocateStore()
  79. const calls = { fly: [], highlight: [] }
  80. const event = { code: 'E-131', deviceCode: 'DEV-131', monitoringPointCode: null, coordinate: { validated: true, renderable: true } }
  81. const result = await locator.locateTarget({ kind: 'event', event }, {
  82. objects: [device],
  83. mapReady: true,
  84. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  85. highlight: (codes) => { calls.highlight.push(codes); return 1 },
  86. })
  87. assert.equal(result.result, 'ok')
  88. assert.equal(calls.fly.length, 1)
  89. assert.equal(calls.fly[0].object.code, 'DEV-131')
  90. assert.ok(calls.highlight[0].includes('DEV-131'))
  91. })
  92. test('工单行保留设备编码,供工单卡定位按钮使用', () => {
  93. const rows = workOrderRows([{ code: 'WO-131', deviceName: '测试设备', deviceCode: 'DEV-131', stateCode: 3 }])
  94. assert.equal(rows[0].deviceCode, 'DEV-131')
  95. assert.ok(rows[0].deviceLabel.includes('DEV-131'))
  96. })
  97. test('关联设备 NORMAL:定位揭示必须让详情越过模式暂停', () => {
  98. const host = {
  99. kind: 'monitoring-point',
  100. code: 'MP-131',
  101. name: '测试点位',
  102. status: 'NORMAL',
  103. deviceCodes: ['DEV-131'],
  104. longitude: device.longitude,
  105. latitude: device.latitude,
  106. coordinate,
  107. }
  108. const row = { code: 'DEV-131', pointCode: 'MP-131', status: 'NORMAL', placement: 'drawn' }
  109. const selection = { level: 'equipment', pointCode: 'MP-131', deviceCode: 'DEV-131' }
  110. const base = {
  111. mode: 'warningResponse',
  112. objects: [host],
  113. abnormalDevices: [],
  114. deviceFacts: [{ deviceCode: 'DEV-131', base: 'NORMAL', tags: [] }],
  115. associatedDevices: [row],
  116. selection,
  117. entered: true,
  118. }
  119. assert.equal(planModeLayers(base).selection.visible, false, '未定位时 NORMAL 关联设备在预警处置应暂停')
  120. const located = planModeLayers({ ...base, locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' } })
  121. assert.ok(located.markers.some((marker) => marker.code === 'MP-131'), '定位揭示应把宿主点位标记临时放行')
  122. assert.equal(located.selection.visible, true, '定位揭示必须让 NORMAL 关联设备的详情可见')
  123. })