point-locate.test.js 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' }
  11. const device = {
  12. kind: 'unassociated-equipment',
  13. code: 'DEV-131',
  14. name: '测试设备',
  15. status: 'ALARM',
  16. longitude: 110.410194,
  17. latitude: 28.445044,
  18. coordinate,
  19. }
  20. const point = {
  21. kind: 'monitoring-point',
  22. code: 'MP-131',
  23. name: '测试点位',
  24. status: 'ALARM',
  25. deviceCodes: ['DEV-131'],
  26. longitude: device.longitude,
  27. latitude: device.latitude,
  28. coordinate,
  29. }
  30. test('设备定位:走完整视角、打开设备详情并写揭示目标', async () => {
  31. setActivePinia(createPinia())
  32. const locator = usePointLocateStore()
  33. const calls = { fly: [], openDevice: [] }
  34. const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
  35. objects: [device],
  36. mapReady: true,
  37. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  38. openDevice: async (code, options) => { calls.openDevice.push({ code, options }) },
  39. })
  40. assert.equal(result.result, 'ok')
  41. assert.equal(calls.fly.length, 1)
  42. assert.equal(calls.fly[0].object.code, 'DEV-131')
  43. assert.deepEqual(calls.openDevice[0], { code: 'DEV-131', options: { locateTarget: { code: 'DEV-131', deviceCode: '' } } })
  44. })
  45. test('关联设备定位:先开宿主点位、再进设备级,揭示宿主点位', async () => {
  46. setActivePinia(createPinia())
  47. const locator = usePointLocateStore()
  48. const calls = { openPoint: [], selectDevice: [] }
  49. const result = await locator.locateTarget({ kind: 'map-object', code: 'DEV-131' }, {
  50. objects: [point],
  51. mapReady: true,
  52. flyPoint: async () => true,
  53. openPoint: async (code, options) => { calls.openPoint.push({ code, options }) },
  54. selectDevice: async (code, options) => { calls.selectDevice.push({ code, options }) },
  55. })
  56. assert.equal(result.result, 'ok')
  57. assert.deepEqual(calls.openPoint[0], { code: 'MP-131', options: undefined })
  58. assert.deepEqual(calls.selectDevice[0], {
  59. code: 'DEV-131',
  60. options: { locateTarget: { code: 'MP-131', deviceCode: 'DEV-131' } },
  61. })
  62. })
  63. test('事件回联:走完整视角飞行 + 高亮,不再只换中心', async () => {
  64. setActivePinia(createPinia())
  65. const locator = usePointLocateStore()
  66. const calls = { fly: [], highlight: [] }
  67. const event = { code: 'E-131', deviceCode: 'DEV-131', monitoringPointCode: null, coordinate: { validated: true, renderable: true } }
  68. const result = await locator.locateTarget({ kind: 'event', event }, {
  69. objects: [device],
  70. mapReady: true,
  71. flyPoint: async (object, options) => { calls.fly.push({ object, options }); return true },
  72. highlight: (codes) => { calls.highlight.push(codes); return 1 },
  73. })
  74. assert.equal(result.result, 'ok')
  75. assert.equal(calls.fly.length, 1)
  76. assert.equal(calls.fly[0].object.code, 'DEV-131')
  77. assert.ok(calls.highlight[0].includes('DEV-131'))
  78. })
  79. test('工单行保留设备编码,供工单卡定位按钮使用', () => {
  80. const rows = workOrderRows([{ code: 'WO-131', deviceName: '测试设备', deviceCode: 'DEV-131', stateCode: 3 }])
  81. assert.equal(rows[0].deviceCode, 'DEV-131')
  82. assert.ok(rows[0].deviceLabel.includes('DEV-131'))
  83. })