import test from 'node:test' import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import { getFacilityPointIcon, getMapClusterIcon, getMonitoringPointColor, getMonitoringPointIcon, getMonitoringPointLabel, getMonitoringPointStatus, getMonitoringPointTagType } 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 merges overlapping markers and emits cluster clicks', 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, /mergeMapPoints\(renderPoints, projectMapPoint, props\.clusterRadius\)/u) assert.match(source, /getMapClusterIcon\(cluster\.points\)/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\(`