| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import test from 'node:test'
- import assert from 'node:assert/strict'
- import { indicatorName, setIndicatorNames, normalizeCode } from '../src/utils/warningIndicator.js'
- test('优先使用后端下发的监测指标中文名', () => {
- setIndicatorNames([])
- assert.equal(indicatorName({ warningName: '窨井倾斜预警', warningCode: 'WARN-TILT' }), '窨井倾斜预警')
- })
- test('没有 warningName 时使用 alarm_data 的中文类型名', () => {
- setIndicatorNames([])
- assert.equal(indicatorName({ warningType: '倾斜预警', warningCode: 'WARN-TILT' }), '倾斜预警')
- })
- test('通过 warning_code 从 warning_type 字典取 warning_name 显示', () => {
- setIndicatorNames([
- { dictValue: 'WARN-TILT', dictLabel: '窨井倾斜预警' },
- { typeCode: 'WARN_PRESSURE', typeName: '压力预警' }
- ])
- assert.equal(indicatorName({ warningCode: 'WARN-TILT' }, '监测指标'), '窨井倾斜预警')
- assert.equal(indicatorName({ warningCode: 'WARN_PRESSURE' }, '监测指标'), '压力预警')
- })
- test('warning_type 与 alarm_data 编码 -/_、大小写混用也能关联上', () => {
- setIndicatorNames([{ dictValue: 'WARN_TILT', dictLabel: '窨井倾斜预警' }])
- assert.equal(indicatorName({ warningCode: ' warn-tilt ' }, '监测指标'), '窨井倾斜预警')
- assert.equal(normalizeCode(' WARN-Tilt '), 'WARN_TILT')
- })
- test('任何 WARN-*/WARN_* 编码都不作为展示文案', () => {
- setIndicatorNames([])
- assert.equal(indicatorName({ warningName: 'WARN-TILT' }, '监测指标'), '监测指标')
- assert.equal(indicatorName({ warningType: 'WARN_PRESSURE' }, '监测指标'), '监测指标')
- assert.equal(indicatorName({ warningType: 'UNKNOWN_EVENT_TYPE' }, '监测指标'), '监测指标')
- })
- test('全大写下划线编码也不当作名称', () => {
- setIndicatorNames([])
- assert.equal(indicatorName({ warningType: 'DRAINAGE_DEVICE' }, '监测指标'), '监测指标')
- })
- test('字段缺失或字典未命中时返回兜底文案而不是编码', () => {
- setIndicatorNames([])
- assert.equal(indicatorName({ warningCode: 'WARN-TILT' }), '—')
- assert.equal(indicatorName({ warningCode: 'WARN-TILT' }, '其他告警'), '其他告警')
- assert.equal(indicatorName(), '—')
- setIndicatorNames([{ dictValue: 'WARN-PRESSURE', dictLabel: '压力预警' }])
- assert.equal(indicatorName({ warningCode: 'WARN-TILT' }, '监测指标'), '监测指标')
- })
|