Files
crawler-plugin/admin-frontend-vue/tests/task-center-board.test.ts
T
huangzd1997 06396d537e feat(看板): 客户端任务管理从设备维度改为店铺维度全局在跑看板
原「在线设备」卡按日志上报窗口统计,把 89 台算成在线,与实际在跑的客户端数差一个
量级,且设备维度并不能回答"哪台机器上有任务卡住"。改为:

- 汇总卡:总店铺 / 在跑店铺 / 进行中任务 / 今日完成 / 疑似卡住
- 新增「在跑店铺看板」:当前所有进行中任务按店铺归组(在跑数、卡住数、业务分布、
  最近上报),点店铺行下筛该店铺任务;不落店铺的任务归「不挂店铺」桶
- 卡片与面板同源(同一个 aggregateShops),杜绝口径分裂
- 店铺只认两个真来源:上架结果文件 + 逐店落行的结果文件名;
  biz_task_progress_snapshot.current_scope_key 是实例锁不是店铺,已从口径中剔除
- 设备号退为详情附注,花名册 /devices 与在线判定整条链删除
- 上报口径只留一个 10 分钟窗口(进行中且超 10 分钟无上报 = 疑似卡住)

后端 3487 例全绿;新增反射护栏断言设备维度查询与快照当店铺的来源已彻底移除。
2026-10-03 22:41:29 +08:00

