import test from 'node:test' import assert from 'node:assert/strict' import fs from 'node:fs' import { FACILITY_STATUS_LABELS, FACILITY_STATUS_TAG_TYPES, resolveFacilityStatusLabel, resolveFacilityStatusTagType } from '../src/utils/waterFacilityStatisticsModel.js' import { formatFacilityDetail } from '../src/utils/waterFacilityGisModel.js' // 管网状态与其他设施统一为两值域:0-正常 / 1-异常。 test('pipe status labels follow the two-value contract', () => { assert.deepEqual(FACILITY_STATUS_LABELS.pipe, { 0: '正常', 1: '异常' }) assert.equal(resolveFacilityStatusLabel('pipe', '0'), '正常') assert.equal(resolveFacilityStatusLabel('pipe', '1'), '异常') assert.equal(resolveFacilityStatusLabel('pipe', 1), '异常') assert.equal(resolveFacilityStatusLabel('pipe', '2'), '未知') }) test('pipe status colors are green / red in both list and detail', () => { assert.deepEqual(FACILITY_STATUS_TAG_TYPES.pipe, { 0: 'success', 1: 'danger' }) assert.equal(resolveFacilityStatusTagType('pipe', '0'), 'success') assert.equal(resolveFacilityStatusTagType('pipe', '1'), 'danger') assert.equal(resolveFacilityStatusTagType('pipe', '2'), 'info') assert.equal(resolveFacilityStatusTagType('pipe', null), 'info') }) test('pipe detail drawer resolves the same two-value labels', () => { const normal = formatFacilityDetail({ status: 0, networkName: '输水干线' }, 'pipe') assert.ok(normal.some(item => item.label === '运行状态' && item.value === '正常')) const abnormal = formatFacilityDetail({ status: 1 }, 'pipe') assert.ok(abnormal.some(item => item.label === '运行状态' && item.value === '异常')) }) test('pipe query page uses shared status dict and hides networkLevel in list/form', () => { const source = fs.readFileSync('src/views/subSystem/pipeNetwork/facilities/pipeNetwork/index.vue', 'utf8') assert.match(source, /loadDict\("infrastructure_status", statusDict\)/u) assert.match(source, /const type = hit && hit\.listClass/u) assert.match(source, /getStatusTagType\(scope\.row\.status\)/u) assert.match(source, /getStatusText\(scope\.row\.status\)/u) assert.doesNotMatch(source, /prop="networkLevel"/u) assert.doesNotMatch(source, /维护中/u) })