4a6e139ae9
- utils/datetime 新增 todayDateInput()/todayDateTimeRange(),8 处日期筛选的初值与「重置」都锁当天; 撞款监控按口径排除(该页日期是 ASIN 上架时间,默认当天会让首屏几乎为空)。 - NotificationBell 的 hasFilter 不再把日期计入:日期恒有值是默认视图,计入会让 「无筛选才记录已提醒 id」那条分支永久失效。 - 新增护栏 tests/date-filter-default-today.test.ts(6 例,变异自证 3/3 转红): 凡带日期控件的页面没接入当天默认就红,不等人工发现首屏是空的。 - 同批带上另一路会话的看板在途改动(task-center-model 的 tabCount/完成数口径、 TaskCenterBoardPage 列改造与对应用例):它与本页的日期默认改动落在同一文件, 拆开会让单次提交编译不过,故按现状一起上。
99 lines
4.1 KiB
TypeScript
99 lines
4.1 KiB
TypeScript
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'])
|
|
})
|