import assert from 'node:assert/strict' import { facilityCategoryText, facilityStatusText, normalizeEntityDetail } from '../src/modules/cockpit/domain/entityDetail.js' import { panelSideFor } from '../src/modules/cockpit/domain/panelCatalog.js' // —— 1) 左右判定:目录单源(历史分析曾在左栏却被当右栏) —— assert.equal(panelSideFor('warningResponse', 'currentEvents'), 'left') assert.equal(panelSideFor('warningResponse', 'historyAnalysis'), 'left') assert.equal(panelSideFor('warningResponse', 'responseEfficiency'), 'right') assert.equal(panelSideFor('warningResponse', 'eventAnalysis'), 'right') assert.equal(panelSideFor('infrastructure', 'operation'), 'left') assert.equal(panelSideFor('infrastructure', 'emergency'), 'right') assert.equal(panelSideFor('monitoring', 'monitoringOverview'), 'left') assert.equal(panelSideFor('monitoring', 'operationOverview'), 'right') assert.equal(panelSideFor('unknownMode', 'operation'), '') // —— 2) 设施枚举词表(0 正常 / 1 维护中 / 2 异常) —— assert.equal(facilityStatusText('0'), '正常') assert.equal(facilityStatusText('1'), '维护中') assert.equal(facilityStatusText('2'), '异常') assert.equal(facilityStatusText(''), '') assert.equal(facilityStatusText('9'), '9') // 维护者 2026-10-29:取消英文括注 —— 类别只回中文 assert.equal(facilityCategoryText('PIPE_NETWORK'), '管网') const fieldOf = (detail, label) => detail.sections.flatMap((s) => s.fields).find((f) => f.label === label) // —— 排水管:二级分类有效,码值翻中文 —— const drainage = normalizeEntityDetail({ kind: 'facility', id: 'n1', category: 'PIPE_NETWORK' }, { category: 'PIPE_NETWORK', id: 'n1', code: 'PN-1', name: '城南污水干管', status: '0', attributes: { networkType: '1', networkLevel: '0', lengthMeters: 1200, diameterMillimeters: 300 }, }) assert.equal(drainage.statusText, '正常') assert.equal(drainage.categoryText, '管网') assert.equal(fieldOf(drainage, '管网类型').value, '排水管网') assert.equal(fieldOf(drainage, '二级分类').value, '污水') assert.equal(fieldOf(drainage, '长度').value, '1200 米') assert.equal(fieldOf(drainage, '管径').value, '300 毫米') // —— 非排水管:二级分类无业务含义 → 保留行显示「—」,并给适用说明 —— for (const networkType of ['0', '2']) { const other = normalizeEntityDetail({ kind: 'facility', id: 'n2', category: 'PIPE_NETWORK' }, { category: 'PIPE_NETWORK', id: 'n2', name: '非排水管', status: '0', attributes: { networkType, networkLevel: '1' }, }) const level = fieldOf(other, '二级分类') assert.equal(level.value, '—') assert.equal(level.note, '仅排水管道适用') assert.equal(fieldOf(other, '管网类型').value, networkType === '0' ? '燃气管网' : '供水管网') } // —— 有量纲的读数必须带单位 —— const plant = normalizeEntityDetail({ kind: 'facility', id: '1', category: 'WATER_PLANT' }, { category: 'WATER_PLANT', id: '1', name: '一水厂', status: '1', attributes: { designCapacity: 10, currentCapacity: 8.5 }, }) assert.equal(plant.statusText, '维护中') assert.equal(plant.tone, 'lv2') assert.equal(fieldOf(plant, '设计能力').value, '10 万m³/d') assert.equal(fieldOf(plant, '当前能力').value, '8.5 万m³/d') const station = normalizeEntityDetail({ kind: 'facility', id: '2', category: 'PUMP_STATION' }, { category: 'PUMP_STATION', id: '2', name: '一号泵站', status: '0', attributes: { pumpCount: 3, designFlow: 1200, designHead: 25, powerCapacity: 90 }, }) assert.equal(fieldOf(station, '水泵数量').value, '3 台') assert.equal(fieldOf(station, '设计流量').value, '1200 m³/h') assert.equal(fieldOf(station, '设计扬程').value, '25 m') assert.equal(fieldOf(station, '装机功率').value, '90 kW') const engineering = normalizeEntityDetail({ kind: 'facility', id: 'f1', category: 'ENGINEERING_FACILITY' }, { category: 'ENGINEERING_FACILITY', id: 'f1', name: '东门闸', status: '0', attributes: { facilityType: '0', designFlow: 3.5, designHead: 4, storageCapacity: 1000 }, }) assert.equal(fieldOf(engineering, '设施类型').value, '闸门') assert.equal(fieldOf(engineering, '设计流量').value, '3.5 m³/s') assert.equal(fieldOf(engineering, '设计扬程').value, '4 m') assert.equal(fieldOf(engineering, '调蓄容积').value, '1000 m³') const resource = normalizeEntityDetail({ kind: 'emergency', id: 'e1', category: 'EMERGENCY_RESOURCE' }, { category: 'EMERGENCY_RESOURCE', id: 'e1', name: '应急水泵', attributes: { assetValue: 12000, useLifeYears: 8 }, }) assert.equal(fieldOf(resource, '资产价值').value, '12000 元') assert.equal(fieldOf(resource, '预计使用年限').value, '8 年') const target = normalizeEntityDetail({ kind: 'emergency', id: 'r1', category: 'PROTECTION_TARGET' }, { category: 'PROTECTION_TARGET', id: 'r1', name: '学校', attributes: { riskScore: 88 }, }) assert.equal(fieldOf(target, '风险分值').value, '88 分') // —— 命名规范:标签一律中文,**不得再带任何括注**(维护者 2026-10-29 第二条) —— for (const detail of [drainage, plant, station, engineering, resource, target]) { for (const section of detail.sections) { for (const item of section.fields) { assert.ok(/[\u4e00-\u9fff]/.test(item.label), '字段名必须以中文开头: ' + item.label) assert.ok(!item.label.includes('('), '字段名不得带括注: ' + item.label) } } } console.log('t65-facility-detail-labels: 45/45')