waterDeviceAbnormalBoard.test.mjs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import assert from 'node:assert/strict'
  2. import { readFile } from 'node:fs/promises'
  3. import test from 'node:test'
  4. const pagePath = 'src/views/subSystem/waterSupply/components/WaterDevicePage.vue'
  5. /** 找到 marker 所在标签上离它最近的 v-if 条件,用于校验列/区块的视图可见性 */
  6. function conditionOf(source, marker) {
  7. const at = source.indexOf(marker)
  8. if (at < 0) return null
  9. const before = source.slice(0, at)
  10. const start = before.lastIndexOf('v-if="')
  11. if (start < 0) return null
  12. const end = source.indexOf('"', start + 'v-if="'.length)
  13. return source.slice(start + 'v-if="'.length, end)
  14. }
  15. test('abnormal board shows the district column so the region filter is verifiable', async () => {
  16. const source = await readFile(pagePath, 'utf8')
  17. assert.match(
  18. source,
  19. /label="所属区域"[^>]*>\s*<template #default="\{ row \}">\{\{ row\.district \|\| '-' \}\}/u,
  20. '异常看板应展示所属区域列'
  21. )
  22. assert.match(source, /v-if="view === 'abnormal' \|\| view === 'dispatch'"/u)
  23. })
  24. test('abnormal board detail includes the district field', async () => {
  25. const source = await readFile(pagePath, 'utf8')
  26. assert.match(source, /\['所属区域', detail\.value\.district\]/u)
  27. })
  28. test('abnormal board lists and previews the device image', async () => {
  29. const source = await readFile(pagePath, 'utf8')
  30. const columnCond = conditionOf(source, 'label="设备图片"')
  31. assert.ok(columnCond, '缺少设备图片列')
  32. assert.match(columnCond, /'abnormal'/u, '设备图片列需覆盖异常视图')
  33. assert.match(columnCond, /'ledger'/u, '设备图片列不应丢掉台账视图')
  34. const mediaCond = conditionOf(source, 'class="detail-media"')
  35. assert.ok(mediaCond, '详情抽屉缺少设备图片区块')
  36. assert.match(mediaCond, /'abnormal'/u, '详情图片区块需覆盖异常视图')
  37. })
  38. test('abnormal board is read-only and stats come from the backend aggregate', async () => {
  39. const source = await readFile(pagePath, 'utf8')
  40. assert.match(
  41. source,
  42. /function canDispatch\(row\) \{\s*if \(view !== 'dispatch'\) return false/u,
  43. '异常视图不应保留派单入口'
  44. )
  45. assert.match(
  46. source,
  47. /if \(view === 'abnormal'\) await loadAbnormalStats\(\)/u,
  48. '异常视图应加载后端聚合统计'
  49. )
  50. const statsBlock = source.slice(
  51. source.indexOf('const abnormalStats = computed'),
  52. source.indexOf('const ledgerStatsCards')
  53. )
  54. assert.doesNotMatch(statsBlock, /page\.value\.records/u, '统计卡片不应基于当前分页行计数')
  55. assert.match(statsBlock, /abnormalStatsData\.value\.total/u)
  56. assert.match(statsBlock, /abnormalStatsData\.value\.offline/u)
  57. })