Files
crawler-plugin/frontend-vue/tests/jd-console-tool-catalog.test.ts

57 lines
2.9 KiB
TypeScript

import assert from 'node:assert/strict'
import test from 'node:test'
import { existsSync, readFileSync } from 'node:fs'
import { join } from 'node:path'
import { JD_TOOLS, JD_TOOL_MAP } from '../src/pages/jd/tool-catalog.ts'
/** 京东一级入口(v1.5):首页「京东」→ 京东工作台两个菜单(获取店铺数据 / 商品上架占位)。 */
const ROOT = process.cwd()
function read(relativePath: string): string {
const path = join(ROOT, relativePath)
assert.ok(existsSync(path), `文件缺失:${path}`)
return readFileSync(path, 'utf8')
}
test('京东工作台只有两个菜单:获取店铺数据 + 商品上架', () => {
assert.equal(JD_TOOLS.length, 2, '京东工作台菜单数应为 2')
const names = JD_TOOLS.map((tool) => tool.name)
assert.deepEqual(names, ['获取店铺数据', '商品上架'])
assert.equal(new Set(JD_TOOLS.map((tool) => tool.id)).size, 2, '工具 id 不应重复')
assert.ok(JD_TOOL_MAP.get('jd-collect'), 'JD_TOOL_MAP 应按 id 命中获取店铺数据')
})
test('获取店铺数据指向采集页,商品上架先做占位菜单', () => {
const collect = JD_TOOLS.find((tool) => tool.id === 'jd-collect')
const publish = JD_TOOLS.find((tool) => tool.id === 'jd-publish')
assert.equal(collect?.href, '/jd-collect', '获取店铺数据应指向 /jd-collect')
assert.equal(publish?.href, undefined, '商品上架先做假菜单:不得挂路由')
})
test('路由器注册京东工作台与采集页', () => {
const router = read('src/router/index.ts')
assert.ok(router.includes("path: '/jd-console'"), 'router 缺 /jd-console')
assert.ok(router.includes('JdConsolePage.vue'), 'router 未指向 JdConsolePage')
assert.ok(router.includes("path: '/jd-collect'"), 'router 缺 /jd-collect')
})
test('首页京东入口与亚马逊/视频并列', () => {
const home = read('src/pages/home/DesktopHomePage.vue')
assert.ok(home.includes('jd-console.html'), '首页京东入口未指向京东工作台')
assert.ok(/>京东</.test(home), '首页缺「京东」按钮文字')
})
test('获取店铺数据页是一键触发 + 服务端进度(任务面板改版后)', () => {
const page = read('src/pages/jd/JdCollectTab.vue')
// 进度真源仍是服务端:改版后走批量进度轮询(useLiveTaskBoard),不再有单任务进度条
assert.ok(page.includes('fetchJdCollectTaskProgressBatch'),
'采集页必须经 useLiveTaskBoard 轮询服务端批量进度(不拿本地内存数充进度)')
assert.ok(page.includes('file-progress') || page.includes('progress: showProgress'),
'采集页任务卡片必须带进度条(照外观专利面板形状)')
assert.ok(page.includes('一键获取店铺数据'), '主按钮应是一键获取')
assert.ok(page.includes('jd-shop-collect-run'), '建单后必须推送本机客户端队列')
assert.ok(page.includes('TaskCenterPanel'), '改版后右侧必须是共享任务面板(含历史任务层)')
})