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 套件入口,与后管同口径)
49 lines
2.2 KiB
TypeScript
49 lines
2.2 KiB
TypeScript
import test from 'node:test'
|
|
import assert from 'node:assert/strict'
|
|
|
|
import {
|
|
buildAmazonProductUrl,
|
|
FIVE_ASIN_COUNTRIES,
|
|
FIVE_ASIN_COUNTRY_MAP,
|
|
isValidAsin,
|
|
normalizeAsin,
|
|
} from '../src/pages/common/five-asin.ts'
|
|
|
|
test('五国站点常量:域名 / 邮编 / 城市与桌面版一致', () => {
|
|
assert.equal(FIVE_ASIN_COUNTRIES.length, 5)
|
|
const byCode = new Map(FIVE_ASIN_COUNTRIES.map((c) => [c.code, c]))
|
|
assert.deepEqual(byCode.get('uk'), {
|
|
code: 'uk', name: '英国', flag: '🇬🇧', domain: 'www.amazon.co.uk', postcode: 'SW1A 1AA', city: '伦敦', currency: '英镑',
|
|
})
|
|
assert.equal(byCode.get('de')?.postcode, '10115')
|
|
assert.equal(byCode.get('fr')?.postcode, '75001')
|
|
assert.equal(byCode.get('es')?.postcode, '28001')
|
|
assert.equal(byCode.get('it')?.postcode, '20121')
|
|
// 五国域名唯一且都带 https 之外的裸域名形状
|
|
assert.equal(new Set(FIVE_ASIN_COUNTRIES.map((c) => c.domain)).size, 5)
|
|
for (const country of FIVE_ASIN_COUNTRIES) {
|
|
assert.equal(FIVE_ASIN_COUNTRY_MAP.get(country.code), country, 'code→country 映射应完整')
|
|
}
|
|
})
|
|
|
|
test('ASIN 规范化:strip + 大写 + 去非字母数字', () => {
|
|
assert.equal(normalizeAsin(' b0c1234abc '), 'B0C1234ABC')
|
|
assert.equal(normalizeAsin('B0C-1234 abc'), 'B0C1234ABC')
|
|
assert.equal(normalizeAsin('asin/1234?5'), 'ASIN12345')
|
|
assert.equal(normalizeAsin(''), '')
|
|
})
|
|
|
|
test('ASIN 校验:规范化后必须恰好 10 位字母数字', () => {
|
|
assert.equal(isValidAsin('B0C1234ABC'), true)
|
|
assert.equal(isValidAsin(normalizeAsin(' b0c1234abc ')), true, '页面先规范化再校验,小写输入规范化后应合法')
|
|
assert.equal(isValidAsin('B0C1234AB'), false, '9 位应判不合法')
|
|
assert.equal(isValidAsin('B0C1234ABCD'), false, '11 位应判不合法')
|
|
assert.equal(isValidAsin(''), false)
|
|
assert.equal(isValidAsin('B0C1234AB!'), false, '非字母数字应判不合法')
|
|
})
|
|
|
|
test('商品页链接:https://{domain}/dp/{asin}', () => {
|
|
assert.equal(buildAmazonProductUrl('www.amazon.co.uk', 'B0C1234ABC'), 'https://www.amazon.co.uk/dp/B0C1234ABC')
|
|
assert.equal(buildAmazonProductUrl('www.amazon.de', 'B0C1234ABC'), 'https://www.amazon.de/dp/B0C1234ABC')
|
|
})
|