import test from 'node:test' import assert from 'node:assert/strict' import { readSource } from './helpers.ts' // 日志管理列表改「用户维度」的护栏(2026-10-04 用户要求:去掉设备/文件名模糊搜索与设备列,加用户筛选)。 // 后端查询侧已有 DeviceLogServiceTest 锁住 uid 精确过滤;这里补前端这一段—— // 页面筛选控件、请求参数、表头列三处任意一处退回设备维度,本用例会红而不是悄悄生效。 const PAGE = 'src/pages/records/DeviceLogsPage.vue' const API = 'src/api/device-logs.ts' /** 取第一张表 = 日志文件列表;采集配置弹窗里另有一张含「设备」的表,混着判会误报。 */ function firstTable(src: string): string { const matched = /
| ]*>\s*用户\s*<\/th>/, '列表表头没有「用户」列') assert.doesNotMatch(table, /设备/, '列表表头又出现「设备」列') }) test('test_device_log_list_colspan_matches_header_column_count', () => { // 「删了列忘了改占位行 colspan」是这类改动最常留下的残行 const table = firstTable(readSource(PAGE)) const columns = (table.match(/ | ]/g) ?? []).length assert.ok(columns >= 2, `表头只数到 ${columns} 列,取块规则已失效`) const spans = [...table.matchAll(/colspan="(\d+)"/g)].map((m) => Number(m[1])) assert.ok(spans.length >= 1, '列表 tbody 没有 colspan 占位行') for (const span of spans) { assert.equal(span, columns, `占位行 colspan=${span} 与表头列数 ${columns} 不符`) } }) test('test_device_log_page_wires_user_dropdown_to_uid_param', () => { const page = readSource(PAGE) assert.match(page, /指定用户[\s\S]{0,220}?v-model="uidFilter"/, '筛选条没有绑定 uidFilter 的下拉') assert.match(page, /uid:\s*uidFilter\.value\s*\?\s*Number\(uidFilter\.value\)/, '请求未把所选用户映射成 uid') }) test('test_device_log_list_query_carries_no_fuzzy_keyword', () => { const body = functionBody(readSource(API), 'export async function fetchDeviceLogFiles', 'export async function fetchDeviceLogContent') assert.match(body, /query\.uid = params\.uid/, '列表接口不再下发 uid') assert.doesNotMatch(body, /keyword/, '列表接口又带回 keyword 模糊匹配') // 页面整份都不该出现 keyword:设备/文件名模糊搜索的入口应彻底消失 assert.doesNotMatch(readSource(PAGE), /\bkeyword\b/, '日志管理页仍存在模糊搜索入参') }) test('test_device_log_user_dropdown_is_filled_from_admin_users', () => { // 复用生成记录页那份用户下拉,避免两处各写一套解析 const page = readSource(PAGE) assert.match(page, /import \{[^}]*fetchHistoryUserOptions[^}]*\} from/, '用户下拉没有走既有的 admin users 取数') // 断言锁定挂载时的**调用点**:只写 /loadUserOptions\(\)/ 会匹配到函数声明本身,恒绿 assert.match( page, /onMounted\(\(\)\s*=>\s*\{[^}]*loadUserOptions\(\)/, '用户选项未在 onMounted 里加载(首屏下拉会是空的)', ) }) |
|---|