entityDetailAssetFields.test.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. import assert from 'node:assert/strict'
  2. import { test } from 'node:test'
  3. import { normalizeEntityDetail, entityDetailView } from '../src/modules/cockpit/domain/entityDetail.js'
  4. const EMERGENCY_CATEGORIES = new Set(['HAZARD', 'PROTECTION_TARGET', 'EMERGENCY_RESOURCE'])
  5. function assetView(raw) {
  6. const kind = EMERGENCY_CATEGORIES.has(raw.category) ? 'emergency' : 'facility'
  7. return entityDetailView(normalizeEntityDetail({ kind, id: raw.id, category: raw.category }, raw))
  8. }
  9. function hazardView(attributes = {}) {
  10. return assetView({
  11. category: 'HAZARD',
  12. id: 'h1',
  13. code: 'YH-20261113175702',
  14. name: '322322',
  15. attributes: { reportTime: '2026-11-13T17:57:10', rectifyDeadline: '2026-11-13T00:00:00', ...attributes },
  16. })
  17. }
  18. function resourceView(attributes = {}) {
  19. return assetView({
  20. category: 'EMERGENCY_RESOURCE',
  21. id: 'e1',
  22. code: '8652052335',
  23. name: '漏失监测',
  24. attributes: { installTime: '2026-10-26T00:00:00', ...attributes },
  25. })
  26. }
  27. function businessFields(view) {
  28. return view.sections.find((group) => group.title === '业务详情').fields
  29. }
  30. test('资产摘要不再有「状态」卡、基本信息不再有「运行状态」行;抬头状态仍在', () => {
  31. const view = assetView({
  32. category: 'HAZARD',
  33. id: 'h1',
  34. code: 'YH-1',
  35. name: '322322',
  36. status: '待核查',
  37. attributes: { reportTime: '2026-11-13T17:57:10' },
  38. })
  39. assert.equal(view.status, '待核查')
  40. assert.equal(view.summary.some((item) => item.label === '状态'), false)
  41. const basic = view.sections.find((group) => group.title === '基本信息')
  42. assert.equal(basic.fields.some((item) => item.label === '运行状态'), false)
  43. })
  44. test('防护目标没有业务编码列:不生成编码字段,抬头不拼接「编码未提供」', () => {
  45. const view = assetView({
  46. category: 'PROTECTION_TARGET',
  47. id: 'risk001',
  48. code: 'risk001',
  49. name: '郑东新区CBD商业中心',
  50. status: '1',
  51. attributes: { riskLevel: '1', riskScore: 72.5, riskColor: '1' },
  52. })
  53. assert.equal(view.subtitle, '应急对象')
  54. // 防护目标的基本信息整栏已删(只剩对象类别与更新时间,抬头都有),所以直接断言不存在编码相关字段。
  55. assert.equal(view.sections.some((group) => group.title === '基本信息'), false)
  56. assert.equal(JSON.stringify(view.sections).includes('对象编码'), false)
  57. })
  58. test('应急对象基本信息用「对象编码/对象类别」,编码整行;设施编码同样整行', () => {
  59. const resource = assetView({
  60. category: 'EMERGENCY_RESOURCE',
  61. id: 'e1',
  62. code: '41010500002000000004/34020000001310000007',
  63. name: '过道1',
  64. attributes: { installTime: '2026-10-26T00:00:00' },
  65. })
  66. const basic = resource.sections.find((group) => group.title === '基本信息')
  67. assert.equal(basic.fields.some((item) => item.label === '设施编码' || item.label === '设施类别'), false)
  68. const code = basic.fields.find((item) => item.label === '对象编码')
  69. assert.equal(code.value, '41010500002000000004/34020000001310000007')
  70. assert.equal(code.wide, true)
  71. assert.equal(basic.fields.find((item) => item.label === '对象类别').value, '应急资源')
  72. const pipe = assetView({
  73. category: 'PIPE_NETWORK',
  74. id: 'p1',
  75. code: 'GD-41010500002000000004',
  76. name: '测试管线',
  77. attributes: { buildDate: '2020-05-01' },
  78. })
  79. const pipeBasic = pipe.sections.find((group) => group.title === '基本信息')
  80. assert.equal(pipeBasic.fields.find((item) => item.label === '设施编码').wide, true)
  81. })
  82. test('评估时间只在摘要出现一次,业务详情不再重复(维护者 2026-12-01)', () => {
  83. const view = assetView({
  84. category: 'PROTECTION_TARGET',
  85. id: 'risk001',
  86. code: 'risk001',
  87. name: '郑东新区CBD商业中心',
  88. status: '1',
  89. updatedAt: '2025-01-15T10:00:00+08:00',
  90. attributes: { riskLevel: '1', riskScore: 72.5, assessmentTime: '2025-01-15T10:00:00' },
  91. })
  92. assert.equal(view.summary.find((item) => item.label === '评估时间').value, '2025-01-15 10:00:00')
  93. assert.equal(businessFields(view).some((item) => item.label === '评估时间'), false)
  94. assert.equal(businessFields(view).some((item) => item.label === '风险分值'), false)
  95. })
  96. test('纯日期字段只显示 yyyy-MM-dd,不补 00:00:00', () => {
  97. assert.equal(businessFields(hazardView()).find((item) => item.label === '整改期限').value, '2026-11-13')
  98. const pipe = assetView({
  99. category: 'PIPE_NETWORK',
  100. id: 'p1',
  101. code: 'GD-1',
  102. name: '测试管线',
  103. attributes: { buildDate: '2020-05-01T00:00:00' },
  104. })
  105. assert.equal(businessFields(pipe).find((item) => item.label === '建设日期').value, '2020-05-01')
  106. })
  107. const relationFields = (view) => {
  108. const group = view.sections.find((item) => item.title === '关联信息')
  109. return group ? group.fields : []
  110. }
  111. test('关联项按源表列存在:有列缺值显示「未提供」,无列不生成该行', () => {
  112. // 隐患台账的三个关联对象在「关联信息」页签里(维护者 2026-12-01 归位);缺值仍保留行。
  113. const hazardLabels = relationFields(hazardView()).map((item) => item.label)
  114. assert.equal(hazardLabels.includes('关联管网'), true)
  115. assert.equal(hazardLabels.includes('关联工单'), true)
  116. assert.equal(relationFields(hazardView()).find((item) => item.label === '关联管网').value, '未提供')
  117. // 设备台账没有这三列:整行不生成
  118. const resourceLabels = businessFields(resourceView()).map((item) => item.label)
  119. assert.equal(resourceLabels.some((label) => ['关联管网', '关联设备', '关联工单'].includes(label)), false)
  120. // 风险评估表有 network_id 列:缺值保留
  121. const target = assetView({
  122. category: 'PROTECTION_TARGET',
  123. id: 'risk001',
  124. name: '防护目标',
  125. attributes: { riskLevel: '1' },
  126. })
  127. assert.equal(businessFields(target).find((item) => item.label === '关联管网').value, '未提供')
  128. })
  129. test('时间按值的实际粒度展示:真时刻给完整串,00:00:00 占位只显示日期', () => {
  130. // 维护者 2026-12-01 时间显示规则:落在 00:00:00 这个占位时刻上的一律只显示日期。
  131. assert.equal(businessFields(hazardView()).find((item) => item.label === '报告时间').value, '2026-11-13 17:57:10')
  132. assert.equal(businessFields(resourceView()).find((item) => item.label === '安装时间').value, '2026-10-26')
  133. })