t65-facility-detail-labels.mjs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import assert from 'node:assert/strict'
  2. import { facilityCategoryText, facilityStatusText, normalizeEntityDetail } from '../src/modules/cockpit/domain/entityDetail.js'
  3. import { panelSideFor } from '../src/modules/cockpit/domain/panelCatalog.js'
  4. // —— 1) 左右判定:目录单源(历史分析曾在左栏却被当右栏) ——
  5. assert.equal(panelSideFor('warningResponse', 'currentEvents'), 'left')
  6. assert.equal(panelSideFor('warningResponse', 'historyAnalysis'), 'left')
  7. assert.equal(panelSideFor('warningResponse', 'responseEfficiency'), 'right')
  8. assert.equal(panelSideFor('warningResponse', 'eventAnalysis'), 'right')
  9. assert.equal(panelSideFor('infrastructure', 'operation'), 'left')
  10. assert.equal(panelSideFor('infrastructure', 'emergency'), 'right')
  11. assert.equal(panelSideFor('monitoring', 'monitoringOverview'), 'left')
  12. assert.equal(panelSideFor('monitoring', 'operationOverview'), 'right')
  13. assert.equal(panelSideFor('unknownMode', 'operation'), '')
  14. // —— 2) 设施枚举词表(0 正常 / 1 维护中 / 2 异常) ——
  15. assert.equal(facilityStatusText('0'), '正常')
  16. assert.equal(facilityStatusText('1'), '维护中')
  17. assert.equal(facilityStatusText('2'), '异常')
  18. assert.equal(facilityStatusText(''), '')
  19. assert.equal(facilityStatusText('9'), '9')
  20. // 维护者 2026-10-29:取消英文括注 —— 类别只回中文
  21. assert.equal(facilityCategoryText('PIPE_NETWORK'), '管网')
  22. const fieldOf = (detail, label) => detail.sections.flatMap((s) => s.fields).find((f) => f.label === label)
  23. // —— 排水管:二级分类有效,码值翻中文 ——
  24. const drainage = normalizeEntityDetail({ kind: 'facility', id: 'n1', category: 'PIPE_NETWORK' }, {
  25. category: 'PIPE_NETWORK', id: 'n1', code: 'PN-1', name: '城南污水干管', status: '0',
  26. attributes: { networkType: '1', networkLevel: '0', lengthMeters: 1200, diameterMillimeters: 300 },
  27. })
  28. assert.equal(drainage.statusText, '正常')
  29. assert.equal(drainage.categoryText, '管网')
  30. assert.equal(fieldOf(drainage, '管网类型').value, '排水管网')
  31. assert.equal(fieldOf(drainage, '二级分类').value, '污水')
  32. assert.equal(fieldOf(drainage, '长度').value, '1200 米')
  33. assert.equal(fieldOf(drainage, '管径').value, '300 毫米')
  34. // —— 非排水管:二级分类无业务含义 → 保留行显示「—」,并给适用说明 ——
  35. for (const networkType of ['0', '2']) {
  36. const other = normalizeEntityDetail({ kind: 'facility', id: 'n2', category: 'PIPE_NETWORK' }, {
  37. category: 'PIPE_NETWORK', id: 'n2', name: '非排水管', status: '0',
  38. attributes: { networkType, networkLevel: '1' },
  39. })
  40. const level = fieldOf(other, '二级分类')
  41. assert.equal(level.value, '—')
  42. assert.equal(level.note, '仅排水管道适用')
  43. assert.equal(fieldOf(other, '管网类型').value, networkType === '0' ? '燃气管网' : '供水管网')
  44. }
  45. // —— 有量纲的读数必须带单位 ——
  46. const plant = normalizeEntityDetail({ kind: 'facility', id: '1', category: 'WATER_PLANT' }, {
  47. category: 'WATER_PLANT', id: '1', name: '一水厂', status: '1',
  48. attributes: { designCapacity: 10, currentCapacity: 8.5 },
  49. })
  50. assert.equal(plant.statusText, '维护中')
  51. assert.equal(plant.tone, 'lv2')
  52. assert.equal(fieldOf(plant, '设计能力').value, '10 万m³/d')
  53. assert.equal(fieldOf(plant, '当前能力').value, '8.5 万m³/d')
  54. const station = normalizeEntityDetail({ kind: 'facility', id: '2', category: 'PUMP_STATION' }, {
  55. category: 'PUMP_STATION', id: '2', name: '一号泵站', status: '0',
  56. attributes: { pumpCount: 3, designFlow: 1200, designHead: 25, powerCapacity: 90 },
  57. })
  58. assert.equal(fieldOf(station, '水泵数量').value, '3 台')
  59. assert.equal(fieldOf(station, '设计流量').value, '1200 m³/h')
  60. assert.equal(fieldOf(station, '设计扬程').value, '25 m')
  61. assert.equal(fieldOf(station, '装机功率').value, '90 kW')
  62. const engineering = normalizeEntityDetail({ kind: 'facility', id: 'f1', category: 'ENGINEERING_FACILITY' }, {
  63. category: 'ENGINEERING_FACILITY', id: 'f1', name: '东门闸', status: '0',
  64. attributes: { facilityType: '0', designFlow: 3.5, designHead: 4, storageCapacity: 1000 },
  65. })
  66. assert.equal(fieldOf(engineering, '设施类型').value, '闸门')
  67. assert.equal(fieldOf(engineering, '设计流量').value, '3.5 m³/s')
  68. assert.equal(fieldOf(engineering, '设计扬程').value, '4 m')
  69. assert.equal(fieldOf(engineering, '调蓄容积').value, '1000 m³')
  70. const resource = normalizeEntityDetail({ kind: 'emergency', id: 'e1', category: 'EMERGENCY_RESOURCE' }, {
  71. category: 'EMERGENCY_RESOURCE', id: 'e1', name: '应急水泵', attributes: { assetValue: 12000, useLifeYears: 8 },
  72. })
  73. assert.equal(fieldOf(resource, '资产价值').value, '12000 元')
  74. assert.equal(fieldOf(resource, '预计使用年限').value, '8 年')
  75. const target = normalizeEntityDetail({ kind: 'emergency', id: 'r1', category: 'PROTECTION_TARGET' }, {
  76. category: 'PROTECTION_TARGET', id: 'r1', name: '学校', attributes: { riskScore: 88 },
  77. })
  78. assert.equal(fieldOf(target, '风险分值').value, '88 分')
  79. // —— 命名规范:标签一律中文,**不得再带任何括注**(维护者 2026-10-29 第二条) ——
  80. for (const detail of [drainage, plant, station, engineering, resource, target]) {
  81. for (const section of detail.sections) {
  82. for (const item of section.fields) {
  83. assert.ok(/[\u4e00-\u9fff]/.test(item.label), '字段名必须以中文开头: ' + item.label)
  84. assert.ok(!item.label.includes('('), '字段名不得带括注: ' + item.label)
  85. }
  86. }
  87. }
  88. console.log('t65-facility-detail-labels: 45/45')