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