import test from 'node:test'
import assert from 'node:assert/strict'
import { readFile } from 'node:fs/promises'
import { getMapClusterIcon, getMonitoringPointColor, getMonitoringPointIcon, getMonitoringPointLabel, getMonitoringPointStatus, getMonitoringPointTagType } from '../src/utils/gisMapColors.js'
import { getFacilityStatusIcon, getFacilityStatusMeta } from '../src/utils/gisMapColors.js'
test('shared gis map canvas converts WGS84 coordinates before BMapGL rendering', async () => {
const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
assert.match(source, /import \{ convertCoord \} from '@\/utils\/coordTransform'/u)
assert.match(source, /const \[lng, lat\] = convertCoord\(point\.lng, point\.lat\)/u)
assert.match(source, /new BMapGL\.Point\(lng, lat\)/u)
assert.match(source, /mapInstance\.setViewport\(bmapPoints/u)
assert.doesNotMatch(source, /new BMapGL\.Point\(point\.lng, point\.lat\)/u)
})
test('shared gis map canvas renders pipelines without endpoint markers', async () => {
const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
const addLine = source.match(/function addLine\(BMapGL, line\) \{[\s\S]*?\n\}/u)?.[0] || ''
assert.match(addLine, /new BMapGL\.Polyline\(bmapPoints/u)
assert.match(addLine, /emit\('line-click', line\)/u)
assert.doesNotMatch(addLine, /new BMapGL\.Marker/u)
assert.doesNotMatch(addLine, /new BMapGL\.Label/u)
assert.doesNotMatch(addLine, /起点/u)
assert.doesNotMatch(addLine, /终点/u)
})
test('shared gis map canvas renders contextual clusters with colorful mixed icons', async () => {
const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
const addClusterMarker = source.match(/function addClusterMarker\(BMapGL, cluster\) \{[\s\S]*?\n\}/u)?.[0] || ''
assert.match(source, /import \{ mergeMapPoints \} from '@\/utils\/gisMapClustering'/u)
assert.match(source, /clusterRadius: \{ type: Number, default: 48 \}/u)
assert.match(source, /clusterLabel: \{ type: String, default: '点位集合' \}/u)
assert.match(source, /mergeMapPoints\(renderPoints, projectMapPoint, props\.clusterRadius\)/u)
assert.match(source, /getMapClusterIcon\(cluster\.points\)/u)
assert.match(source, /escapeHtml\(props\.clusterLabel\)/u)
assert.match(source, /focusCluster\(cluster\)/u)
assert.match(source, /emit\('cluster-click', cluster\)/u)
assert.match(source, /function isClusterUnexpandable\(cluster\)/u)
assert.match(addClusterMarker, /if \(isClusterUnexpandable\(cluster\)\) emit\('cluster-click', cluster\)/u)
assert.doesNotMatch(addClusterMarker, /props\.showMarkerName/u)
assert.match(source, /mapInstance\.addEventListener\('moveend', renderScene\)/u)
assert.match(source, /mapInstance\.addEventListener\('zoomend', renderScene\)/u)
})
test('shared gis map canvas renders every point as an official icon with a label above it', async () => {
const source = await readFile('src/components/GisMapCanvas.vue', 'utf8')
assert.match(source, /function escapeHtml\(value\)/u)
assert.match(source, /let bmapLoadTimer = null/u)
assert.match(source, /let disposed = false/u)
assert.match(source, /if \(disposed\) \{[\s\S]*?clearInterval\(bmapLoadTimer\)/u)
assert.match(source, /if \(disposed \|\| !mapContainer\.value\) return/u)
assert.match(source, /onBeforeUnmount\(\(\) => \{[\s\S]*?disposed = true/u)
assert.match(source, /clearInterval\(bmapLoadTimer\)/u)
assert.match(source, /markerSize: \{ type: Number, default: 28 \}/u)
assert.match(source, /const iconUrl = point\.iconUrl \|\| getMonitoringPointIcon\(point\)/u)
assert.match(source, /new BMapGL\.Icon\(iconUrl, new BMapGL\.Size\(size, size\), \{/u)
assert.match(source, /anchor: new BMapGL\.Size\(size \/ 2, size\)/u)
assert.match(source, /const marker = new BMapGL\.Marker\(position, \{/u)
assert.match(source, /new BMapGL\.Label\(`
/u)
assert.match(source, /offset: new BMapGL\.Size\(-28, -props\.markerSize - 18\)/u)
assert.match(source, /width: 56px/u)
assert.match(source, /overflow-wrap: anywhere/u)
assert.doesNotMatch(source, /white-space: nowrap/u)
assert.doesNotMatch(source, /
![]()
{
// 供水设施一张图与首页统一:绿-正常、红-报警/异常、蓝-工单/检修、黄-预警/欠费
assert.deepEqual(getFacilityStatusMeta('source', 0), { key: 'normal', text: '正常' })
assert.deepEqual(getFacilityStatusMeta('source', 1), { key: 'alarm', text: '异常' })
assert.deepEqual(getFacilityStatusMeta('plant', 1), { key: 'alarm', text: '停产' })
assert.deepEqual(getFacilityStatusMeta('pumpStation', 1), { key: 'alarm', text: '故障停运' })
assert.deepEqual(getFacilityStatusMeta('pumpStation', 2), { key: 'workOrder', text: '检修中' })
assert.deepEqual(getFacilityStatusMeta('user', 1), { key: 'warning', text: '欠费' })
assert.deepEqual(getFacilityStatusMeta('user', 2), { key: 'alarm', text: '停用' })
// 未维护状态的设施按正常处理,不臆造异常
assert.deepEqual(getFacilityStatusMeta('source', null), { key: 'normal', text: '正常' })
assert.deepEqual(getFacilityStatusMeta('plant', undefined), { key: 'normal', text: '正常' })
assert.deepEqual(getFacilityStatusMeta('source', 9), { key: 'normal', text: '正常' })
assert.deepEqual(getFacilityStatusMeta('unknown', 1), { key: 'normal', text: '正常' })
})
test('facility gis page colors points by facility status instead of facility type', async () => {
const source = await readFile('src/views/subSystem/waterSupply/facility/gis.vue', 'utf8')
assert.match(source, /getFacilityStatusMeta/u)
assert.match(source, /getFacilityStatusIcon/u)
assert.doesNotMatch(source, /iconUrl: getFacilityPointIcon\(point\.type\)/u)
assert.match(source, /设施状态图例/u)
})
test('pipelines keep no point icon while facilities map status to the shared palette', () => {
// 管网保持现状:只构造管线,不添加图标
assert.equal(getFacilityStatusIcon('pipe', 0), null)
assert.match(getFacilityStatusIcon('source', 0), /T_MarkPoint_Green\.png/u)
assert.match(getFacilityStatusIcon('source', 1), /T_MarkPoint_Red\.png/u)
assert.match(getFacilityStatusIcon('pumpStation', 2), /T_MarkPoint_Blue\.png/u)
assert.match(getFacilityStatusIcon('user', 1), /T_MarkPoint_Yellow\.png/u)
})
test('cluster icons reuse the single member icon or fall back to the colorful marker', () => {
assert.match(getMapClusterIcon([{ alarmStatus: 1 }, { alarmStatus: 1 }]), /T_MarkPoint_Red\.png/u)
assert.match(getMapClusterIcon([{ onlineStatus: 0 }, { onlineStatus: 0 }]), /T_MarkPoint_Grey\.png/u)
assert.match(getMapClusterIcon([{ alarmStatus: 1 }, { onlineStatus: 0 }]), /T_MarkPoint_Colorful\.png/u)
})
test('monitoring point colors follow the documented status semantics', () => {
assert.equal(getMonitoringPointStatus({ relatedOrderNo: 'WO-1' }), 'workOrder')
assert.equal(getMonitoringPointStatus({ relatedWorkOrderNo: 'WO-2' }), 'workOrder')
assert.equal(getMonitoringPointStatus({ orderNo: 'WO-3', orderStatus: 5 }), 'normal')
assert.equal(getMonitoringPointStatus({ orderNo: 'WO-4', orderStatus: 7, deviceAlarmStatus: 1 }), 'alarm')
assert.equal(getMonitoringPointStatus({ alarmStatus: 1 }), 'alarm')
assert.equal(getMonitoringPointStatus({ currentStatus: 3 }), 'warning')
assert.equal(getMonitoringPointStatus({ onlineStatus: 0 }), 'offline')
assert.equal(getMonitoringPointStatus({}), 'normal')
assert.equal(getMonitoringPointColor({ relatedOrderNo: 'WO-1' }), '#3498db')
assert.equal(getMonitoringPointColor({ alarmStatus: 1 }), '#e74c3c')
assert.equal(getMonitoringPointColor({ currentStatus: 3 }), '#f1c40f')
assert.equal(getMonitoringPointColor({ onlineStatus: 0 }), '#95a5a6')
assert.equal(getMonitoringPointColor({}), '#2ecc71')
assert.match(getMonitoringPointIcon({ relatedOrderNo: 'WO-1' }), /T_MarkPoint_Blue\.png/u)
assert.match(getMonitoringPointIcon({ alarmStatus: 1 }), /T_MarkPoint_Red\.png/u)
assert.match(getMonitoringPointIcon({ currentStatus: 3 }), /T_MarkPoint_Yellow\.png/u)
assert.match(getMonitoringPointIcon({ onlineStatus: 0 }), /T_MarkPoint_Grey\.png/u)
assert.match(getMonitoringPointIcon({}), /T_MarkPoint_Green\.png/u)
assert.equal(getMonitoringPointLabel({ currentStatus: 3 }), '预警')
assert.equal(getMonitoringPointLabel({ relatedWorkOrderNo: 'WO-2' }), '关联工单')
assert.equal(getMonitoringPointTagType({ relatedWorkOrderNo: 'WO-2' }), 'primary')
assert.equal(getMonitoringPointTagType({ onlineStatus: 0 }), 'info')
})
test('an explicit status key wins over inferred monitoring point fields', () => {
const offlineAlarmRecord = { statusKey: 'offline', alarmStatus: 1, onlineStatus: 0 }
assert.equal(getMonitoringPointStatus(offlineAlarmRecord), 'offline')
assert.equal(getMonitoringPointColor(offlineAlarmRecord), '#95a5a6')
assert.match(getMonitoringPointIcon(offlineAlarmRecord), /T_MarkPoint_Grey\.png/u)
const handledAlarm = { statusKey: 'normal', alarmStatus: 1 }
assert.equal(getMonitoringPointStatus(handledAlarm), 'normal')
assert.match(getMonitoringPointIcon(handledAlarm), /T_MarkPoint_Green\.png/u)
assert.equal(getMonitoringPointStatus({ statusKey: '未知状态', alarmStatus: 1 }), 'alarm')
})
test('water supply GIS pages share the common canvas component', async () => {
const deviceSource = await readFile('src/views/subSystem/waterSupply/components/WaterDeviceGisMap.vue', 'utf8')
const facilitySource = await readFile('src/views/subSystem/waterSupply/facility/gis.vue', 'utf8')
assert.match(deviceSource, /
关联工单/u)
assert.match(deviceSource, /legend-dot warning/u)
assert.match(deviceSource, /getMonitoringPointTagType/u)
assert.match(deviceSource, /:points="mapPoints"/u)
assert.match(deviceSource, /@point-click="openDetail\(\$event\.equipmentId\)"/u)
assert.match(facilitySource, /