gisMapCanvas.test.mjs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { readFile } from 'node:fs/promises'
  4. import { getMonitoringPointColor, 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 uses the common point marker contract', async () => {
  14. const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
  15. assert.match(source, /markerSize: \{ type: Number, default: 22 \}/u)
  16. assert.match(source, /border-radius:50%/u)
  17. assert.match(source, /border:3px solid #fff/u)
  18. assert.match(source, /class="marker-text"/u)
  19. assert.match(source, /emit\('point-click', point\)/u)
  20. })
  21. test('monitoring point colors follow the documented status semantics', () => {
  22. assert.equal(getMonitoringPointStatus({ relatedOrderNo: 'WO-1' }), 'workOrder')
  23. assert.equal(getMonitoringPointStatus({ relatedWorkOrderNo: 'WO-2' }), 'workOrder')
  24. assert.equal(getMonitoringPointStatus({ alarmStatus: 1 }), 'alarm')
  25. assert.equal(getMonitoringPointStatus({ currentStatus: 3 }), 'warning')
  26. assert.equal(getMonitoringPointStatus({ onlineStatus: 0 }), 'offline')
  27. assert.equal(getMonitoringPointStatus({}), 'normal')
  28. assert.equal(getMonitoringPointColor({ relatedOrderNo: 'WO-1' }), '#3498db')
  29. assert.equal(getMonitoringPointColor({ alarmStatus: 1 }), '#e74c3c')
  30. assert.equal(getMonitoringPointColor({ currentStatus: 3 }), '#f1c40f')
  31. assert.equal(getMonitoringPointColor({ onlineStatus: 0 }), '#95a5a6')
  32. assert.equal(getMonitoringPointColor({}), '#2ecc71')
  33. assert.equal(getMonitoringPointLabel({ currentStatus: 3 }), '预警')
  34. assert.equal(getMonitoringPointLabel({ relatedWorkOrderNo: 'WO-2' }), '关联工单')
  35. assert.equal(getMonitoringPointTagType({ relatedWorkOrderNo: 'WO-2' }), 'primary')
  36. assert.equal(getMonitoringPointTagType({ onlineStatus: 0 }), 'info')
  37. })
  38. test('water supply GIS pages share the common canvas component', async () => {
  39. const deviceSource = await readFile('src/views/subSystem/waterSupply/components/WaterDeviceGisMap.vue', 'utf8')
  40. const facilitySource = await readFile('src/views/subSystem/waterSupply/facility/gis.vue', 'utf8')
  41. assert.match(deviceSource, /<GisMapCanvas/u)
  42. assert.match(deviceSource, /value="workOrder">关联工单/u)
  43. assert.match(deviceSource, /legend-dot warning/u)
  44. assert.match(deviceSource, /getMonitoringPointTagType/u)
  45. assert.match(deviceSource, /:points="mapPoints"/u)
  46. assert.match(deviceSource, /@point-click="openDetail\(\$event\.equipmentId\)"/u)
  47. assert.match(facilitySource, /<GisMapCanvas/u)
  48. assert.match(facilitySource, /:points="mapPoints"/u)
  49. assert.match(facilitySource, /:lines="mapLines"/u)
  50. assert.match(facilitySource, /@point-click="openFacilityDetail"/u)
  51. const alarmSource = await readFile('src/views/subSystem/waterSupply/components/WaterAlarmPage.vue', 'utf8')
  52. assert.match(alarmSource, /<GisMapCanvas/u)
  53. assert.match(alarmSource, /getMonitoringPointColor\(point\)/u)
  54. assert.match(alarmSource, /一级报警/u)
  55. assert.doesNotMatch(alarmSource, /color: point\.relatedOrderNo \?/u)
  56. assert.match(alarmSource, /:points="gisMapPoints"/u)
  57. assert.match(alarmSource, /@point-click="openDetail"/u)
  58. })