Forráskód Böngészése

fix(cockpit): 预警详情阈值缺值时不再打出 null ~ null

票 11 真实后端联调抓到的契约偏差:后端对没有阈值的预警下发
minValue/maxValue = null,threshold() 只把 undefined 当缺值(?? 对 null 仍返回 null),
于是「监测读数 → 阈值」上屏成「null ~ null(单位未发布)」。

改为两端统一过 thresholdBound():null / 空串视为"没有这一端",
缺少的整行按既有 compactSections 纪律剔除;有值时仍按「min ~ max 单位」渲染。

闸门:tests/entityDetailWarning.test.js 新增 2 条(null 不出行 / 有值渲染),
全量 37 个文件 184 条全绿。
ChenJZ 1 napja
szülő
commit
a6cef68f7f

+ 15 - 2
src/modules/cockpit/domain/entityDetail.js

@@ -1245,9 +1245,22 @@ function withUnit(value, unit) {
     if (!hasValue) return ''
     return unit ? `${value} ${unit}` : `${value}(单位未发布)`
 }
+/**
+ * 阈值端点:`null` / 空串一律当"没有这一端"。
+ *
+ * 曾经的实测缺陷(票 11 联调):真实后端对没有阈值的预警下发
+ * `minValue: null, maxValue: null`,而本函数只把 `undefined` 当缺值 ——
+ * `??` 对 null 也返回 null,于是拼出「null ~ null(单位未发布)」上屏。
+ * 缺值就该整行不出(与本区其它读数同一纪律),不是把 null 当数字。
+ */
+function thresholdBound(value) {
+    if (value === null || value === undefined) return undefined
+    if (typeof value === 'string' && value.trim() === '') return undefined
+    return value
+}
 function threshold(source) {
-    const min = source.thresholdMinValue ?? source.minValue
-    const max = source.thresholdMaxValue ?? source.maxValue
+    const min = thresholdBound(source.thresholdMinValue ?? source.minValue)
+    const max = thresholdBound(source.thresholdMaxValue ?? source.maxValue)
     if (min === undefined && max === undefined) return ''
     return withUnit(min !== undefined && max !== undefined ? `${min} ~ ${max}` : min !== undefined ? `≥ ${min}` : `≤ ${max}`, source.unit)
 }

+ 31 - 1
tests/entityDetailWarning.test.js

@@ -190,4 +190,34 @@ test('报警已处理时流程结束在关闭步,不再停在处置步', () =>
     ))
     assert.equal(view.status, '已处理')
     assert.deepEqual(view.stage.map((item) => item.state), ['done', 'done', 'done', 'active'])
-})
+})
+// 票 11 真实联调抓到的契约偏差:后端对没有阈值的预警下发 minValue/maxValue = null,
+// 旧实现只把 undefined 当缺值 ⇒ 界面上出现「阈值 null ~ null(单位未发布)」。
+function warningWithMetrics(metrics) {
+    const raw = {
+        basicInfo: {
+            warningNo: 'YJ202612011319124570',
+            warningName: '测试环境监测-测试01',
+            status: 'PENDING',
+            eventTime: '2026-12-01T13:19:12.000+08:00',
+            ...metrics,
+        },
+        disposalHistory: [],
+    }
+    return entityDetailView(normalizeEntityDetail({ kind: 'event', id: 'YJ202612011319124570', family: 'WARNING' }, raw))
+}
+
+test('阈值两端为 null:整行不出,不把 null 打成字符串上屏', () => {
+    const view = warningWithMetrics({ minValue: null, maxValue: null, actualValue: null })
+    const metrics = view.sections.find((g) => g.title === '监测读数')
+    const thresholdRow = (metrics ? metrics.fields : []).find((f) => f.label === '阈值')
+    assert.equal(thresholdRow, undefined, '缺阈值的行应被 compactSections 剔除')
+    assert.equal(JSON.stringify(view.sections).includes('null ~ null'), false)
+})
+
+test('阈值有值时仍按「min ~ max 单位」渲染', () => {
+    const view = warningWithMetrics({ minValue: 1.5, maxValue: 2.5, unit: '%LEL', actualValue: 3.1 })
+    const metrics = view.sections.find((g) => g.title === '监测读数')
+    assert.equal(metrics.fields.find((f) => f.label === '阈值').value, '1.5 ~ 2.5 %LEL')
+    assert.equal(metrics.fields.find((f) => f.label === '实际值').value, '3.1 %LEL')
+})