locate-steps.test.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /**
  2. * 定位计划闸门(#13 收尾重构):
  3. * 一次定位最终都落成三件事 —— ① 相机到目标坐标 ② 目标点可见(揭示)③ 详情面板展开。
  4. * 本测试钉住**计划层**对三种目标的判定,执行侧(pointLocateStore)只按计划做事。
  5. */
  6. import assert from 'node:assert/strict'
  7. import { test } from 'node:test'
  8. import { DETAIL_STEP, planMapObjectLocate } from '../src/modules/cockpit/domain/locateSteps.js'
  9. const coordinate = { state: 'VALID', reason: null, renderable: true, crs: 'WGS84' }
  10. const point = {
  11. kind: 'monitoring-point',
  12. code: 'MP-T',
  13. name: '测试点位',
  14. status: 'NORMAL',
  15. industry: 'DRAINAGE',
  16. deviceCodes: ['DEV-A'],
  17. longitude: 110.4,
  18. latitude: 28.4,
  19. coordinate,
  20. }
  21. const independent = {
  22. kind: 'unassociated-equipment',
  23. code: 'DEV-FREE',
  24. name: '独立设备',
  25. status: 'NORMAL',
  26. longitude: 110.41,
  27. latitude: 28.41,
  28. coordinate,
  29. }
  30. test('监测点:飞到点位档、开点位级详情、揭示点位自身', () => {
  31. const plan = planMapObjectLocate({ code: 'MP-T', objects: [point], mapReady: true })
  32. assert.equal(plan.result, 'ok')
  33. assert.equal(plan.cameraTier, '', '点位按点位档(不带 device 档)')
  34. assert.equal(plan.needsDevice, false, '点位不需要解析设备行')
  35. assert.deepEqual(plan.open, { level: DETAIL_STEP.POINT, pointCode: 'MP-T', deviceCode: '' })
  36. assert.deepEqual(plan.reveal, { code: 'MP-T', deviceCode: '' })
  37. })
  38. test('关联设备:越过宿主点位飞设备档、开设备级详情(保留宿主点位)、揭示宿主+设备', () => {
  39. const plan = planMapObjectLocate({ code: 'DEV-A', objects: [point], mapReady: true })
  40. assert.equal(plan.result, 'ok')
  41. assert.equal(plan.cameraTier, 'device')
  42. assert.equal(plan.needsDevice, true, '关联设备坐标要先去设备卡/档案解析')
  43. assert.equal(plan.devicePointCode, 'MP-T', '解析设备时要知道宿主点位')
  44. assert.deepEqual(plan.open, { level: DETAIL_STEP.DEVICE, pointCode: 'MP-T', deviceCode: 'DEV-A' })
  45. assert.deepEqual(plan.reveal, { code: 'MP-T', deviceCode: 'DEV-A' })
  46. })
  47. test('未关联设备:它自己就是相机目标与揭示来源,设备级的点位编码为空', () => {
  48. const plan = planMapObjectLocate({ code: 'DEV-FREE', objects: [independent], mapReady: true })
  49. assert.equal(plan.result, 'ok')
  50. assert.equal(plan.cameraTier, 'device')
  51. assert.equal(plan.needsDevice, true)
  52. assert.equal(plan.devicePointCode, '')
  53. assert.deepEqual(plan.open, { level: DETAIL_STEP.DEVICE, pointCode: '', deviceCode: 'DEV-FREE' })
  54. assert.deepEqual(plan.reveal, { code: 'DEV-FREE', deviceCode: '' })
  55. })
  56. test('目标不在摘要里:保留原因,并给出「退设备档案取坐标」的计划', () => {
  57. const plan = planMapObjectLocate({ code: 'DEV-NOT-LOADED', objects: [point], mapReady: true })
  58. assert.equal(plan.result, 'missing')
  59. assert.equal(plan.archiveCode, 'DEV-NOT-LOADED', '执行侧据此去设备档案兜底')
  60. assert.equal(plan.open, null, '计划层不假装能开详情')
  61. assert.equal(plan.reveal, null)
  62. })
  63. test('地图未就绪:结果如实为不可用,不改判定为可定位', () => {
  64. const plan = planMapObjectLocate({ code: 'MP-T', objects: [point], mapReady: false })
  65. assert.equal(plan.result, 'unavailable')
  66. assert.equal(plan.open, null)
  67. assert.equal(plan.needsDevice, true)
  68. })