| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import assert from 'node:assert/strict'
- import { readFile } from 'node:fs/promises'
- import test from 'node:test'
- const pagePath = 'src/views/subSystem/waterSupply/components/WaterDevicePage.vue'
- /** 找到 marker 所在标签上离它最近的 v-if 条件,用于校验列/区块的视图可见性 */
- function conditionOf(source, marker) {
- const at = source.indexOf(marker)
- if (at < 0) return null
- const before = source.slice(0, at)
- const start = before.lastIndexOf('v-if="')
- if (start < 0) return null
- const end = source.indexOf('"', start + 'v-if="'.length)
- return source.slice(start + 'v-if="'.length, end)
- }
- test('abnormal board shows the district column so the region filter is verifiable', async () => {
- const source = await readFile(pagePath, 'utf8')
- assert.match(
- source,
- /label="所属区域"[^>]*>\s*<template #default="\{ row \}">\{\{ row\.district \|\| '-' \}\}/u,
- '异常看板应展示所属区域列'
- )
- assert.match(source, /v-if="view === 'abnormal' \|\| view === 'dispatch'"/u)
- })
- test('abnormal board detail includes the district field', async () => {
- const source = await readFile(pagePath, 'utf8')
- assert.match(source, /\['所属区域', detail\.value\.district\]/u)
- })
- test('abnormal board lists and previews the device image', async () => {
- const source = await readFile(pagePath, 'utf8')
- const columnCond = conditionOf(source, 'label="设备图片"')
- assert.ok(columnCond, '缺少设备图片列')
- assert.match(columnCond, /'abnormal'/u, '设备图片列需覆盖异常视图')
- assert.match(columnCond, /'ledger'/u, '设备图片列不应丢掉台账视图')
- const mediaCond = conditionOf(source, 'class="detail-media"')
- assert.ok(mediaCond, '详情抽屉缺少设备图片区块')
- assert.match(mediaCond, /'abnormal'/u, '详情图片区块需覆盖异常视图')
- })
- test('abnormal board is read-only and stats come from the backend aggregate', async () => {
- const source = await readFile(pagePath, 'utf8')
- assert.match(
- source,
- /function canDispatch\(row\) \{\s*if \(view !== 'dispatch'\) return false/u,
- '异常视图不应保留派单入口'
- )
- assert.match(
- source,
- /if \(view === 'abnormal'\) await loadAbnormalStats\(\)/u,
- '异常视图应加载后端聚合统计'
- )
- const statsBlock = source.slice(
- source.indexOf('const abnormalStats = computed'),
- source.indexOf('const ledgerStatsCards')
- )
- assert.doesNotMatch(statsBlock, /page\.value\.records/u, '统计卡片不应基于当前分页行计数')
- assert.match(statsBlock, /abnormalStatsData\.value\.total/u)
- assert.match(statsBlock, /abnormalStatsData\.value\.offline/u)
- })
|