| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- import assert from 'node:assert/strict'
- import { test } from 'node:test'
- import { normalizeEntityDetail, entityDetailView } from '../src/modules/cockpit/domain/entityDetail.js'
- const EMERGENCY_CATEGORIES = new Set(['HAZARD', 'PROTECTION_TARGET', 'EMERGENCY_RESOURCE'])
- function assetView(raw) {
- const kind = EMERGENCY_CATEGORIES.has(raw.category) ? 'emergency' : 'facility'
- return entityDetailView(normalizeEntityDetail({ kind, id: raw.id, category: raw.category }, raw))
- }
- function hazardView(attributes = {}) {
- return assetView({
- category: 'HAZARD',
- id: 'h1',
- code: 'YH-20261113175702',
- name: '322322',
- attributes: { reportTime: '2026-11-13T17:57:10', rectifyDeadline: '2026-11-13T00:00:00', ...attributes },
- })
- }
- function resourceView(attributes = {}) {
- return assetView({
- category: 'EMERGENCY_RESOURCE',
- id: 'e1',
- code: '8652052335',
- name: '漏失监测',
- attributes: { installTime: '2026-10-26T00:00:00', ...attributes },
- })
- }
- function businessFields(view) {
- return view.sections.find((group) => group.title === '业务详情').fields
- }
- test('资产摘要不再有「状态」卡、基本信息不再有「运行状态」行;抬头状态仍在', () => {
- const view = assetView({
- category: 'HAZARD',
- id: 'h1',
- code: 'YH-1',
- name: '322322',
- status: '待核查',
- attributes: { reportTime: '2026-11-13T17:57:10' },
- })
- assert.equal(view.status, '待核查')
- assert.equal(view.summary.some((item) => item.label === '状态'), false)
- const basic = view.sections.find((group) => group.title === '基本信息')
- assert.equal(basic.fields.some((item) => item.label === '运行状态'), false)
- })
- test('防护目标没有业务编码列:不生成编码字段,抬头不拼接「编码未提供」', () => {
- const view = assetView({
- category: 'PROTECTION_TARGET',
- id: 'risk001',
- code: 'risk001',
- name: '郑东新区CBD商业中心',
- status: '1',
- attributes: { riskLevel: '1', riskScore: 72.5, riskColor: '1' },
- })
- assert.equal(view.subtitle, '应急对象')
- const basic = view.sections.find((group) => group.title === '基本信息')
- assert.equal(basic.fields.some((item) => item.label === '设施编码'), false)
- })
- test('应急对象基本信息用「对象编码/对象类别」,编码整行;设施编码同样整行', () => {
- const resource = assetView({
- category: 'EMERGENCY_RESOURCE',
- id: 'e1',
- code: '41010500002000000004/34020000001310000007',
- name: '过道1',
- attributes: { installTime: '2026-10-26T00:00:00' },
- })
- const basic = resource.sections.find((group) => group.title === '基本信息')
- assert.equal(basic.fields.some((item) => item.label === '设施编码' || item.label === '设施类别'), false)
- const code = basic.fields.find((item) => item.label === '对象编码')
- assert.equal(code.value, '41010500002000000004/34020000001310000007')
- assert.equal(code.wide, true)
- assert.equal(basic.fields.find((item) => item.label === '对象类别').value, '应急资源')
- const pipe = assetView({
- category: 'PIPE_NETWORK',
- id: 'p1',
- code: 'GD-41010500002000000004',
- name: '测试管线',
- attributes: { buildDate: '2020-05-01' },
- })
- const pipeBasic = pipe.sections.find((group) => group.title === '基本信息')
- assert.equal(pipeBasic.fields.find((item) => item.label === '设施编码').wide, true)
- })
- test('时间戳统一为 yyyy-MM-dd HH:mm:ss:评估时间、数据更新时间(摘要与明细同源)', () => {
- const view = assetView({
- category: 'PROTECTION_TARGET',
- id: 'risk001',
- code: 'risk001',
- name: '郑东新区CBD商业中心',
- status: '1',
- updatedAt: '2025-01-15T10:00:00+08:00',
- attributes: { riskLevel: '1', riskScore: 72.5, assessmentTime: '2025-01-15T10:00:00' },
- })
- const basic = view.sections.find((group) => group.title === '基本信息')
- assert.equal(basic.fields.find((item) => item.label === '数据更新时间').value, '2025-01-15 10:00:00')
- assert.equal(businessFields(view).find((item) => item.label === '评估时间').value, '2025-01-15 10:00:00')
- assert.equal(view.summary.find((item) => item.label === '评估时间').value, '2025-01-15 10:00:00')
- })
- test('纯日期字段只显示 yyyy-MM-dd,不补 00:00:00', () => {
- assert.equal(businessFields(hazardView()).find((item) => item.label === '整改期限').value, '2026-11-13')
- const pipe = assetView({
- category: 'PIPE_NETWORK',
- id: 'p1',
- code: 'GD-1',
- name: '测试管线',
- attributes: { buildDate: '2020-05-01T00:00:00' },
- })
- assert.equal(businessFields(pipe).find((item) => item.label === '建设日期').value, '2020-05-01')
- })
- test('关联项按源表列存在:有列缺值显示「未提供」,无列不生成该行', () => {
- // 隐患台账有 network_id / work_order_id 列:缺值仍保留行
- const hazardLabels = businessFields(hazardView()).map((item) => item.label)
- assert.equal(hazardLabels.includes('关联管网'), true)
- assert.equal(hazardLabels.includes('关联工单'), true)
- assert.equal(businessFields(hazardView()).find((item) => item.label === '关联管网').value, '未提供')
- // 设备台账没有这三列:整行不生成
- const resourceLabels = businessFields(resourceView()).map((item) => item.label)
- assert.equal(resourceLabels.some((label) => ['关联管网', '关联设备', '关联工单'].includes(label)), false)
- // 风险评估表有 network_id 列:缺值保留
- const target = assetView({
- category: 'PROTECTION_TARGET',
- id: 'risk001',
- name: '防护目标',
- attributes: { riskLevel: '1' },
- })
- assert.equal(businessFields(target).find((item) => item.label === '关联管网').value, '未提供')
- })
- test('危险源报告时间与应急资源安装时间按完整时间戳展示', () => {
- assert.equal(businessFields(hazardView()).find((item) => item.label === '报告时间').value, '2026-11-13 17:57:10')
- assert.equal(businessFields(resourceView()).find((item) => item.label === '安装时间').value, '2026-10-26 00:00:00')
- })
|