waterSupplyThreshold.test.mjs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { readFile } from 'node:fs/promises'
  4. import {
  5. buildThresholdQuery,
  6. buildThresholdSavePayload,
  7. buildThresholdUpdatePayload
  8. } from '../src/utils/waterSupplyUiModel.js'
  9. test('threshold page uses the water-only threshold device endpoint', async () => {
  10. const source = await readFile(
  11. 'src/views/subSystem/waterSupply/components/WaterThresholdPage.vue',
  12. 'utf8'
  13. )
  14. assert.match(source, /listThresholdDevices/u)
  15. assert.doesNotMatch(source, /listDeviceLedger/u)
  16. })
  17. test('threshold drawer follows the shared right-side detail drawer contract', async () => {
  18. const source = await readFile(
  19. 'src/views/subSystem/waterSupply/components/WaterThresholdPage.vue',
  20. 'utf8'
  21. )
  22. assert.match(source, /<el-drawer\b[^>]*direction="rtl"[^>]*>/u)
  23. assert.match(source, /<el-drawer\b[^>]*class="detail-drawer threshold-drawer"[^>]*>/u)
  24. assert.match(source, /\.threshold-drawer\s*\{\s*width:\s*100% !important/u)
  25. })
  26. test('builds the flat batch-save contract expected by the threshold API', () => {
  27. const payload = buildThresholdSavePayload({
  28. id: 'draft-id',
  29. deviceCodes: [' WS-FLOW-1 ', '', 'WS-FLOW-2', 'WS-FLOW-1'],
  30. warningType: ' 流量预警 ',
  31. warningCode: ' WARN-FLOW ',
  32. minValue: '20',
  33. maxValue: '40',
  34. periodStart: '08:00',
  35. periodEnd: '20:00',
  36. remark: ' 高峰期阈值 '
  37. })
  38. assert.deepEqual(payload, {
  39. deviceCodes: ['WS-FLOW-1', 'WS-FLOW-2'],
  40. warningType: '流量预警',
  41. warningCode: 'WARN-FLOW',
  42. minValue: 20,
  43. maxValue: 40,
  44. periodStart: '08:00',
  45. periodEnd: '20:00',
  46. remark: '高峰期阈值'
  47. })
  48. })
  49. test('builds an update payload that preserves the threshold id', () => {
  50. const payload = buildThresholdUpdatePayload({
  51. id: 'threshold-id',
  52. deviceCode: 'WS-FLOW-1',
  53. warningType: '流量预警',
  54. warningCode: 'WARN-FLOW',
  55. minValue: 20,
  56. maxValue: 40,
  57. periodStart: '08:00',
  58. periodEnd: '20:00',
  59. createTime: '2026-09-02 10:00:00'
  60. })
  61. assert.deepEqual(payload, {
  62. id: 'threshold-id',
  63. deviceCode: 'WS-FLOW-1',
  64. warningType: '流量预警',
  65. warningCode: 'WARN-FLOW',
  66. minValue: 20,
  67. maxValue: 40,
  68. periodStart: '08:00',
  69. periodEnd: '20:00'
  70. })
  71. })
  72. test('builds threshold list filters without alarm-only fields', () => {
  73. const query = buildThresholdQuery({
  74. pageNum: 2,
  75. pageSize: 20,
  76. deviceCode: 'WS-FLOW-1',
  77. warningType: '流量预警',
  78. keyword: ' ',
  79. alarmLevel: 2,
  80. alarmStatus: 0
  81. })
  82. assert.deepEqual(query, {
  83. pageNum: 2,
  84. pageSize: 20,
  85. deviceCode: 'WS-FLOW-1',
  86. warningType: '流量预警'
  87. })
  88. })