import test from 'node:test' import assert from 'node:assert/strict' import { readFile } from 'node:fs/promises' import { parse as parseSfc } from '@vue/compiler-sfc' import { parse as parseJs } from '@babel/parser' const homePath = 'src/views/subSystem/waterSupply/components/WaterSupplyHome.vue' test('home API imports all resolve to real named exports', async () => { const { descriptor } = parseSfc(await readFile(homePath, 'utf8')) const imports = parseJs(descriptor.scriptSetup.content, { sourceType: 'module' }).program.body .filter(node => node.type === 'ImportDeclaration' && node.source.value.startsWith('@/api/')) for (const declaration of imports) { const apiPath = declaration.source.value.replace('@/', 'src/') + '.js' const nodes = parseJs(await readFile(apiPath, 'utf8'), { sourceType: 'module' }).program.body const names = nodes.filter(node => node.type === 'ExportNamedDeclaration').flatMap(node => { if (node.declaration?.type === 'VariableDeclaration') return node.declaration.declarations.map(item => item.id.name) return node.declaration?.id ? [node.declaration.id.name] : node.specifiers.map(item => item.exported.name) }) for (const item of declaration.specifiers.filter(item => item.type === 'ImportSpecifier')) { assert.ok(names.includes(item.imported.name), `${apiPath} does not export ${item.imported.name}`) } } }) test('home dashboard uses the unified scoped endpoint instead of the removed ledger dashboard', async () => { const source = await readFile(homePath, 'utf8') assert.doesNotMatch(source, /getAlarmLedgerDashboard/u) assert.match(source, /getAlarmDashboard\(\{ rootTypeId: WATER_DEVICE_ROOT_TYPE_ID, days: trendDays \}\)/u) const api = (await readFile('src/api/alarm.js', 'utf8')) .replace("import request from '@/utils/request'", 'const request = config => Promise.resolve(config)') const { getAlarmDashboard } = await import('data:text/javascript;base64,' + Buffer.from(api).toString('base64')) assert.deepEqual(await getAlarmDashboard({ rootTypeId: 1, days: 7 }), { url: '/api/alarm/dashboard', method: 'get', params: { rootTypeId: 1, days: 7 } }) }) test('home removes the A/B/C placeholder headings', async () => { const source = await readFile(homePath, 'utf8') assert.doesNotMatch(source, /A · 指挥台/u) assert.doesNotMatch(source, /B · 异常待办/u) assert.doesNotMatch(source, /C · 数据总览/u) }) test('home realtime alarms split between audit and work order by display status', async () => { const source = await readFile(homePath, 'utf8') assert.match(source, /openRealtimeAlarm\(item\)/u) assert.match(source, /realtimeAlarmJumpTarget\(item\)/u) assert.match(source, /goPage\(target\.path, target\.query\)/u) assert.match(source, /item\.displayStatusText/u) assert.match(source, /item\.displayStatusType/u) assert.match(source, /goPage\('\/device\/maintain'/u) }) test('home overview uses the shared GIS map canvas and aggregates all one-map layers', async () => { const source = await readFile(homePath, 'utf8') assert.match(source, / { const source = await readFile(homePath, 'utf8') assert.match(source, /grid-template-columns:\s*minmax\(240px,\s*1fr\)\s+minmax\(0,\s*3fr\)\s+minmax\(240px,\s*1fr\)/u) }) test('home work order jumps point to device maintenance dispatch page', async () => { const source = await readFile(homePath, 'utf8') const jumps = source.match(/goPage\('\/device\/maintain'/gu) || [] assert.ok(jumps.length >= 3, 'header, work order rows and related order should all route to device maintain') assert.doesNotMatch(source, /monitorAlarm\/workOrder/u) assert.match(source, />设备维修派单<\/el-button>/u) }) test('home B-road detail panel is 1:1 with the todo and shortcut panels', async () => { const source = await readFile(homePath, 'utf8') assert.match(source, /workbench-grid--equal/u) assert.match(source, /repeat\(3,\s*minmax\(0,\s*1fr\)\)/u) const sectionB = source.match(/
([\s\S]*?)/u) assert.ok(sectionB, 'detail panel should live in the equal-width B section') }) test('home list panels scroll to reveal the full queue instead of pinning a few rows', async () => { const source = await readFile(homePath, 'utf8') const listSelector = source.match(/\.compact-list\s*\{[^}]*\}/u) assert.ok(listSelector, 'compact list style block exists') assert.match(listSelector[0], /max-height:\s*[\w.]+/u) assert.match(listSelector[0], /overflow-y:\s*auto/u) assert.match(source, /listRealtimeAlarms\(\),/u) }) test('home overview map fills the full map card body', async () => { const source = await readFile(homePath, 'utf8') assert.match(source, /\.map-panel[\s\S]{0,160}?display:\s*flex/u) assert.match(source, /\.map-stage[\s\S]{0,140}?flex:\s*1/u) }) test('home overview legend and detail cover unified device and facility status colors', async () => { const source = await readFile(homePath, 'utf8') assert.match(source, /gisPointStatusColors\.alarm[\s\S]{0,20}报警\/异常/u) assert.match(source, /gisPointStatusColors\.workOrder[\s\S]{0,20}工单\/检修中/u) assert.match(source, /gisPointStatusColors\.warning[\s\S]{0,20}预警\/欠费/u) assert.match(source, /gisPointStatusColors\.offline[\s\S]{0,20}离线/u) assert.match(source, /gisPointStatusColors\.normal[\s\S]{0,20}正常/u) assert.match(source, /overviewDetail\.statusText \|\| gisStatusLabel\(overviewDetail\.statusKey\)/u) }) test('home device data sources track the unified equipment endpoints', async () => { const source = await readFile(homePath, 'utf8') // 设备台账已统一到 /equipment-base:统计与列表都走统一设备接口,供水范围用 rootTypeId 限定 assert.match(source, /getEquipmentStatusStatistics\(/u) assert.match(source, /listEquipment\(/u) assert.match(source, /rootTypeId/u) assert.match(source, /normalizeDeviceStatistics/u) // 供水专属的旧设备接口已下线,不得再被首页引用 assert.doesNotMatch(source, /getDeviceLedgerStatistics/u) assert.doesNotMatch(source, /listAbnormalDevices/u) }) test('home surfaces partial load failures instead of swallowing them', async () => { const source = await readFile(homePath, 'utf8') // settle 自身吞掉异常并返回兜底值,因此失败上报必须由 settle 内部完成; // 链式 .catch(recordProblem(...)) 永不触发,会让“部分数据加载失败”提示变成死代码。 assert.match(source, /async function settle\(fn, fallback = null, onError = null\)/u) assert.match(source, /onError\?\.\(\)/u) assert.doesNotMatch(source, /\.catch\(recordProblem\(/u) assert.match(source, /settle\(\(\) => getWaterFacilityOverview\(\), \[\], recordProblem\('设施概览'\)\)/u) assert.match(source, /settle\(\(\) => listRealtimeAlarms\(\), \[\], recordProblem\('实时报警'\)\)/u) })