gisMapCanvas.test.mjs 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { readFile } from 'node:fs/promises'
  4. import { getFacilityPointIcon, getMapClusterIcon, 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 pipelines without endpoint markers', async () => {
  14. const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
  15. const addLine = source.match(/function addLine\(BMapGL, line\) \{[\s\S]*?\n\}/u)?.[0] || ''
  16. assert.match(addLine, /new BMapGL\.Polyline\(bmapPoints/u)
  17. assert.match(addLine, /emit\('line-click', line\)/u)
  18. assert.doesNotMatch(addLine, /new BMapGL\.Marker/u)
  19. assert.doesNotMatch(addLine, /new BMapGL\.Label/u)
  20. assert.doesNotMatch(addLine, /起点/u)
  21. assert.doesNotMatch(addLine, /终点/u)
  22. })
  23. test('shared gis map canvas renders contextual clusters with colorful mixed icons', async () => {
  24. const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
  25. const addClusterMarker = source.match(/function addClusterMarker\(BMapGL, cluster\) \{[\s\S]*?\n\}/u)?.[0] || ''
  26. assert.match(source, /import \{ mergeMapPoints \} from '@\/utils\/gisMapClustering'/u)
  27. assert.match(source, /clusterRadius: \{ type: Number, default: 48 \}/u)
  28. assert.match(source, /clusterLabel: \{ type: String, default: '点位集合' \}/u)
  29. assert.match(source, /mergeMapPoints\(renderPoints, projectMapPoint, props\.clusterRadius\)/u)
  30. assert.match(source, /getMapClusterIcon\(cluster\.points\)/u)
  31. assert.match(source, /escapeHtml\(props\.clusterLabel\)/u)
  32. assert.match(source, /focusCluster\(cluster\)/u)
  33. assert.match(source, /emit\('cluster-click', cluster\)/u)
  34. assert.match(source, /function isClusterUnexpandable\(cluster\)/u)
  35. assert.match(addClusterMarker, /if \(isClusterUnexpandable\(cluster\)\) emit\('cluster-click', cluster\)/u)
  36. assert.doesNotMatch(addClusterMarker, /props\.showMarkerName/u)
  37. assert.match(source, /mapInstance\.addEventListener\('moveend', renderScene\)/u)
  38. assert.match(source, /mapInstance\.addEventListener\('zoomend', renderScene\)/u)
  39. })
  40. test('shared gis map canvas renders every point as an official icon with a label above it', async () => {
  41. const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
  42. assert.match(source, /function escapeHtml\(value\)/u)
  43. assert.match(source, /let bmapLoadTimer = null/u)
  44. assert.match(source, /let disposed = false/u)
  45. assert.match(source, /if \(disposed\) \{[\s\S]*?clearInterval\(bmapLoadTimer\)/u)
  46. assert.match(source, /if \(disposed \|\| !mapContainer\.value\) return/u)
  47. assert.match(source, /onBeforeUnmount\(\(\) => \{[\s\S]*?disposed = true/u)
  48. assert.match(source, /clearInterval\(bmapLoadTimer\)/u)
  49. assert.match(source, /markerSize: \{ type: Number, default: 28 \}/u)
  50. assert.match(source, /const iconUrl = point\.iconUrl \|\| getMonitoringPointIcon\(point\)/u)
  51. assert.match(source, /new BMapGL\.Icon\(iconUrl, new BMapGL\.Size\(size, size\), \{/u)
  52. assert.match(source, /anchor: new BMapGL\.Size\(size \/ 2, size\)/u)
  53. assert.match(source, /const marker = new BMapGL\.Marker\(position, \{/u)
  54. assert.match(source, /new BMapGL\.Label\(`<div class="gis-marker-label-text">/u)
  55. assert.match(source, /offset: new BMapGL\.Size\(-28, -props\.markerSize - 18\)/u)
  56. assert.match(source, /width: 56px/u)
  57. assert.match(source, /overflow-wrap: anywhere/u)
  58. assert.doesNotMatch(source, /white-space: nowrap/u)
  59. assert.doesNotMatch(source, /<img class="marker-icon"/u)
  60. assert.doesNotMatch(source, /class="marker-wrap"/u)
  61. assert.ok(source.includes("emit('point-click', point)"))
  62. })
  63. test('facility point icons follow the five-facility-type contract', () => {
  64. assert.match(getFacilityPointIcon('source'), /T_MarkPoint_Blue\.png/u)
  65. assert.match(getFacilityPointIcon('plant'), /T_MarkPoint_Green\.png/u)
  66. assert.match(getFacilityPointIcon('pumpStation'), /T_MarkPoint_Red\.png/u)
  67. assert.match(getFacilityPointIcon('pipe'), /T_MarkPoint_Yellow\.png/u)
  68. assert.match(getFacilityPointIcon('user'), /T_MarkPoint_Black\.png/u)
  69. assert.match(getFacilityPointIcon('unknown'), /T_MarkPoint_Green\.png/u)
  70. })
  71. test('cluster icons reuse the single member icon or fall back to the colorful marker', () => {
  72. assert.match(getMapClusterIcon([{ alarmStatus: 1 }, { alarmStatus: 1 }]), /T_MarkPoint_Red\.png/u)
  73. assert.match(getMapClusterIcon([{ onlineStatus: 0 }, { onlineStatus: 0 }]), /T_MarkPoint_Grey\.png/u)
  74. assert.match(getMapClusterIcon([{ alarmStatus: 1 }, { onlineStatus: 0 }]), /T_MarkPoint_Colorful\.png/u)
  75. })
  76. test('monitoring point colors follow the documented status semantics', () => {
  77. assert.equal(getMonitoringPointStatus({ relatedOrderNo: 'WO-1' }), 'workOrder')
  78. assert.equal(getMonitoringPointStatus({ relatedWorkOrderNo: 'WO-2' }), 'workOrder')
  79. assert.equal(getMonitoringPointStatus({ orderNo: 'WO-3', orderStatus: 5 }), 'normal')
  80. assert.equal(getMonitoringPointStatus({ orderNo: 'WO-4', orderStatus: 7, deviceAlarmStatus: 1 }), 'alarm')
  81. assert.equal(getMonitoringPointStatus({ alarmStatus: 1 }), 'alarm')
  82. assert.equal(getMonitoringPointStatus({ currentStatus: 3 }), 'warning')
  83. assert.equal(getMonitoringPointStatus({ onlineStatus: 0 }), 'offline')
  84. assert.equal(getMonitoringPointStatus({}), 'normal')
  85. assert.equal(getMonitoringPointColor({ relatedOrderNo: 'WO-1' }), '#3498db')
  86. assert.equal(getMonitoringPointColor({ alarmStatus: 1 }), '#e74c3c')
  87. assert.equal(getMonitoringPointColor({ currentStatus: 3 }), '#f1c40f')
  88. assert.equal(getMonitoringPointColor({ onlineStatus: 0 }), '#95a5a6')
  89. assert.equal(getMonitoringPointColor({}), '#2ecc71')
  90. assert.match(getMonitoringPointIcon({ relatedOrderNo: 'WO-1' }), /T_MarkPoint_Blue\.png/u)
  91. assert.match(getMonitoringPointIcon({ alarmStatus: 1 }), /T_MarkPoint_Red\.png/u)
  92. assert.match(getMonitoringPointIcon({ currentStatus: 3 }), /T_MarkPoint_Yellow\.png/u)
  93. assert.match(getMonitoringPointIcon({ onlineStatus: 0 }), /T_MarkPoint_Grey\.png/u)
  94. assert.match(getMonitoringPointIcon({}), /T_MarkPoint_Green\.png/u)
  95. assert.equal(getMonitoringPointLabel({ currentStatus: 3 }), '预警')
  96. assert.equal(getMonitoringPointLabel({ relatedWorkOrderNo: 'WO-2' }), '关联工单')
  97. assert.equal(getMonitoringPointTagType({ relatedWorkOrderNo: 'WO-2' }), 'primary')
  98. assert.equal(getMonitoringPointTagType({ onlineStatus: 0 }), 'info')
  99. })
  100. test('an explicit status key wins over inferred monitoring point fields', () => {
  101. const offlineAlarmRecord = { statusKey: 'offline', alarmStatus: 1, onlineStatus: 0 }
  102. assert.equal(getMonitoringPointStatus(offlineAlarmRecord), 'offline')
  103. assert.equal(getMonitoringPointColor(offlineAlarmRecord), '#95a5a6')
  104. assert.match(getMonitoringPointIcon(offlineAlarmRecord), /T_MarkPoint_Grey\.png/u)
  105. const handledAlarm = { statusKey: 'normal', alarmStatus: 1 }
  106. assert.equal(getMonitoringPointStatus(handledAlarm), 'normal')
  107. assert.match(getMonitoringPointIcon(handledAlarm), /T_MarkPoint_Green\.png/u)
  108. assert.equal(getMonitoringPointStatus({ statusKey: '未知状态', alarmStatus: 1 }), 'alarm')
  109. })
  110. test('water supply GIS pages share the common canvas component', async () => {
  111. const deviceSource = await readFile('src/views/subSystem/waterSupply/components/WaterDeviceGisMap.vue', 'utf8')
  112. const facilitySource = await readFile('src/views/subSystem/waterSupply/facility/gis.vue', 'utf8')
  113. assert.match(deviceSource, /<GisMapCanvas/u)
  114. assert.match(deviceSource, /cluster-label="设备集合"/u)
  115. assert.match(deviceSource, /value="workOrder">关联工单/u)
  116. assert.match(deviceSource, /legend-dot warning/u)
  117. assert.match(deviceSource, /getMonitoringPointTagType/u)
  118. assert.match(deviceSource, /:points="mapPoints"/u)
  119. assert.match(deviceSource, /@point-click="openDetail\(\$event\.equipmentId\)"/u)
  120. assert.match(facilitySource, /<GisMapCanvas/u)
  121. assert.match(facilitySource, /:points="mapPoints"/u)
  122. assert.match(facilitySource, /:lines="mapLines"/u)
  123. assert.match(facilitySource, /iconUrl: getFacilityPointIcon\(point\.type\)/u)
  124. assert.match(facilitySource, /cluster-label="设施集合"/u)
  125. assert.match(facilitySource, /@point-click="locateFeature"/u)
  126. const alarmSource = await readFile('src/views/subSystem/waterSupply/components/WaterAlarmPage.vue', 'utf8')
  127. assert.match(alarmSource, /<GisMapCanvas/u)
  128. assert.match(alarmSource, /cluster-label="报警集合"/u)
  129. assert.match(alarmSource, /一级报警/u)
  130. assert.doesNotMatch(alarmSource, /color: point\.relatedOrderNo \?/u)
  131. assert.match(alarmSource, /:points="gisMapPoints"/u)
  132. assert.match(alarmSource, /@point-click="locateAlarmPoint"/u)
  133. })