|
|
@@ -8,6 +8,13 @@ import {
|
|
|
FACILITY_SECTION_TYPES,
|
|
|
FACILITY_STATUS_TAG_TYPES,
|
|
|
getFacilityStatusOptions,
|
|
|
+ flattenStatisticMetrics,
|
|
|
+ formatStatisticRow,
|
|
|
+ normalizeStatisticKey,
|
|
|
+ resolveDistributionValueLabel,
|
|
|
+ resolveFacilitySectionLabel,
|
|
|
+ resolveStatisticMetricDescription,
|
|
|
+ resolveStatisticMetricLabel,
|
|
|
resolveFacilityStatusLabel
|
|
|
} from '../src/utils/waterFacilityStatisticsModel.js'
|
|
|
|
|
|
@@ -63,7 +70,7 @@ test('statistics table uses Chinese field labels and explicit hints', () => {
|
|
|
'utf8'
|
|
|
)
|
|
|
|
|
|
- assert.match(source, /STATISTIC_LABELS/u)
|
|
|
+ assert.match(source, /formatStatisticRow/u)
|
|
|
assert.match(source, /el-tooltip content="按设施类型汇总的关键统计指标"/u)
|
|
|
assert.match(source, /el-tooltip content="当前行的统计口径和数据来源"/u)
|
|
|
})
|
|
|
@@ -73,8 +80,9 @@ test('statistics status rows use the agreed unknown label', () => {
|
|
|
'src/views/subSystem/waterSupply/components/WaterFacilityDashboard.vue',
|
|
|
'utf8'
|
|
|
)
|
|
|
+ const model = fs.readFileSync('src/utils/waterFacilityStatisticsModel.js', 'utf8')
|
|
|
|
|
|
- assert.match(source, /resolveFacilityStatusLabel\(facilityType, item\.name\)/u)
|
|
|
+ assert.match(model, /resolveFacilityStatusLabel\(facilityType, item\.name\)/u)
|
|
|
assert.match(source, /category === 'normal' \? '正常' : '未知'/u)
|
|
|
assert.doesNotMatch(source, /未填报/u)
|
|
|
})
|
|
|
@@ -199,8 +207,95 @@ test('statistics charts hide status series without data', () => {
|
|
|
'src/views/subSystem/waterSupply/components/WaterFacilityDashboard.vue',
|
|
|
'utf8'
|
|
|
)
|
|
|
+ const model = fs.readFileSync('src/utils/waterFacilityStatisticsModel.js', 'utf8')
|
|
|
|
|
|
assert.match(source, /\.filter\(series => facilityOverview\.some\(item => Number\(item\[series\.key\] \|\| 0\) > 0\)\)/u)
|
|
|
- assert.match(source, /resolveFacilityStatusLabel\(facilityType, item\.name\)/u)
|
|
|
+ assert.match(model, /resolveFacilityStatusLabel\(facilityType, item\.name\)/u)
|
|
|
assert.doesNotMatch(source, /未填报/u)
|
|
|
})
|
|
|
+
|
|
|
+test('statistics metric keys accept both snake_case and camelCase', () => {
|
|
|
+ assert.equal(normalizeStatisticKey('total_count'), 'totalCount')
|
|
|
+ assert.equal(normalizeStatisticKey('totalCount'), 'totalCount')
|
|
|
+ assert.equal(normalizeStatisticKey('annual_water_consumption'), 'annualWaterConsumption')
|
|
|
+
|
|
|
+ assert.equal(resolveStatisticMetricLabel('total_count'), '总数')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('total_length'), '总长度')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('average_diameter'), '平均管径')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('design_capacity'), '设计规模')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('current_capacity'), '实际规模')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('pump_count'), '水泵数量')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('design_flow'), '设计流量')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('design_head'), '设计扬程')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('power_capacity'), '装机容量')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('annual_water_consumption'), '年用水量')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('capacity_utilization'), '产能利用率')
|
|
|
+ assert.equal(resolveStatisticMetricLabel('totalCount'), '总数')
|
|
|
+})
|
|
|
+
|
|
|
+test('statistics detail table never falls back to english keys or codes', () => {
|
|
|
+ assert.equal(resolveStatisticMetricLabel('unknown_metric_xyz'), '其他指标')
|
|
|
+ assert.equal(resolveStatisticMetricDescription('unknown_metric_xyz'), '按当前筛选条件统计')
|
|
|
+ assert.equal(resolveStatisticMetricDescription('total_length'), '当前筛选条件下的管网总长度')
|
|
|
+ assert.equal(resolveFacilitySectionLabel('unknownSection'), '总览')
|
|
|
+ assert.equal(resolveFacilitySectionLabel('pipeNetwork'), '管网')
|
|
|
+})
|
|
|
+
|
|
|
+test('statistics distribution groups translate coded values', () => {
|
|
|
+ assert.equal(resolveDistributionValueLabel('materialDistribution', 'PE'), '聚乙烯')
|
|
|
+ assert.equal(resolveDistributionValueLabel('materialDistribution', 'PVC-U'), '硬聚氯乙烯')
|
|
|
+ assert.equal(resolveDistributionValueLabel('materialDistribution', '铸铁'), '铸铁')
|
|
|
+ assert.equal(resolveDistributionValueLabel('materialDistribution', null), '未填报')
|
|
|
+ assert.equal(resolveDistributionValueLabel('waterSourceTypeDistribution', '地下水'), '地下水')
|
|
|
+})
|
|
|
+
|
|
|
+test('statistics detail rows render backend payload without english text', () => {
|
|
|
+ const payload = {
|
|
|
+ pipeNetwork: {
|
|
|
+ total_count: 996,
|
|
|
+ total_length: 18819.43,
|
|
|
+ average_diameter: 334.53,
|
|
|
+ materialDistribution: [
|
|
|
+ { name: 'PE', value: 277, unit: '条' },
|
|
|
+ { name: '铸铁', value: 183, unit: '条' }
|
|
|
+ ],
|
|
|
+ statusDistribution: [{ name: '2', value: 4, unit: '条' }]
|
|
|
+ },
|
|
|
+ waterPlant: {
|
|
|
+ design_capacity: 5,
|
|
|
+ current_capacity: 4,
|
|
|
+ capacity_utilization: 80,
|
|
|
+ capacityUtilization: { value: 80, unit: '%' }
|
|
|
+ },
|
|
|
+ waterSource: { qualityDistribution: [{ name: 'Ⅳ类', value: 1, unit: '处' }] }
|
|
|
+ }
|
|
|
+
|
|
|
+ const rows = Object.entries(payload)
|
|
|
+ .flatMap(([section, value]) => flattenStatisticMetrics(section, value))
|
|
|
+ .map(item => formatStatisticRow(item.section, item, { levelLabel: name => `第${name}级` }))
|
|
|
+
|
|
|
+ const cells = rows.map(row => `${row.section}|${row.name}|${row.description}`).join('\n')
|
|
|
+ assert.doesNotMatch(cells, /[A-Za-z]{2,}/u)
|
|
|
+ assert.doesNotMatch(cells, /\bvalue\b|\bunit\b/u)
|
|
|
+
|
|
|
+ assert.equal(rows.find(row => row.section === '管网 - 总数').name, '总数')
|
|
|
+ assert.equal(rows.find(row => row.section === '管网 - 总长度').value, 18819.43)
|
|
|
+ assert.equal(rows.find(row => row.section === '管网 - 管材分布').name, '聚乙烯')
|
|
|
+ assert.equal(rows.find(row => row.section === '管网 - 管材分布').value, 277)
|
|
|
+ assert.equal(rows.find(row => row.section === '管网 - 状态分布').name, '异常')
|
|
|
+ assert.equal(rows.find(row => row.section === '水厂 - 产能利用率').name, '产能利用率')
|
|
|
+ assert.equal(rows.find(row => row.section === '水源地 - 水质等级分布').name, 'Ⅳ类')
|
|
|
+})
|
|
|
+
|
|
|
+test('statistics detail table uses the shared chinese label helpers', () => {
|
|
|
+ const source = fs.readFileSync(
|
|
|
+ 'src/views/subSystem/waterSupply/components/WaterFacilityDashboard.vue',
|
|
|
+ 'utf8'
|
|
|
+ )
|
|
|
+
|
|
|
+ assert.match(source, /flattenStatisticMetrics/u)
|
|
|
+ assert.match(source, /formatStatisticRow\(item\.section, item, \{ levelLabel: resolveLevelLabel \}\)/u)
|
|
|
+ assert.match(source, /resolveLevelLabel/u)
|
|
|
+ assert.doesNotMatch(source, /STATISTIC_LABELS/u)
|
|
|
+ assert.doesNotMatch(source, /\|\| rawMetricKey/u)
|
|
|
+})
|