| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- 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'
- // Gogs #55:管网状态以数据库口径为准 —— 0-正常 / 1-维护中 / 2-异常。
- test('pipe status labels follow the three-value contract', () => {
- assert.deepEqual(FACILITY_STATUS_LABELS.pipe, { 0: '正常', 1: '维护中', 2: '异常' })
- assert.equal(resolveFacilityStatusLabel('pipe', '0'), '正常')
- assert.equal(resolveFacilityStatusLabel('pipe', '1'), '维护中')
- assert.equal(resolveFacilityStatusLabel('pipe', '2'), '异常')
- assert.equal(resolveFacilityStatusLabel('pipe', 2), '异常')
- })
- test('pipe status colors are green / orange / red in both list and detail', () => {
- assert.deepEqual(FACILITY_STATUS_TAG_TYPES.pipe, { 0: 'success', 1: 'warning', 2: 'danger' })
- assert.equal(resolveFacilityStatusTagType('pipe', '0'), 'success')
- assert.equal(resolveFacilityStatusTagType('pipe', '1'), 'warning')
- assert.equal(resolveFacilityStatusTagType('pipe', '2'), 'danger')
- assert.equal(resolveFacilityStatusTagType('pipe', null), 'info')
- })
- test('status 2 is no longer reported as unknown for pipes', () => {
- assert.notEqual(resolveFacilityStatusLabel('pipe', '2'), '未知')
- assert.notEqual(resolveFacilityStatusTagType('pipe', '2'), 'info')
- })
- test('pipe detail drawer resolves the same three-value labels', () => {
- const detail = formatFacilityDetail({ status: 1, networkName: '输水干线' }, 'pipe')
- assert.ok(detail.some(item => item.label === '运行状态' && item.value === '维护中'))
- const abnormal = formatFacilityDetail({ status: 2 }, 'pipe')
- assert.ok(abnormal.some(item => item.label === '运行状态' && item.value === '异常'))
- })
- test('pipe query page keeps dict-driven labels and a shared three-value color helper', () => {
- const source = fs.readFileSync('src/views/subSystem/basic/pipeInfo/index.vue', 'utf8')
- assert.match(source, /getDicts\('pipe_network_status'\)/u)
- assert.match(source, /statusTagType\(row\.status\)/u)
- assert.match(source, /statusTagType\(detailData\.status\)/u)
- assert.match(source, /'0': 'success', '1': 'warning', '2': 'danger'/u)
- assert.doesNotMatch(source, /status\) === '0' \? 'success' : 'danger'/u)
- })
- test('gas pipe network page shares the same three-value colors for the same table', () => {
- const source = fs.readFileSync('src/views/subSystem/basic/PipeNetwork.vue', 'utf8')
- assert.match(source, /statusTagType\(row\.status\)/u)
- assert.match(source, /'0': 'success', '1': 'warning', '2': 'danger'/u)
- assert.doesNotMatch(source, /row\.status === '0' \? 'success' : 'danger'/u)
- })
|