208583e14c
- tool-catalog 最前插入「常用工具」组(brand_common_tools,23 工具·4 大分类), 三工具各自权限键:pricing-calc / five-asin / keyword-share - /pricing-calc:站点(英 GBP÷9、德法 EUR÷8)+ 买货价/运费 → 营业额/利润/ 利润率/换算汇率,公式与精度照抄桌面版,纯函数 node --test 钉住 - /five-asin:五国常量 + ASIN 10 位校验 → 亚马逊商品链接,window.open 与 :href 出口全部过 safeHttpUrl(url-outlet 棘轮),邮编一键复制 - /keyword-share:筛选/四级类目级联/统计卡/表格分页 200/标记与取消使用/ 添加/删除/随机抽词/共享记录,对接 keywordshare 后端九端点 - 顶栏与 BrandTopBar 导航同步;router 注册三路由;补 test:mount 脚本 (vitest mount 套件入口,与后管同口径)
136 lines
6.2 KiB
TypeScript
136 lines
6.2 KiB
TypeScript
import assert from 'node:assert/strict'
|
||
import test from 'node:test'
|
||
|
||
import {
|
||
filterGroupsByPermission,
|
||
filterWorkflowByPermission,
|
||
TOOL_DETAILS,
|
||
TOOL_GROUPS,
|
||
TOOL_ICON_GRADIENTS,
|
||
TOOL_ICON_SHAPES,
|
||
TOOL_MAP,
|
||
} from '../src/pages/amazon/tool-catalog.ts'
|
||
|
||
test('工具目录:23 个工具 id 唯一且每个都有图标与渐变配色', () => {
|
||
const ids = TOOL_GROUPS.flatMap((g) => g.tools.map((t) => t.id))
|
||
assert.equal(ids.length, 23, '工具总数应为 23(常用3 + 前端8 + 运营10 + 后勤2)')
|
||
assert.equal(new Set(ids).size, ids.length, '工具 id 不应重复')
|
||
for (const id of ids) {
|
||
assert.ok(TOOL_ICON_SHAPES[id], `图标形状缺失: ${id}`)
|
||
assert.ok(TOOL_ICON_GRADIENTS[id], `图标渐变缺失: ${id}`)
|
||
assert.equal(TOOL_MAP.get(id)?.id, id, `TOOL_MAP 应覆盖: ${id}`)
|
||
}
|
||
})
|
||
|
||
test('工具目录:常用工具分组排在最前且三个工具都有页面与权限键', () => {
|
||
const common = TOOL_GROUPS[0]
|
||
assert.equal(common.key, 'common', '常用工具组应在 TOOL_GROUPS 最前')
|
||
assert.equal(common.columnKey, 'brand_common_tools')
|
||
assert.equal(common.name, '常用工具')
|
||
assert.equal(common.desc, '换算 · 查询 · 词库共享,高频小工具')
|
||
assert.ok(common.color, '常用工具组应有主色')
|
||
assert.equal(common.workflow, undefined, '常用工具组没有标准工作流')
|
||
|
||
const byId = new Map(common.tools.map((tool) => [tool.id, tool]))
|
||
assert.deepEqual(
|
||
[...byId.keys()],
|
||
['pricing-calc', 'five-asin', 'keyword-share'],
|
||
'常用工具组的三个工具顺序固定',
|
||
)
|
||
assert.equal(byId.get('pricing-calc')?.href, '/pricing-calc')
|
||
assert.equal(byId.get('five-asin')?.href, '/five-asin')
|
||
assert.equal(byId.get('keyword-share')?.href, '/keyword-share')
|
||
assert.deepEqual(byId.get('pricing-calc')?.permissionKeys, ['pricing-calc'])
|
||
assert.deepEqual(byId.get('five-asin')?.permissionKeys, ['five-asin'])
|
||
assert.deepEqual(byId.get('keyword-share')?.permissionKeys, ['keyword-share'])
|
||
})
|
||
|
||
test('权限过滤:常用工具组整组 / 单工具键都按口径过滤', () => {
|
||
// 组键命中:整组保留且排在最前
|
||
const withCommon = filterGroupsByPermission(TOOL_GROUPS, ['brand_common_tools'])
|
||
const common = withCommon.find((group) => group.key === 'common')
|
||
assert.ok(common, '组键 brand_common_tools 命中时常用工具组应整组可见')
|
||
assert.deepEqual(common.tools.map((tool) => tool.id), ['pricing-calc', 'five-asin', 'keyword-share'])
|
||
|
||
// 只给单个工具权限键:常用组只留命中工具,不整组放行
|
||
const partial = filterGroupsByPermission(TOOL_GROUPS, ['pricing-calc', 'keyword-share'])
|
||
const partialCommon = partial.find((group) => group.key === 'common')
|
||
assert.ok(partialCommon, '有可见工具时常用组不应整体隐藏')
|
||
assert.deepEqual(partialCommon.tools.map((tool) => tool.id), ['pricing-calc', 'keyword-share'])
|
||
assert.equal(partialCommon.tools.some((tool) => tool.id === 'five-asin'), false, '无权限的 five-asin 不应混入')
|
||
|
||
// 无任何常用权限:常用组整体隐藏
|
||
const none = filterGroupsByPermission(TOOL_GROUPS, ['brand_front_tools'])
|
||
assert.equal(none.some((group) => group.key === 'common'), false, '无常用权限时常用组应隐藏')
|
||
|
||
// 无任何权限:全部隐藏
|
||
assert.equal(filterGroupsByPermission(TOOL_GROUPS, []).length, 0)
|
||
})
|
||
|
||
test('工具目录:无页面的工具应在 catalog 里标记为未开通(无 href)', () => {
|
||
const pending = TOOL_GROUPS.flatMap((g) => g.tools).filter((t) => !t.href)
|
||
const pendingIds = pending.map((t) => t.id).sort()
|
||
assert.deepEqual(pendingIds, ['erp', 'purchase', 'shop'], '只有 店铺状态查询/采购/ERP 未开通')
|
||
})
|
||
|
||
test('权限过滤:组键命中整组保留,未命中按工具权限过滤并隐藏空组', () => {
|
||
const allowedAll = ['brand_front_tools', 'brand_operation_tools', 'brand_logistics_tools']
|
||
const all = filterGroupsByPermission(TOOL_GROUPS, allowedAll)
|
||
assert.equal(all.length, 3)
|
||
assert.ok(all[0].tools.every((t) => t.permissionKeys.length > 0))
|
||
|
||
// 只给前端组键:仅前端工具整组可见
|
||
const frontOnly = filterGroupsByPermission(TOOL_GROUPS, ['brand_front_tools'])
|
||
assert.equal(frontOnly.length, 1)
|
||
assert.equal(frontOnly[0].key, 'front')
|
||
assert.equal(frontOnly[0].tools.length, 8)
|
||
|
||
// 无组键时按单个工具权限过滤
|
||
const partial = filterGroupsByPermission(TOOL_GROUPS, ['collect-data', 'publish'])
|
||
const groups = new Map(partial.map((g) => [g.key, g]))
|
||
assert.deepEqual(groups.get('front')?.tools.map((t) => t.id), ['collect'])
|
||
assert.deepEqual(groups.get('ops')?.tools.map((t) => t.id), ['list'])
|
||
assert.equal(groups.has('logi'), false, '后勤无可见工具应整体隐藏')
|
||
|
||
// 无任何权限:全部隐藏
|
||
assert.equal(filterGroupsByPermission(TOOL_GROUPS, []).length, 0)
|
||
})
|
||
|
||
test('权限过滤:工作流时间线按工具权限截断', () => {
|
||
const front = TOOL_GROUPS.find((g) => g.key === 'front')
|
||
assert.ok(front?.workflow?.length === 8)
|
||
|
||
// 只允许 采集数据,时间线只剩它一步
|
||
const steps = filterWorkflowByPermission(front?.workflow ?? [], ['collect-data'])
|
||
assert.equal(steps.length, 1)
|
||
assert.equal(steps[0].name, '采集数据')
|
||
|
||
// 无权限 → 空
|
||
assert.equal(filterWorkflowByPermission(front?.workflow ?? [], []).length, 0)
|
||
})
|
||
|
||
test('工具目录:页面链接与现有 BrandTopBar 导航映射一致', () => {
|
||
const expectHref = new Map<string, string>([
|
||
['collect', '/collect-data'],
|
||
['dedupe', '/dedupe'],
|
||
['source', '/similar-asin'],
|
||
['brand', '/brand'],
|
||
['list', '/publish'],
|
||
['follow', '/price-track'],
|
||
['scrape', '/shop-data-crawl'],
|
||
['cash', '/withdraw'],
|
||
])
|
||
for (const [id, href] of expectHref) {
|
||
assert.equal(TOOL_MAP.get(id)?.href, href, `工具 ${id} 应指向 ${href}`)
|
||
}
|
||
})
|
||
|
||
test('工具目录:页头长描述(detail)只覆盖已知工具,且不为空', () => {
|
||
for (const [id, detail] of Object.entries(TOOL_DETAILS)) {
|
||
assert.ok(TOOL_MAP.has(id), `TOOL_DETAILS 引用了未知工具: ${id}`)
|
||
assert.ok(detail.trim().length > 0, `工具 ${id} 的 detail 不应为空`)
|
||
const toolsWithHref = TOOL_MAP.get(id)
|
||
assert.ok(toolsWithHref?.href, `detail 只应用于有页面的工具: ${id}`)
|
||
}
|
||
})
|