feat(后台): 日期筛选统一默认当天(7 页 + 告警铃铛),并带上看板列改造的在途改动
- utils/datetime 新增 todayDateInput()/todayDateTimeRange(),8 处日期筛选的初值与「重置」都锁当天; 撞款监控按口径排除(该页日期是 ASIN 上架时间,默认当天会让首屏几乎为空)。 - NotificationBell 的 hasFilter 不再把日期计入:日期恒有值是默认视图,计入会让 「无筛选才记录已提醒 id」那条分支永久失效。 - 新增护栏 tests/date-filter-default-today.test.ts(6 例,变异自证 3/3 转红): 凡带日期控件的页面没接入当天默认就红,不等人工发现首屏是空的。 - 同批带上另一路会话的看板在途改动(task-center-model 的 tabCount/完成数口径、 TaskCenterBoardPage 列改造与对应用例):它与本页的日期默认改动落在同一文件, 拆开会让单次提交编译不过,故按现状一起上。
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
import test from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { readdirSync, statSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
import { readSource } from './helpers.ts'
|
||||
import { todayDateInput, todayDateTimeRange } from '../src/utils/datetime.ts'
|
||||
|
||||
// 后台日期筛选统一默认「当天」(2026-10-04 定口径)的护栏:
|
||||
// 凡渲染了日期筛选控件的页面/组件,首屏初值与「重置」目标都必须是当天;
|
||||
// 以后新增带日期筛选的页若没接入,会被本用例拦下而不是悄悄漏掉。
|
||||
|
||||
const DATE_CONTROL_RES = [/type="date"/, /type="datetime-local"/, /<el-date-picker/]
|
||||
|
||||
/** 有意排除:该页日期是 ASIN「上架时间」,默认当天会让首屏几乎为空(用户 2026-10-04 确认)。 */
|
||||
const EXEMPT = new Set(['src/pages/tasks/DuplicateCheckPage.vue'])
|
||||
|
||||
/** 把日期筛选清回空值的写法(初值或重置里都不许出现)。 */
|
||||
const DATE_CLEARED =
|
||||
/(?:startDate|endDate|timeStart|timeEnd|startTime|endTime|dateFrom|dateTo)(?:\.value)?\s*[:=]\s*''|dateRange\s*[:=]\s*\[\s*\]/
|
||||
|
||||
/** 去掉 import 行:`import { todayDateInput }` 这种"只引不用"不能算接入(变异实测会造恒绿)。 */
|
||||
function withoutImportLines(src: string): string {
|
||||
return src.split(/\r?\n/).filter((line) => !/^\s*import\b/.test(line)).join('\n')
|
||||
}
|
||||
|
||||
function hasDateControl(src: string): boolean {
|
||||
return DATE_CONTROL_RES.some((re) => re.test(src))
|
||||
}
|
||||
|
||||
function vueFiles(): string[] {
|
||||
const out: string[] = []
|
||||
const walk = (dir: string): void => {
|
||||
for (const name of readdirSync(dir)) {
|
||||
const abs = join(dir, name)
|
||||
if (statSync(abs).isDirectory()) walk(abs)
|
||||
else if (name.endsWith('.vue')) out.push(abs.split(/[\\/]+/).join('/'))
|
||||
}
|
||||
}
|
||||
walk('src')
|
||||
return out
|
||||
}
|
||||
|
||||
const managed = vueFiles().filter((rel) => !EXEMPT.has(rel) && hasDateControl(readSource(rel)))
|
||||
|
||||
test('test_default_today_normal_inventory_is_not_empty', () => {
|
||||
// 分母由扫描得出、不自挑:掉到 7 以下说明控件识别正则已失效(会造出恒绿)
|
||||
assert.ok(managed.length >= 7, `只扫到 ${managed.length} 个带日期筛选的文件,扫描规则可能已失效`)
|
||||
})
|
||||
|
||||
test('test_default_today_normal_every_date_filter_page_is_wired', () => {
|
||||
for (const rel of managed) {
|
||||
const src = readSource(rel)
|
||||
assert.match(
|
||||
withoutImportLines(src),
|
||||
/todayDateInput\(|todayDateTimeRange\(/,
|
||||
`${rel} 有日期筛选控件但未默认当天`,
|
||||
)
|
||||
assert.match(src, /from ['"]@\/utils\/datetime['"]/, `${rel} 的 today* 取值须来自 @/utils/datetime`)
|
||||
}
|
||||
})
|
||||
|
||||
test('test_default_today_normal_reset_keeps_today', () => {
|
||||
for (const rel of managed) {
|
||||
const hit = readSource(rel)
|
||||
.split(/\r?\n/)
|
||||
.filter((line) => DATE_CLEARED.test(line))
|
||||
assert.deepEqual(hit, [], `${rel} 仍把日期筛选清成空值:\n${hit.join('\n')}`)
|
||||
}
|
||||
})
|
||||
|
||||
test('test_default_today_boundary_exempt_still_intentional', () => {
|
||||
for (const rel of EXEMPT) {
|
||||
const src = readSource(rel)
|
||||
assert.ok(hasDateControl(src), `${rel} 已无日期筛选控件,应从豁免清单移除`)
|
||||
assert.equal(
|
||||
/todayDateInput\(|todayDateTimeRange\(/.test(withoutImportLines(src)),
|
||||
false,
|
||||
`${rel} 已被排除,不得接入默认当天`,
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
test('test_default_today_boundary_values_match_backend_patterns', () => {
|
||||
const day = todayDateInput()
|
||||
assert.match(day, /^\d{4}-\d{2}-\d{2}$/, 'type="date" 与各页 ISO 日期校验')
|
||||
const [start, end] = todayDateTimeRange()
|
||||
const LOCAL_DATETIME = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2})?$/
|
||||
assert.match(start, LOCAL_DATETIME, 'datetime-local 各页的秒级校验')
|
||||
assert.match(end, LOCAL_DATETIME)
|
||||
assert.equal(day, start.slice(0, 10), '日期与区间必须同一天,不能跨零点各算各的')
|
||||
assert.ok(start < end, '起须早于止,否则各页「开始日期不能晚于结束」校验会弹警告')
|
||||
})
|
||||
|
||||
test('test_default_today_invalid_input_pads_and_uses_local_time', () => {
|
||||
const fixed = new Date(2026, 0, 5, 8, 30, 0)
|
||||
assert.equal(todayDateInput(fixed), '2026-01-05', '月/日须补零')
|
||||
assert.deepEqual(todayDateTimeRange(fixed), ['2026-01-05T00:00', '2026-01-05T23:59'])
|
||||
})
|
||||
@@ -15,6 +15,7 @@ import {
|
||||
progressPercent,
|
||||
progressText,
|
||||
shopDisplayName,
|
||||
tabCount,
|
||||
taskStatusLabel,
|
||||
taskStatusType,
|
||||
toApiTime,
|
||||
@@ -124,12 +125,25 @@ test('task_center_device_display_falls_back_to_truncated_id', () => {
|
||||
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 截断')
|
||||
/**
|
||||
* 进度口径与客户端一致:完成数 = 已处理(成功 + 失败都算跑完一步),
|
||||
* 见 frontend-vue `BrandBrandTab.vue`「完成数 = 已处理品牌行(成功或查询失败都计入)」。
|
||||
* 旧文案「成功 0 / 总 1」会把一个已跑完(失败 1)的任务读成 0% 进度。
|
||||
*/
|
||||
test('task_center_progress_counts_done_rows_like_the_client', () => {
|
||||
assert.equal(progressText({ progressSuccess: 3, progressFailed: 0, progressTotal: 10 }), '已完成 3 / 总 10')
|
||||
assert.equal(
|
||||
progressText({ progressSuccess: 0, progressFailed: 1, progressTotal: 1 }),
|
||||
'已完成 1 / 总 1',
|
||||
'失败的那一步同样是已完成的一步',
|
||||
)
|
||||
assert.equal(progressText({ progressSuccess: 0, progressFailed: 0, progressTotal: 0 }), '—')
|
||||
assert.equal(progressText({ progressSuccess: 0, progressFailed: 0, progressTotal: -1 }), '—', '哨兵总数不当进度')
|
||||
assert.equal(progressPercent({ progressSuccess: 3, progressFailed: 1, progressTotal: 10 }), 40)
|
||||
assert.equal(progressPercent({ progressSuccess: 0, progressFailed: 1, progressTotal: 1 }), 100)
|
||||
assert.equal(progressPercent({ progressSuccess: 0, progressFailed: 0, progressTotal: 0 }), 0)
|
||||
assert.equal(progressPercent({ progressSuccess: 15, progressFailed: 0, progressTotal: 10 }), 100, '超出按 100 截断')
|
||||
assert.equal(progressPercent({ progressSuccess: -5, progressFailed: 0, progressTotal: 10 }), 0, '脏负数不按负进度画')
|
||||
})
|
||||
|
||||
test('task_center_query_builder_omits_blanks_and_normalizes_time', () => {
|
||||
@@ -195,6 +209,40 @@ test('task_center_shop_panel_is_the_board_and_drills_down_by_exact_shop', () =>
|
||||
assert.equal(page.includes('device-strip'), false, '设备卡条已删除')
|
||||
})
|
||||
|
||||
/**
|
||||
* 任务列表列改造(2026-10-04 用户要求):
|
||||
* ① 「当前处理」列全是「—」(无快照模块没有 current_scope_key),换成任务 ID;
|
||||
* ID 单元格继承被删掉的「查看」按钮职责,否则详情抽屉没有入口。
|
||||
* ② 账号下方的 taskNo 副行删掉——ID 已经在独立列里,长任务号只把行撑高。
|
||||
* ③ 「操作」列整条删除,空态 colspan 跟着从 10 收到 9。
|
||||
* ④ 店铺那组比别的多一行提示文案,而 .form-row 是 align-items: flex-end,
|
||||
* 于是它的 label 被顶高一行——提示必须退出列流(绝对定位)而不是删掉。
|
||||
*/
|
||||
test('task_center_task_list_columns_are_trimmed_to_the_data_that_exists', () => {
|
||||
const page = readSource(PAGE)
|
||||
const style = page.slice(page.indexOf('<style scoped>'))
|
||||
|
||||
assert.match(page, /<th style="width: 170px">任务ID<\/th>/, '「当前处理」列改名任务ID')
|
||||
assert.equal(/<th[^>]*>当前处理<\/th>/.test(page), false, '列表不再有全「—」的当前处理列')
|
||||
assert.match(page, /<td>\s*<button class="cell-link mono" type="button" @click="openDetail\(row\)">\{\{ row\.id \}\}<\/button>/, 'ID 单元格点开详情')
|
||||
assert.match(page, /:key="row\.taskNo"/, ':key 仍是唯一任务号(biz 与 brand 两张表的自增 id 会撞)')
|
||||
|
||||
assert.equal(/<span class="sub">\{\{ row\.taskNo \}\}<\/span>/.test(page), false, '账号下方不再重复任务号')
|
||||
assert.equal(/<th[^>]*>操作<\/th>/.test(page), false, '操作列已删')
|
||||
assert.equal(page.includes('btn-sm'), false, '没有别的按钮后 btn-sm 样式一并撤掉')
|
||||
assert.equal(/colspan="10"/.test(page), false, '任务表空态不再是 10 列')
|
||||
assert.equal(page.match(/colspan="9"/g)?.length, 2, '加载中/空态两处收到 9 列')
|
||||
|
||||
assert.match(style, /\.shop-filter\s*\{[^}]*position: relative/, '店铺组是提示的定位父元素')
|
||||
assert.match(style, /\.filter-tip\s*\{[^}]*position: absolute/, '提示绝对定位,不再撑高该组把 label 顶上去')
|
||||
assert.match(style, /\.form-row\s*\{[^}]*align-items: flex-end[^}]*margin-bottom: 22px/, '底部留白容纳提示行')
|
||||
assert.match(
|
||||
page,
|
||||
/<el-select[\s\S]{0,220}class="admin-filter"[\s\S]{0,220}placeholder="全部店铺"/,
|
||||
'店铺下拉挂全局 admin-filter(控件 42px,与其它原生控件同高,flex-end 下 label 才齐线)',
|
||||
)
|
||||
})
|
||||
|
||||
test('task_center_page_wires_tabs_filters_and_polling', () => {
|
||||
const page = readSource(PAGE)
|
||||
assert.match(page, /客户端任务/, '页签一文案')
|
||||
@@ -213,3 +261,40 @@ test('task_center_page_wires_tabs_filters_and_polling', () => {
|
||||
assert.match(page, /resMes/, '变体表展示麦象 res_mes')
|
||||
assert.equal(/shopName/.test(readSource(PAGE)), true)
|
||||
})
|
||||
|
||||
/**
|
||||
* 页签徽章的两个口径缺陷:
|
||||
* ① 「客户端任务」曾绑列表 total(默认全部状态、全部时间 = 历史全量,线上 1135 条,
|
||||
* 且每天 00:00 的 7 天保留清理会把它往下掉),而这一页讲的是「当前在跑」——
|
||||
* 现在绑汇总卡的 runningTasks,两处不允许各算各的。
|
||||
* ② 「变体采集」曾恒显示 0:refreshAll 只加载当前页签的列表,停在页签一时该接口
|
||||
* 从未请求过(线上此刻返回 106 条)。没查过与"查了是 0"必须是两个读数。
|
||||
*/
|
||||
test('task_center_tab_badge_never_claims_an_unqueried_count', () => {
|
||||
assert.equal(tabCount(undefined), null, '接口没回 total 不能读成 0')
|
||||
assert.equal(tabCount(null), null)
|
||||
assert.equal(tabCount(''), null)
|
||||
assert.equal(tabCount(Number.NaN), null)
|
||||
assert.equal(tabCount(-1), null, '麦象未注册结果表时 total 是 -1 哨兵,不是条数')
|
||||
assert.equal(tabCount(0), 0, '接口真的返回 0 才算 0')
|
||||
assert.equal(tabCount('106'), 106)
|
||||
|
||||
const page = readSource(PAGE)
|
||||
// ① 页签一 = 在跑数,与汇总卡同源;历史全量只留给分页用
|
||||
assert.match(page, /const runningBadge = computed\(\(\) => tabCount\(overview\.value\?\.runningTasks\)\)/,
|
||||
'页签一徽章取 overview.runningTasks')
|
||||
assert.match(page, /\{\{\s*runningBadge\s*\?\?\s*'—'\s*\}\}/, '页签一画在跑数,没取到时画 —')
|
||||
assert.equal(/<span class="t-count">\{\{ taskTotal/.test(page), false, '页签一不再绑列表总数')
|
||||
// ② 页签二 = 真查过的条数,未查过/查失败都画 —
|
||||
assert.match(page, /const variantTotal = ref<number \| null>\(null\)/, '初始是「没查过」不是 0')
|
||||
assert.match(page, /\{\{\s*variantTotal\s*\?\?\s*'—'\s*\}\}/, '页签二未查过时徽章画 —')
|
||||
assert.match(page, /variantTotal\.value = tabCount\(/, '变体总数经 tabCount 归一')
|
||||
assert.match(page, /catch[\s\S]{0,160}variantTotal\.value = null/, '加载失败退回「没查过」,不留在 0')
|
||||
assert.match(page, /loadInactiveTabTotal/, '首屏补查另一个页签的条数')
|
||||
assert.match(page, /onMounted\(\(\) => \{[\s\S]{0,220}loadInactiveTabTotal/, '补查挂在首屏')
|
||||
assert.match(
|
||||
page,
|
||||
/activeTab\.value === 'tasks' \? loadTasks\(silent\) : loadVariants\(silent\)/,
|
||||
'30s 轮询仍只刷当前页签:麦象 console 是外部依赖,不进热路径',
|
||||
)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user