overviewPerceptionCards.test.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import assert from 'node:assert/strict'
  2. import { readFileSync } from 'node:fs'
  3. import test from 'node:test'
  4. import { toPerception } from '../src/modules/cockpit/domain/overviewPanels.js'
  5. const raw = {
  6. updatedAt: '2026-12-01 10:00:00',
  7. totals: { deviceCount: 443, onlineCount: 300, offlineCount: 143, onlineRate: { state: 'OK', value: '0.6772' } },
  8. byType: [
  9. { code: '1', name: '供水设备', deviceCount: 16, onlineCount: 12, offlineCount: 4, monitoringContent: '供水压力监测 / 供水瞬时流量监测 / 供水漏失监测' },
  10. { code: '2', name: '排水设备', deviceCount: 52, onlineCount: 40, offlineCount: 12, monitoringContent: '排水瞬时流量监测 / 排水流速监测 / 排水液位监测' },
  11. { code: '3', name: '燃气设备', deviceCount: 32, onlineCount: 20, offlineCount: 12, monitoringContent: '可燃气体浓度监测 / 可燃气体温度监测' },
  12. { code: '4', name: '窨井设备', deviceCount: 343, onlineCount: 228, offlineCount: 115, monitoringContent: '井盖倾斜监测 / 井盖水浸监测' },
  13. ],
  14. byDistrict: [],
  15. }
  16. test('类型卡小字按行业给一条举例设备类型,长短一致不再换行', () => {
  17. const types = toPerception(raw).types
  18. assert.deepEqual(types.map((row) => row.note), [
  19. '供水压力流量终端 等',
  20. '环境监测终端 等',
  21. '可燃气体监测终端 等',
  22. '窨井监测终端 等',
  23. ])
  24. // 完整监测内容仍保留在悬停标题里,信息不丢。
  25. assert.equal(types[2].noteTitle, '可燃气体浓度监测 / 可燃气体温度监测')
  26. })
  27. test('未登记的行业仍回退到后端监测内容,不画空小字', () => {
  28. const [row] = toPerception({
  29. ...raw,
  30. byType: [{ code: '9', name: '照明设备', deviceCount: 1, monitoringContent: '照明电流监测 / 照明电压监测 / 照明功率监测' }],
  31. }).types
  32. assert.equal(row.note, '照明电流 / 照明电压 等')
  33. })
  34. test('value-first 四卡读数统一字号,不再按每张卡的文本长度各自缩字号', () => {
  35. const source = readFileSync(new URL('../src/modules/cockpit/components/PanelBlocks.vue', import.meta.url), 'utf8')
  36. const style = source.match(/<style[^>]*>([\s\S]*?)<\/style>/)[1]
  37. const readingRules = style
  38. .split('}')
  39. .map((rule) => rule.split('{'))
  40. .filter(([selector, body]) => body && /panel-kpi--value-first/.test(selector) && /panel-kpi__value\b/.test(selector))
  41. assert.ok(readingRules.length > 0, '应有 value-first 读数规则')
  42. for (const [selector, body] of readingRules) {
  43. assert.doesNotMatch(body, /--kpi-reading-em/, `这条规则仍按每卡文本长度收字号:${selector.trim()}`)
  44. }
  45. assert.ok(readingRules.some(([, body]) => /font-size:\s*min\(calc\(22 \* var\(--u, 1px\)\), 34cqw\)/.test(body)))
  46. })