gisMapCanvas.test.mjs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { readFile } from 'node:fs/promises'
  4. import { getFacilityPointIcon, getMonitoringPointColor, getMonitoringPointIcon, getMonitoringPointLabel, getMonitoringPointStatus, getMonitoringPointTagType } from '../src/utils/gisMapColors.js'
  5. test('shared gis map canvas converts WGS84 coordinates before BMapGL rendering', async () => {
  6. const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
  7. assert.match(source, /import \{ convertCoord \} from '@\/utils\/coordTransform'/u)
  8. assert.match(source, /const \[lng, lat\] = convertCoord\(point\.lng, point\.lat\)/u)
  9. assert.match(source, /new BMapGL\.Point\(lng, lat\)/u)
  10. assert.match(source, /mapInstance\.setViewport\(bmapPoints/u)
  11. assert.doesNotMatch(source, /new BMapGL\.Point\(point\.lng, point\.lat\)/u)
  12. })
  13. test('shared gis map canvas renders every point as an official icon with a label above it', async () => {
  14. const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
  15. assert.match(source, /function escapeHtml\(value\)/u)
  16. assert.match(source, /let bmapLoadTimer = null/u)
  17. assert.match(source, /let disposed = false/u)
  18. assert.match(source, /if \(disposed\) \{[\s\S]*?clearInterval\(bmapLoadTimer\)/u)
  19. assert.match(source, /if \(disposed \|\| !mapContainer\.value\) return/u)
  20. assert.match(source, /onBeforeUnmount\(\(\) => \{[\s\S]*?disposed = true/u)
  21. assert.match(source, /clearInterval\(bmapLoadTimer\)/u)
  22. assert.match(source, /markerSize: \{ type: Number, default: 28 \}/u)
  23. assert.match(source, /const iconUrl = point\.iconUrl \|\| getMonitoringPointIcon\(point\)/u)
  24. assert.match(source, /new BMapGL\.Icon\(iconUrl, new BMapGL\.Size\(size, size\), \{/u)
  25. assert.match(source, /anchor: new BMapGL\.Size\(size \/ 2, size\)/u)
  26. assert.match(source, /const marker = new BMapGL\.Marker\(position, \{/u)
  27. assert.match(source, /new BMapGL\.Label\(`<div class="gis-marker-label-text">/u)
  28. assert.match(source, /offset: new BMapGL\.Size\(-28, -props\.markerSize - 18\)/u)
  29. assert.match(source, /width: 56px/u)
  30. assert.match(source, /overflow-wrap: anywhere/u)
  31. assert.doesNotMatch(source, /white-space: nowrap/u)
  32. assert.doesNotMatch(source, /<img class="marker-icon"/u)
  33. assert.doesNotMatch(source, /class="marker-wrap"/u)
  34. assert.match(source, /供水管网.*起点/u)
  35. assert.match(source, /终点/u)
  36. assert.ok(source.includes("emit('point-click', point)"))
  37. })
  38. test('facility point icons follow the five-facility-type contract', () => {
  39. assert.match(getFacilityPointIcon('source'), /T_MarkPoint_Blue\.png/u)
  40. assert.match(getFacilityPointIcon('plant'), /T_MarkPoint_Green\.png/u)
  41. assert.match(getFacilityPointIcon('pumpStation'), /T_MarkPoint_Red\.png/u)
  42. assert.match(getFacilityPointIcon('pipe'), /T_MarkPoint_Yellow\.png/u)
  43. assert.match(getFacilityPointIcon('user'), /T_MarkPoint_Black\.png/u)
  44. assert.match(getFacilityPointIcon('unknown'), /T_MarkPoint_Green\.png/u)
  45. })
  46. test('monitoring point colors follow the documented status semantics', () => {
  47. assert.equal(getMonitoringPointStatus({ relatedOrderNo: 'WO-1' }), 'workOrder')
  48. assert.equal(getMonitoringPointStatus({ relatedWorkOrderNo: 'WO-2' }), 'workOrder')
  49. assert.equal(getMonitoringPointStatus({ alarmStatus: 1 }), 'alarm')
  50. assert.equal(getMonitoringPointStatus({ currentStatus: 3 }), 'warning')
  51. assert.equal(getMonitoringPointStatus({ onlineStatus: 0 }), 'offline')
  52. assert.equal(getMonitoringPointStatus({}), 'normal')
  53. assert.equal(getMonitoringPointColor({ relatedOrderNo: 'WO-1' }), '#3498db')
  54. assert.equal(getMonitoringPointColor({ alarmStatus: 1 }), '#e74c3c')
  55. assert.equal(getMonitoringPointColor({ currentStatus: 3 }), '#f1c40f')
  56. assert.equal(getMonitoringPointColor({ onlineStatus: 0 }), '#95a5a6')
  57. assert.equal(getMonitoringPointColor({}), '#2ecc71')
  58. assert.match(getMonitoringPointIcon({ relatedOrderNo: 'WO-1' }), /T_MarkPoint_Blue\.png/u)
  59. assert.match(getMonitoringPointIcon({ alarmStatus: 1 }), /T_MarkPoint_Red\.png/u)
  60. assert.match(getMonitoringPointIcon({ currentStatus: 3 }), /T_MarkPoint_Yellow\.png/u)
  61. assert.match(getMonitoringPointIcon({ onlineStatus: 0 }), /T_MarkPoint_Grey\.png/u)
  62. assert.match(getMonitoringPointIcon({}), /T_MarkPoint_Green\.png/u)
  63. assert.equal(getMonitoringPointLabel({ currentStatus: 3 }), '预警')
  64. assert.equal(getMonitoringPointLabel({ relatedWorkOrderNo: 'WO-2' }), '关联工单')
  65. assert.equal(getMonitoringPointTagType({ relatedWorkOrderNo: 'WO-2' }), 'primary')
  66. assert.equal(getMonitoringPointTagType({ onlineStatus: 0 }), 'info')
  67. })
  68. test('water supply GIS pages share the common canvas component', async () => {
  69. const deviceSource = await readFile('src/views/subSystem/waterSupply/components/WaterDeviceGisMap.vue', 'utf8')
  70. const facilitySource = await readFile('src/views/subSystem/waterSupply/facility/gis.vue', 'utf8')
  71. assert.match(deviceSource, /<GisMapCanvas/u)
  72. assert.match(deviceSource, /value="workOrder">关联工单/u)
  73. assert.match(deviceSource, /legend-dot warning/u)
  74. assert.match(deviceSource, /getMonitoringPointTagType/u)
  75. assert.match(deviceSource, /:points="mapPoints"/u)
  76. assert.match(deviceSource, /@point-click="openDetail\(\$event\.equipmentId\)"/u)
  77. assert.match(facilitySource, /<GisMapCanvas/u)
  78. assert.match(facilitySource, /:points="mapPoints"/u)
  79. assert.match(facilitySource, /:lines="mapLines"/u)
  80. assert.match(facilitySource, /iconUrl: getFacilityPointIcon\(point\.type\)/u)
  81. assert.match(facilitySource, /@point-click="locateFeature"/u)
  82. const alarmSource = await readFile('src/views/subSystem/waterSupply/components/WaterAlarmPage.vue', 'utf8')
  83. assert.match(alarmSource, /<GisMapCanvas/u)
  84. assert.match(alarmSource, /getMonitoringPointColor\(point\)/u)
  85. assert.match(alarmSource, /一级报警/u)
  86. assert.doesNotMatch(alarmSource, /color: point\.relatedOrderNo \?/u)
  87. assert.match(alarmSource, /:points="gisMapPoints"/u)
  88. assert.match(alarmSource, /@point-click="openDetail"/u)
  89. })