Files
crawler-plugin/frontend-vue/tests/jd-on-shelf.test.ts
T
huangzd1997 10dec12ec0 refactor(前端): 前后台界面小字全面精简——删技术ID括号/页头操作提示条/机制解释句(2026-11-28 客户口径「这些小字都不需要多余,还有shopId啥的…除了必须要的比如任务ID密钥,其他精简一些」)
用户端 frontend-vue:
- jd-publish-shop.ts:shopLabel 只出店名(缺名兜底「店铺 N」),跨店/多店琥珀文案压成一两句,判据逻辑零改动
- JdPublishTab:删工具头/分类解释/品牌句后半,默认店铺/选品/collect-hint/中断回执/加价规则各压一句
- JdCollectTab:删工具头 desc、分类机制句、断点游标行,「页面筛选未生效兜底翻页中」从任务卡撤下
- jd-on-shelf 空态一句、JdConsolePage hero-sub 整段删(含过时的「正在建设中」)
- 品牌 10 个 tab:输入/筛选/加载长句压一句或删,任务卡删「结果ID/店铺ID/平台」技术行(店名已显形)
- 保留:错误出口、额度「当前在架X/Y」、GROUPS_EMPTY 空态动作句、检测按钮与店铺显形

后管 admin-frontend-vue:
- 每页顶部「当前页面操作提示」条整条下线(删 OperationGuide.vue+operation-guides.ts)
- 撞款/任务中心/关键词用量/密钥用量/客户端包/教程/软件版本/数字人/菜单/店铺密钥/登录页逐页删说明小字(保留:踢线警示、「留空=永不过期」、「不要带v前缀」、「仅支持.zip」、草稿需手动发布、已授权人数、安全提示)
- 编辑/建号弹窗 label 括号收短;代理弹窗/设备日志(删 pywebview/kk-browser 进程名)/密钥 pill title/授权弹窗 dim/品牌门控空态收短

测试同步(16 支改反钉或同步断言,全部当场绿):
- align-operation-guide 整份重写为反钉(组件与文案表不得回流)
- source-pin 台账 task-center-board 条目手工点名 7/3/5→24/14/28:旧值是切分器把正则字面量内裸引号当字符串开关吞掉 18 支用例的误量(stripNonCode 不识别 regex literal),本次改写恰好移除该文件最后两处带引号正则后测出真值;真实用例数反而 25→24(删 1 支 guide 用例),非真实增长

门禁:后管 node --test 1965/1965+vitest 253/253+vue-tsc rc=0;用户端 node 1150/mount 149/vue-tsc rc=0;ops 快检 --fast overall=pass(后端9.5/后管8.8/客户端9.8/用户端9.6)。本窗不发版;app_client/jar/后端零改动。
2026-11-28 01:14:51 +08:00

