waterPipeNetworkStatusThreeValues.test.mjs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import fs from 'node:fs'
  4. import {
  5. FACILITY_STATUS_LABELS,
  6. FACILITY_STATUS_TAG_TYPES,
  7. resolveFacilityStatusLabel,
  8. resolveFacilityStatusTagType
  9. } from '../src/utils/waterFacilityStatisticsModel.js'
  10. import { formatFacilityDetail } from '../src/utils/waterFacilityGisModel.js'
  11. // Gogs #55:管网状态以数据库口径为准 —— 0-正常 / 1-维护中 / 2-异常。
  12. test('pipe status labels follow the three-value contract', () => {
  13. assert.deepEqual(FACILITY_STATUS_LABELS.pipe, { 0: '正常', 1: '维护中', 2: '异常' })
  14. assert.equal(resolveFacilityStatusLabel('pipe', '0'), '正常')
  15. assert.equal(resolveFacilityStatusLabel('pipe', '1'), '维护中')
  16. assert.equal(resolveFacilityStatusLabel('pipe', '2'), '异常')
  17. assert.equal(resolveFacilityStatusLabel('pipe', 2), '异常')
  18. })
  19. test('pipe status colors are green / orange / red in both list and detail', () => {
  20. assert.deepEqual(FACILITY_STATUS_TAG_TYPES.pipe, { 0: 'success', 1: 'warning', 2: 'danger' })
  21. assert.equal(resolveFacilityStatusTagType('pipe', '0'), 'success')
  22. assert.equal(resolveFacilityStatusTagType('pipe', '1'), 'warning')
  23. assert.equal(resolveFacilityStatusTagType('pipe', '2'), 'danger')
  24. assert.equal(resolveFacilityStatusTagType('pipe', null), 'info')
  25. })
  26. test('status 2 is no longer reported as unknown for pipes', () => {
  27. assert.notEqual(resolveFacilityStatusLabel('pipe', '2'), '未知')
  28. assert.notEqual(resolveFacilityStatusTagType('pipe', '2'), 'info')
  29. })
  30. test('pipe detail drawer resolves the same three-value labels', () => {
  31. const detail = formatFacilityDetail({ status: 1, networkName: '输水干线' }, 'pipe')
  32. assert.ok(detail.some(item => item.label === '运行状态' && item.value === '维护中'))
  33. const abnormal = formatFacilityDetail({ status: 2 }, 'pipe')
  34. assert.ok(abnormal.some(item => item.label === '运行状态' && item.value === '异常'))
  35. })
  36. test('pipe query page keeps dict-driven labels and a shared three-value color helper', () => {
  37. const source = fs.readFileSync('src/views/subSystem/basic/pipeInfo/index.vue', 'utf8')
  38. assert.match(source, /getDicts\('pipe_network_status'\)/u)
  39. assert.match(source, /statusTagType\(row\.status\)/u)
  40. assert.match(source, /statusTagType\(detailData\.status\)/u)
  41. assert.match(source, /'0': 'success', '1': 'warning', '2': 'danger'/u)
  42. assert.doesNotMatch(source, /status\) === '0' \? 'success' : 'danger'/u)
  43. })
  44. test('gas pipe network page shares the same three-value colors for the same table', () => {
  45. const source = fs.readFileSync('src/views/subSystem/basic/PipeNetwork.vue', 'utf8')
  46. assert.match(source, /statusTagType\(row\.status\)/u)
  47. assert.match(source, /'0': 'success', '1': 'warning', '2': 'danger'/u)
  48. assert.doesNotMatch(source, /row\.status === '0' \? 'success' : 'danger'/u)
  49. })