waterFacilityGis.test.mjs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import fs from 'node:fs'
  4. import {
  5. buildFacilityMapModel,
  6. filterFacilityMapModel,
  7. findFacilityFeature,
  8. formatFacilityDetail
  9. } from '../src/utils/waterFacilityGisModel.js'
  10. const collection = {
  11. type: 'FeatureCollection',
  12. features: [
  13. {
  14. type: 'Feature',
  15. id: 'plant:1',
  16. geometry: { type: 'Point', coordinates: [113.1, 23.1] },
  17. properties: { facilityType: 'plant', id: 1, code: 'WP-1', name: '城北水厂', location: '城北路' }
  18. },
  19. {
  20. type: 'Feature',
  21. id: 'pipe:2',
  22. geometry: { type: 'LineString', coordinates: [[113.2, 23.2], [113.4, 23.4]] },
  23. properties: { facilityType: 'pipe', id: 2, code: 'PIPE-2', name: '输水干线', location: '滨江路' }
  24. },
  25. {
  26. type: 'Feature',
  27. id: 'user:3',
  28. geometry: { type: 'Point', coordinates: [113.5, null] },
  29. properties: { facilityType: 'user', id: 3, code: 'USER-3', name: '缺坐标用水户' }
  30. }
  31. ]
  32. }
  33. test('facility map model keeps WGS84 coordinate order and omits incomplete features', () => {
  34. const model = buildFacilityMapModel(collection)
  35. assert.deepEqual(model.points.map(item => [item.lng, item.lat]), [[113.1, 23.1]])
  36. assert.deepEqual(model.lines[0].points.map(item => [item.lng, item.lat]), [[113.2, 23.2], [113.4, 23.4]])
  37. })
  38. test('facility type filters produce an observable empty layer state', () => {
  39. const model = buildFacilityMapModel(collection)
  40. const visible = filterFacilityMapModel(model, { plant: false, pipe: false, user: true })
  41. assert.equal(visible.points.length, 0)
  42. assert.equal(visible.lines.length, 0)
  43. assert.equal(visible.isEmpty, true)
  44. })
  45. test('facility search locates points and line midpoints by name, code, or address', () => {
  46. const model = buildFacilityMapModel(collection)
  47. assert.deepEqual(findFacilityFeature(model, 'WP-1'), {
  48. ...model.points[0],
  49. kind: 'point'
  50. })
  51. assert.deepEqual(
  52. [findFacilityFeature(model, '滨江路').lng, findFacilityFeature(model, '滨江路').lat],
  53. [113.3, 23.3]
  54. )
  55. })
  56. test('facility detail entries use Chinese labels and business values', () => {
  57. const entries = formatFacilityDetail({
  58. id: 6,
  59. stationCode: 'GIS-TEST-PS-001',
  60. stationType: 'water_supply',
  61. status: '0',
  62. pumpCount: 4
  63. }, 'pumpStation')
  64. assert.ok(entries.some(item => item.label === '泵站编号'))
  65. assert.ok(entries.some(item => item.label === '水泵数量' && item.value === 4))
  66. assert.ok(entries.some(item => item.label === '设施类型' && item.value === '供水泵站'))
  67. assert.ok(entries.some(item => item.label === '运行状态' && item.value === '正常'))
  68. assert.ok(entries.every(item => !/[A-Za-z]/u.test(item.label)))
  69. })
  70. test('GIS page exposes REST-backed right detail drawer and empty layer state', () => {
  71. const source = fs.readFileSync('src/views/subSystem/waterSupply/facility/gis.vue', 'utf8')
  72. assert.match(source, /<el-drawer[\s\S]*?direction="rtl"[\s\S]*?class="detail-drawer"/u)
  73. assert.match(source, /getWaterFacilityDetail\(feature\.type, feature\.id\)/u)
  74. assert.match(source, /detailLoading/u)
  75. assert.match(source, /detailError/u)
  76. assert.match(source, /当前筛选下没有可显示的供水设施/u)
  77. assert.match(source, /const centerPoint = \{ lng: 110\.3965, lat: 28\.4638 \}/u)
  78. assert.match(source, /function featureFocus\(feature\)/u)
  79. assert.match(source, /<WaterGisPageShell/u)
  80. const shellSource = fs.readFileSync('src/components/WaterGisPageShell.vue', 'utf8')
  81. assert.match(shellSource, /class="side-panel-body"/u)
  82. assert.match(shellSource, /overflow-y: auto/u)
  83. })