101 lines
4.6 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 assert from 'node:assert/strict'
import test from 'node:test'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import {
clampPageSize,
markButtonLabel,
markDelistedNotice,
onShelfEmptyText,
quotaNearLimit,
quotaReadoutText,
} from '../src/pages/jd/jd-on-shelf.ts'
/**
* 在架商品面板纯函数与接线绊线(2026-11-25 客户口径「上限=同时在架商品数,
* 下架 10 个就能再上 10 个换着卖」)。
*
* 绊线盯的是「安静地不做」类回退:面板绕过 api 模块裸拼 URL(落点台账失效)、
* 文案在组件里硬拼(单出口失效)、JdPublishTab 不挂面板(功能整面失踪)——
* 行为测试全绿也拦不住,只有源码绊线拦得住。
*/
const ROOT = process.cwd()
function read(relativePath: string, what: string): string {
const path = join(ROOT, relativePath)
assert.ok(existsSync(path), `${what} 尚未落地:${path}`)
return readFileSync(path, 'utf8')
}
// ---------------------------------------------------------- 纯函数:余量文案
test('余量读数:正常档显「在架 X/Y」,不限档绝不显「/0」', () => {
assert.equal(quotaReadoutText(120, 5000, false), '当前在架 120/5000')
assert.equal(quotaReadoutText(120, 0, true), '当前在架 120/不限')
// limit≤0 但 unlimited 没带(防御:服务端两键同值,坏一个也不出「/0」坏数)
assert.equal(quotaReadoutText(3, 0, false), '当前在架 3/不限')
assert.equal(quotaReadoutText(Number.NaN, 5000, false), '当前在架 0/5000')
assert.equal(quotaReadoutText(12.7, 5000.9, false), '当前在架 12/5000')
})
test('到顶判据:used≥limit 才提醒;不限档永不提醒', () => {
assert.equal(quotaNearLimit(5000, 5000, false), true)
assert.equal(quotaNearLimit(5001, 5000, false), true)
assert.equal(quotaNearLimit(4999, 5000, false), false)
assert.equal(quotaNearLimit(999999, 0, true), false)
})
test('空态文案(2026-11-28 精简口径):一句讲完,机制解释句不再回流;翻页态不冒充空账', () => {
assert.equal(onShelfEmptyText(false, 0), '当前没有已上架商品')
assert.equal(onShelfEmptyText(true, 0), '当前没有已上架商品')
assert.equal(onShelfEmptyText(false, 25), '本页暂无更多在架商品,可翻页查看')
assert.ok(!onShelfEmptyText(false, 0).includes('采集入库不占'), '机制解释句已删,不得回流')
})
test('分页钳制与服务端 MAX_PAGE_SIZE=100 同口径', () => {
assert.equal(clampPageSize(9999), 100)
assert.equal(clampPageSize(20), 20)
assert.equal(clampPageSize(0), 20)
assert.equal(clampPageSize(-1), 20)
})
test('标记回执点名商品编码与确认义务,不写「操作成功」空话', () => {
assert.match(markDelistedNotice('100365361600'), /商品 100365361600/)
assert.match(markDelistedNotice('100365361600'), /额度已腾出/)
assert.match(markDelistedNotice(), /已标记下架,额度已腾出/)
assert.equal(markButtonLabel(), '标记已下架')
})
// ---------------------------------------------------------- 源码绊线:接线与单出口
test('绊线:在架端点只在 endpoints.ts 登记一处,面板必须走 api 模块出口', () => {
const endpoints = read('src/shared/api/endpoints.ts', '端点表')
assert.match(endpoints, /onShelf: '\/api\/jd-publish\/on-shelf'/)
assert.match(endpoints, /markDelisted: '\/api\/jd-publish\/items\/\{itemId\}\/delisted'/)
const apiModule = read('src/shared/api/types/modules/jd-publish.ts', '上架 api 模块')
assert.match(apiModule, /API_ENDPOINTS\.jdPublish\.onShelf/)
assert.match(apiModule, /API_ENDPOINTS\.jdPublish\.markDelisted/)
const panel = read('src/pages/jd/JdOnShelfPanel.vue', '在架面板')
assert.doesNotMatch(panel, /\/api\/jd-publish/, '面板不得裸拼后端 URL(落点必须走 api 模块)')
assert.match(panel, /fetchJdOnShelf/)
assert.match(panel, /markJdItemDelisted/)
})
test('绊线:面板文案单出口——组件不硬拼「当前在架」,判据与界面读同一份', () => {
const panel = read('src/pages/jd/JdOnShelfPanel.vue', '在架面板')
assert.doesNotMatch(panel, /当前在架/, '余量文案必须经 quotaReadoutText 单出口')
assert.match(panel, /quotaReadoutText/)
assert.match(panel, /onShelfEmptyText/)
assert.match(panel, /markDelistedNotice/)
})
test('绊线:JdPublishTab 必须挂上在架面板(功能整面失踪类回退)', () => {
const tab = read('src/pages/jd/JdPublishTab.vue', '上架页')
assert.match(tab, /import JdOnShelfPanel from '@\/pages\/jd\/JdOnShelfPanel\.vue'/)
assert.match(tab, /<JdOnShelfPanel \/>/)
})