waterFacilityGis.test.mjs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. } from '../src/utils/waterFacilityGisModel.js'
  9. const collection = {
  10. type: 'FeatureCollection',
  11. features: [
  12. {
  13. type: 'Feature',
  14. id: 'plant:1',
  15. geometry: { type: 'Point', coordinates: [113.1, 23.1] },
  16. properties: { facilityType: 'plant', id: 1, code: 'WP-1', name: '城北水厂', location: '城北路' }
  17. },
  18. {
  19. type: 'Feature',
  20. id: 'pipe:2',
  21. geometry: { type: 'LineString', coordinates: [[113.2, 23.2], [113.4, 23.4]] },
  22. properties: { facilityType: 'pipe', id: 2, code: 'PIPE-2', name: '输水干线', location: '滨江路' }
  23. },
  24. {
  25. type: 'Feature',
  26. id: 'user:3',
  27. geometry: { type: 'Point', coordinates: [113.5, null] },
  28. properties: { facilityType: 'user', id: 3, code: 'USER-3', name: '缺坐标用水户' }
  29. }
  30. ]
  31. }
  32. test('facility map model keeps WGS84 coordinate order and omits incomplete features', () => {
  33. const model = buildFacilityMapModel(collection)
  34. assert.deepEqual(model.points.map(item => [item.lng, item.lat]), [[113.1, 23.1]])
  35. assert.deepEqual(model.lines[0].points.map(item => [item.lng, item.lat]), [[113.2, 23.2], [113.4, 23.4]])
  36. })
  37. test('facility type filters produce an observable empty layer state', () => {
  38. const model = buildFacilityMapModel(collection)
  39. const visible = filterFacilityMapModel(model, { plant: false, pipe: false, user: true })
  40. assert.equal(visible.points.length, 0)
  41. assert.equal(visible.lines.length, 0)
  42. assert.equal(visible.isEmpty, true)
  43. })
  44. test('facility search locates points and line midpoints by name, code, or address', () => {
  45. const model = buildFacilityMapModel(collection)
  46. assert.deepEqual(findFacilityFeature(model, 'WP-1'), {
  47. ...model.points[0],
  48. kind: 'point'
  49. })
  50. assert.deepEqual(
  51. [findFacilityFeature(model, '滨江路').lng, findFacilityFeature(model, '滨江路').lat],
  52. [113.3, 23.3]
  53. )
  54. })
  55. test('GIS page exposes REST-backed right detail drawer and empty layer state', () => {
  56. const source = fs.readFileSync('src/views/subSystem/waterSupply/facility/gis.vue', 'utf8')
  57. assert.match(source, /<el-drawer[\s\S]*?direction="rtl"[\s\S]*?class="detail-drawer"/u)
  58. assert.match(source, /getWaterFacilityDetail\(feature\.type, feature\.id\)/u)
  59. assert.match(source, /detailLoading/u)
  60. assert.match(source, /detailError/u)
  61. assert.match(source, /当前筛选下没有可显示的供水设施/u)
  62. })