216 lines
9.8 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import test from 'node:test'
import assert from 'node:assert/strict'
import { readSource } from './helpers.ts'
import { adminPages, validateAdminPages } from '../src/router/routes.ts'
import { operationGuideFor } from '../src/layout/operation-guides.ts'
import {
MODULE_OPTIONS,
TASK_STATUS_OPTIONS,
VARIANT_STATUS_OPTIONS,
buildTaskQuery,
buildVariantQuery,
createTaskFilter,
createVariantFilter,
deviceDisplayName,
progressPercent,
progressText,
shopDisplayName,
taskStatusLabel,
taskStatusType,
toApiTime,
variantAccountText,
variantStatusLabel,
} from '../src/pages/task-center/task-center-model.ts'
// 客户端任务管理看板(后台):路由注册 / guides 对齐 / 接口层 / 纯逻辑映射。
const PAGE = 'src/pages/task-center/TaskCenterBoardPage.vue'
const API = 'src/api/task-center.ts'
test('task_center_route_registered_with_menu_key', () => {
const page = adminPages.find((p) => p.path === 'task-center/board')
assert.ok(page, '路由注册表登记 task-center/board')
assert.equal(page.menuKey, 'admin_task_center')
assert.equal(page.title, '客户端任务管理')
assert.match(String(page.load), /task-center\/TaskCenterBoardPage\.vue/)
assert.deepEqual(validateAdminPages(adminPages), [])
})
test('task_center_guide_present_for_menu_key', () => {
const guide = operationGuideFor('admin_task_center')
assert.ok(guide, '菜单 key 有独立 guide(align-operation-guide 强制)')
assert.ok(guide.text.length > 10)
assert.equal(guide.steps.length, 3)
})
test('task_center_api_has_six_endpoints', () => {
const api = readSource(API)
for (const path of [
'/api/admin/task-center/overview',
'/api/admin/task-center/shops',
'/api/admin/task-center/shop-options',
'/api/admin/task-center/tasks',
'/api/admin/task-center/tasks/detail',
'/api/admin/task-center/variant-tasks',
]) {
assert.ok(api.includes(path), `接口层覆盖 ${path}`)
}
for (const fn of [
'fetchTaskCenterOverview',
'fetchTaskCenterShops',
'fetchTaskCenterShopOptions',
'fetchTaskCenterTasks',
'fetchTaskCenterTaskDetail',
'fetchTaskCenterVariantTasks',
]) {
assert.match(api, new RegExp(`export (async )?function ${fn}`), `导出 ${fn}`)
}
assert.match(api, /unwrap</, '统一走 unwrap 解包')
})
/** 设备维度已下线:卡片是店铺,接口不再有 /devices,筛选不再有 deviceId。 */
test('task_center_device_dimension_is_gone', () => {
const api = readSource(API)
const model = readSource('src/pages/task-center/task-center-model.ts')
const page = readSource(PAGE)
for (const dead of ['deviceTotal', 'deviceOnline', 'TaskCenterDevice', '/devices', 'fetchTaskCenterDevices']) {
assert.equal(api.includes(dead), false, `接口层不再有 ${dead}`)
}
assert.equal(model.includes("deviceId: ''"), false, '筛选条件不再有设备号')
assert.equal(/buildTaskQuery[\s\S]*put\('deviceId'/.test(model), false, '查询参数不再下传 deviceId')
assert.equal(page.includes('filter.deviceId'), false, '页面不再按设备筛')
assert.equal('deviceId' in createTaskFilter(), false)
})
test('task_center_status_labels_cover_backend_states', () => {
assert.equal(taskStatusLabel('PENDING'), '待执行')
assert.equal(taskStatusLabel('RUNNING'), '执行中')
assert.equal(taskStatusLabel('SUCCESS'), '已完成')
assert.equal(taskStatusLabel('FAILED'), '失败')
assert.equal(taskStatusLabel('CANCELLED'), '已取消')
assert.equal(taskStatusLabel(''), '未知')
assert.equal(taskStatusType('SUCCESS'), 'success')
assert.equal(taskStatusType('FAILED'), 'failed')
assert.equal(taskStatusType('CANCELLED'), 'cancelled')
assert.equal(taskStatusType('PENDING'), 'pending')
assert.equal(taskStatusType('RUNNING'), 'running')
assert.ok(TASK_STATUS_OPTIONS.length >= 5)
assert.equal(TASK_STATUS_OPTIONS[0].value, '')
assert.equal(MODULE_OPTIONS[0].value, '', '首项为「全部业务」')
assert.equal(MODULE_OPTIONS.slice(1).every((o) => o.value && o.label), true)
assert.ok(MODULE_OPTIONS.length >= 13, '业务下拉覆盖客户端模块')
})
test('task_center_variant_status_map_follows_maixiang_semantics', () => {
assert.equal(variantStatusLabel(0), '等待执行')
assert.equal(variantStatusLabel(1), '处理中')
assert.equal(variantStatusLabel(2), '已完成')
assert.equal(variantStatusLabel(3), '处理失败')
assert.equal(variantStatusLabel(9), '未知')
assert.equal(variantStatusLabel(null), '未知')
assert.equal(variantStatusLabel('2'), '已完成', '字符串数字同样识别')
assert.equal(VARIANT_STATUS_OPTIONS.length, 5)
})
test('task_center_device_display_falls_back_to_truncated_id', () => {
assert.equal(deviceDisplayName('小明的电脑', 'dev-1'), '小明的电脑')
const long = 'a'.repeat(40)
const shown = deviceDisplayName(null, long)
assert.ok(shown.length < long.length, '无设备名时截断设备号')
assert.ok(shown.endsWith('…'))
assert.equal(deviceDisplayName('', ''), '未记录')
assert.equal(shopDisplayName('店铺甲', 1), '店铺甲')
assert.equal(shopDisplayName('店铺甲', 3), '店铺甲 等3个')
assert.equal(shopDisplayName('', 0), '—')
})
test('task_center_progress_text_and_percent_boundaries', () => {
assert.equal(progressText({ progressSuccess: 3, progressTotal: 10 }), '成功 3 / 总 10')
assert.equal(progressText({ progressSuccess: 0, progressTotal: 0 }), '—')
assert.equal(progressPercent({ progressSuccess: 3, progressTotal: 10 }), 30)
assert.equal(progressPercent({ progressSuccess: 0, progressTotal: 0 }), 0)
assert.equal(progressPercent({ progressSuccess: 15, progressTotal: 10 }), 100, '超出按 100 截断')
})
test('task_center_query_builder_omits_blanks_and_normalizes_time', () => {
const query = buildTaskQuery(
{ username: ' 张三 ', moduleType: 'COLLECT_DATA', status: 'RUNNING', shop: '林芳旗舰店', startTime: '2026-09-28T10:00', endTime: '' },
2,
20,
)
assert.equal(query.page, 2)
assert.equal(query.pageSize, 20)
assert.equal(query.username, '张三')
assert.equal(query.moduleType, 'COLLECT_DATA')
assert.equal(query.status, 'RUNNING')
assert.equal(query.shop, '林芳旗舰店', '店铺名原样下传,由后端做 LOWER(TRIM) 精确匹配')
assert.equal(query.startTime, '2026-09-28T10:00:00')
assert.equal(query.endTime, undefined)
assert.equal(toApiTime(' 2026-09-28T10:00 '), '2026-09-28T10:00:00')
assert.equal(toApiTime('2026-09-28T10:00:30'), '2026-09-28T10:00:30')
assert.equal(toApiTime(''), undefined)
})
test('task_center_variant_query_builder_keeps_paging', () => {
const empty = buildVariantQuery({ status: '' }, 1, 20)
assert.equal(empty.status, undefined)
assert.equal(empty.page, 1)
const filtered = buildVariantQuery({ status: '3' }, 3, 50)
assert.equal(filtered.status, 3)
assert.equal(filtered.page, 3)
assert.equal(filtered.pageSize, 50)
})
test('task_center_filter_reset_clears_every_field', () => {
const filter = createTaskFilter()
assert.deepEqual(Object.values(filter), ['', '', '', '', '', ''])
assert.deepEqual(createVariantFilter(), { status: '' })
assert.deepEqual(buildTaskQuery(createTaskFilter(), 1, 20), { page: 1, pageSize: 20 }, '重置后只带分页参数')
assert.equal(variantAccountText({ username: 'wangwu', uid: '1048' }), 'wangwu')
assert.equal(variantAccountText({ username: null, uid: 'collect-27475' }), 'collect-27475', '伪 uid 回落')
assert.equal(variantAccountText({ username: '', uid: '' }), '—')
})
test('task_center_page_handles_empty_and_error_states', () => {
const page = readSource(PAGE)
assert.match(page, /暂无符合条件的任务/, '任务空态')
assert.match(page, /暂无在跑店铺/, '店铺面板空态')
assert.match(page, /暂无变体采集任务/, '变体空态')
assert.match(page, /ElMessage\.error/, '接口失败提示')
assert.match(page, /resetFilter/, '筛选重置接线')
assert.match(page, /@size-change="changeTaskSize"/, '分页每页条数切换')
assert.match(page, /@size-change="changeVariantSize"/, '变体分页每页条数切换')
})
test('task_center_shop_panel_is_the_board_and_drills_down_by_exact_shop', () => {
const page = readSource(PAGE)
assert.match(page, /在跑店铺看板/, '面板标题')
assert.match(page, /最近上报/, '面板与任务表都带最近上报')
assert.match(page, /row\.noShop \? null : selectShop\(row\.shop\)/, '点店铺行下钻,「不挂店铺」桶不可点')
assert.match(page, /不落店铺/, '桶行说明:这类任务本来就没有店铺维度')
assert.match(page, /shopFilterOptions/, '店铺下拉候选 = 店铺库 ∪ 面板出现的店铺')
assert.match(page, /fetchTaskCenterShops/, '面板取数')
assert.match(page, /fetchTaskCenterShopOptions/, '候选取数')
assert.match(page, /moduleSummary/, '业务分布列')
assert.equal(page.includes('device-strip'), false, '设备卡条已删除')
})
test('task_center_page_wires_tabs_filters_and_polling', () => {
const page = readSource(PAGE)
assert.match(page, /客户端任务/, '页签一文案')
assert.match(page, /变体采集/, '页签二文案')
assert.match(page, /panel-box/, '复用全局 panel-box 样式')
assert.match(page, /form-row/, '复用全局筛选行样式')
assert.match(page, /OldPagination/, '旧版分页组件')
assert.match(page, /formatDateTime/, '统一时间格式')
assert.match(page, /el-drawer/, '任务详情抽屉')
assert.match(page, /疑似卡住/, 'stuck 徽标文案')
assert.match(page, /网页/, '网页登录设备徽标')
assert.match(page, /visibilitychange/, '页面回前台恢复刷新')
assert.match(page, /document\.visibilityState/, '隐藏时跳过轮询')
assert.match(page, /POLL_INTERVAL_MS/, '30s 轮询常量')
assert.match(page, /clearInterval/, '卸载清理定时器')
assert.match(page, /resMes/, '变体表展示麦象 res_mes')
assert.equal(/shopName/.test(readSource(PAGE)), true)
})