waterPipeNetworkStatusTwoValues.test.mjs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. // 管网状态与其他设施统一为两值域:0-正常 / 1-异常。
  12. test('pipe status labels follow the two-value contract', () => {
  13. assert.deepEqual(FACILITY_STATUS_LABELS.pipe, { 0: '正常', 1: '异常' })
  14. assert.equal(resolveFacilityStatusLabel('pipe', '0'), '正常')
  15. assert.equal(resolveFacilityStatusLabel('pipe', '1'), '异常')
  16. assert.equal(resolveFacilityStatusLabel('pipe', 1), '异常')
  17. assert.equal(resolveFacilityStatusLabel('pipe', '2'), '未知')
  18. })
  19. test('pipe status colors are green / red in both list and detail', () => {
  20. assert.deepEqual(FACILITY_STATUS_TAG_TYPES.pipe, { 0: 'success', 1: 'danger' })
  21. assert.equal(resolveFacilityStatusTagType('pipe', '0'), 'success')
  22. assert.equal(resolveFacilityStatusTagType('pipe', '1'), 'danger')
  23. assert.equal(resolveFacilityStatusTagType('pipe', '2'), 'info')
  24. assert.equal(resolveFacilityStatusTagType('pipe', null), 'info')
  25. })
  26. test('pipe detail drawer resolves the same two-value labels', () => {
  27. const normal = formatFacilityDetail({ status: 0, networkName: '输水干线' }, 'pipe')
  28. assert.ok(normal.some(item => item.label === '运行状态' && item.value === '正常'))
  29. const abnormal = formatFacilityDetail({ status: 1 }, 'pipe')
  30. assert.ok(abnormal.some(item => item.label === '运行状态' && item.value === '异常'))
  31. })
  32. test('pipe query page uses shared status dict and hides networkLevel in list/form', () => {
  33. const source = fs.readFileSync('src/views/subSystem/pipeNetwork/facilities/pipeNetwork/index.vue', 'utf8')
  34. assert.match(source, /loadDict\("infrastructure_status", statusDict\)/u)
  35. assert.match(source, /const type = hit && hit\.listClass/u)
  36. assert.match(source, /getStatusTagType\(scope\.row\.status\)/u)
  37. assert.match(source, /getStatusText\(scope\.row\.status\)/u)
  38. assert.doesNotMatch(source, /prop="networkLevel"/u)
  39. assert.doesNotMatch(source, /维护中/u)
  40. })