waterAlarmGisPage.test.mjs 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import test from 'node:test'
  2. import assert from 'node:assert/strict'
  3. import { readFile } from 'node:fs/promises'
  4. const readAlarmPage = () => readFile('src/views/subSystem/waterSupply/components/WaterAlarmPage.vue', 'utf8')
  5. test('the alarm map merges the alarm ledger and device points onto the shared canvas', async () => {
  6. const source = await readAlarmPage()
  7. assert.match(source, /buildAlarmGisPoints\(\{/u)
  8. assert.match(source, /async function loadAllAlarmLedgerRows\(\)/u)
  9. assert.match(source, /collected\.length >= ledgerPage\.total/u)
  10. assert.match(source, /getDeviceGisAllPoints\(/u)
  11. assert.match(source, /normalizeDeviceGisPoints[\s\S]*?normalizeDeviceRow/u)
  12. assert.match(source, /:points="gisMapPoints"/u)
  13. assert.match(source, /cluster-label="报警集合"/u)
  14. })
  15. test('clicking a map point or search result locates the alarm and opens the detail drawer', async () => {
  16. const source = await readAlarmPage()
  17. assert.match(source, /@point-click="locateAlarmPoint"/u)
  18. assert.match(source, /function locateAlarmPoint\(point\)[\s\S]*?gisMapRef\.value\?\.locatePoint\(/u)
  19. assert.match(source, /function locateAlarmPoint\(point\)[\s\S]*?openDetail\(point\)/u)
  20. })
  21. test('the alarm map shows distinct empty, failed and retry states', async () => {
  22. const source = await readAlarmPage()
  23. assert.match(source, /const mapLoadError = ref\(''\)/u)
  24. assert.match(source, /mapLoadError\.value = /u)
  25. assert.match(source, /@click="loadData"[^>]*>\s*重试/u)
  26. assert.match(source, /暂无报警点位/u)
  27. assert.match(source, /当前筛选下没有匹配的报警点位/u)
  28. assert.match(source, /v-if="mapEnrichmentWarning"[\s\S]*?v-if="!mapLoadError && mapPoints\.length && !filteredAlarmPoints\.length"/u)
  29. })
  30. test('the alarm map exposes five map states with text, not colour alone', async () => {
  31. const source = await readAlarmPage()
  32. const legendStates = [
  33. ['work-order', '关联工单'],
  34. ['alarm', '报警'],
  35. ['warning', '预警'],
  36. ['offline', '离线'],
  37. ['normal', '正常']
  38. ]
  39. for (const [statusClass, label] of legendStates) {
  40. assert.match(source, new RegExp(`status-dot-${statusClass}"\\/>${label}`, 'u'))
  41. }
  42. assert.match(source, /mapStatistics\.byStatus/u)
  43. })
  44. test('the alarm detail panel keeps device, record and work-order states apart', async () => {
  45. const source = await readAlarmPage()
  46. assert.match(source, /\['报警记录状态', row\.recordStatusText \|\| row\.alarmStatusText\]/u)
  47. assert.match(source, /\['设备报警状态', row\.deviceAlarmStatusText\]/u)
  48. assert.match(source, /\['报警展示状态', row\.displayStatusText\]/u)
  49. assert.match(source, /\['工单状态', row\.orderStatus/u)
  50. assert.match(source, /\['在线状态', row\.onlineStatusText\]/u)
  51. })
  52. test('the alarm map fits all points after the map and data are ready', async () => {
  53. const source = await readAlarmPage()
  54. assert.match(source, /@ready="handleAlarmMapReady"/u)
  55. assert.match(source, /function fitAlarmMap\(\)/u)
  56. assert.match(source, /<el-button :icon="Aim" @click="fitAlarmMap">全图<\/el-button>/u)
  57. })