facilityNetworkLocate.test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import assert from 'node:assert/strict'
  2. import { test } from 'node:test'
  3. import { resolveFacilityPoint } from '../src/modules/cockpit/domain/facilitySelection.js'
  4. // 真实几何形状(2026-12-01 线上 /infrastructure/geometry 的 properties):
  5. // 业务编码在 `code`,sourceId/networkId 是内部主键(raw_* 形)。
  6. const PIPE = {
  7. code: 'TCRQ202609080001',
  8. sourceId: 'raw_P11920',
  9. networkId: 'raw_P11920',
  10. name: '太常片区燃气',
  11. industry: 'GAS',
  12. positions: [[110.3621848838, 28.4517546414], [110.3621946507, 28.4517581805]],
  13. }
  14. const networkOf = (pipes) => ({ pipes, components: [], blocked: [] })
  15. test('按管网业务编码聚焦:命中 pipe.code,落成可定位的一段', () => {
  16. const point = resolveFacilityPoint({
  17. identity: { kind: 'facility', id: 'TCRQ202609080001', category: 'PIPE_NETWORK' },
  18. network: networkOf([PIPE]),
  19. })
  20. assert.equal(point.placement, 'drawn')
  21. assert.equal(point.code, 'TCRQ202609080001')
  22. assert.equal(point.name, '太常片区燃气')
  23. assert.ok(Number.isFinite(point.longitude) && Number.isFinite(point.latitude))
  24. assert.match(point.locationHint, /中点/)
  25. })
  26. test('按内部主键定位的既有调用方不受影响', () => {
  27. const point = resolveFacilityPoint({
  28. identity: { kind: 'facility', id: 'raw_P11920', category: 'PIPE_NETWORK' },
  29. network: networkOf([PIPE]),
  30. })
  31. assert.equal(point.placement, 'drawn')
  32. })
  33. test('图层里没有这段管网时如实说没取到几何,不编坐标', () => {
  34. const point = resolveFacilityPoint({
  35. identity: { kind: 'facility', id: 'TCRQ209912319999', category: 'PIPE_NETWORK' },
  36. network: networkOf([PIPE]),
  37. })
  38. assert.equal(point.placement, 'pending')
  39. assert.equal(point.longitude, null)
  40. assert.match(point.reasonText, /几何|管段/)
  41. })
  42. test('同一编码命中多段时不乱挑一段', () => {
  43. const point = resolveFacilityPoint({
  44. identity: { kind: 'facility', id: 'TCRQ202609080001', category: 'PIPE_NETWORK' },
  45. network: networkOf([PIPE, { ...PIPE, sourceId: 'raw_P11921' }]),
  46. })
  47. assert.equal(point.placement, 'pending')
  48. })