revert(common-tools): 回滚常用工具分类与三个工具页

按 2026-10-24 决定整体下线:工具目录分组、定价换算/五国ASIN/关键词共享
三页面与路由、资料下载区与测试全部移除;保留 package.json 的 test:mount
脚本(仓内测试基础设施,与后管同口径)。
This commit is contained in:
2026-10-24 01:43:45 +08:00
parent 314c283503
commit 634fefbc2f
29 changed files with 16 additions and 3234 deletions
@@ -1,153 +0,0 @@
/**
* 常用工具两页的挂载冒烟测试(tests/mount/** 由 vitest 收)。
*
* 页面壳(AmazonToolPageShell→AmazonTopBar)依赖权限接口与路由,这里整体桩掉,
* 只验页面本体的行为:换算数值、站点切换清空、资料下载/常用链接出口、ASIN 校验与链接拼装。
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import PricingCalcPage from '@/pages/common/PricingCalcPage.vue'
import FiveAsinPage from '@/pages/common/FiveAsinPage.vue'
vi.mock('@/shared/api/permission', () => ({
getCurrentUserAppColumnKeys: vi.fn().mockResolvedValue([]),
}))
class ResizeObserverStub {
observe() {}
unobserve() {}
disconnect() {}
}
const STUBS = {
RouterLink: true,
'router-link': true,
AmazonTopBar: true,
NotificationBell: true,
BrandApiSecretSettingsButton: true,
DownloadProgressPanel: true,
AmazonFooterBar: true,
}
let wrapper: VueWrapper | null = null
function mountPage(component: object) {
wrapper = mount(component, {
global: { plugins: [ElementPlus], stubs: STUBS },
})
return wrapper
}
function findButtonByText(text: RegExp) {
return (wrapper?.findAll('button') ?? []).find((b) => text.test(b.text()))
}
async function setInput(index: number, value: string) {
const input = wrapper?.findAll('input')[index]
expect(input, `第 ${index} 个输入框不存在`).toBeTruthy()
await input!.setValue(value)
}
describe('定价利润换算页', () => {
beforeEach(() => {
if (!(globalThis as Record<string, unknown>).ResizeObserver) {
;(globalThis as Record<string, unknown>).ResizeObserver = ResizeObserverStub
}
})
afterEach(() => {
wrapper?.unmount()
wrapper = null
})
it('买货价 10 + 运费 5(英国)→ 营业额 30.00 / 利润 9.00 / 利润率 30.0% / 汇率 3.3333', async () => {
const page = mountPage(PricingCalcPage)
await setInput(0, '10')
await setInput(1, '5')
findButtonByText(/^换算利润$/).trigger('click')
await flushPromises()
const values = page.findAll('.result-value').map((n) => n.text())
expect(values).toEqual(['30.00', '9.00', '30.0%', '3.3333'])
})
it('切到德国·法国:除数 8 生效,且切换站点清空已有结果', async () => {
const page = mountPage(PricingCalcPage)
await setInput(0, '10')
await setInput(1, '5')
findButtonByText(/^换算利润$/).trigger('click')
await flushPromises()
expect(page.findAll('.result-value').length).toBe(4)
findButtonByText(/德国·法国/).trigger('click')
await flushPromises()
expect(page.find('.result-empty').exists()).toBe(true)
findButtonByText(/^换算利润$/).trigger('click')
await flushPromises()
expect(page.findAll('.result-value')[3]?.text()).toBe('3.7500')
})
it('资料下载四个锚点落在 /static/ 且 href 无裸空格;常用链接均为 http(s)', async () => {
const page = mountPage(PricingCalcPage)
const downloadHrefs = page
.findAll('a[download]')
.map((a) => a.attributes('href') ?? '')
expect(downloadHrefs).toHaveLength(4)
for (const href of downloadHrefs) {
expect(href.startsWith('/static/')).toBe(true)
expect(href.includes(' ')).toBe(false)
}
const linkHrefs = page
.findAll('.resource-block')
.filter((block) => block.text().includes('常用链接'))
.flatMap((block) => block.findAll('a').map((a) => a.attributes('href') ?? ''))
expect(linkHrefs.length).toBeGreaterThanOrEqual(5)
for (const href of linkHrefs) {
expect(/^https?:\/\//.test(href)).toBe(true)
}
})
})
describe('五国ASIN快速查询页', () => {
beforeEach(() => {
if (!(globalThis as Record<string, unknown>).ResizeObserver) {
;(globalThis as Record<string, unknown>).ResizeObserver = ResizeObserverStub
}
})
afterEach(() => {
wrapper?.unmount()
wrapper = null
})
it('五个国家可选,小写输入规范化后拼出 amazon.co.uk 商品链接', async () => {
const page = mountPage(FiveAsinPage)
expect(page.findAll('.country-btn')).toHaveLength(5)
await setInput(0, ' b0c1234abc ')
await flushPromises()
const link = page.find('.link-url')
expect(link.attributes('href')).toBe('https://www.amazon.co.uk/dp/B0C1234ABC')
expect(link.text()).toBe('https://www.amazon.co.uk/dp/B0C1234ABC')
})
it('切到德国后链接域名随国家走', async () => {
const page = mountPage(FiveAsinPage)
page.findAll('.country-btn')[1].trigger('click')
await setInput(0, 'B012345678')
await flushPromises()
expect(page.find('.link-url').attributes('href')).toBe('https://www.amazon.de/dp/B012345678')
expect(page.find('.postcode-value').text()).toBe('10115')
})
it('不足 10 位给中文报错并禁用「打开商品页」', async () => {
const page = mountPage(FiveAsinPage)
await setInput(0, 'B0123')
await flushPromises()
expect(page.find('.asin-error').text()).toContain('10')
expect(findButtonByText(/^打开商品页$/).attributes('disabled')).toBeDefined()
})
})
@@ -1,160 +0,0 @@
/**
* 五国关键词共享页挂载用例(2026-10-21 常用工具网页化)。
*
* 两件事都要判,缺一条就是假绿:
* ① 首屏真实走 API:列表行、统计卡都来自 /keywords 返回,页面不得自带假数据;
* ② 行内「标记已使用」真实打到 POST /usage/mark,且载荷是 country+keyword、
* 成功后重拉列表(防"点了没反应")。
*
* 跑法:cd frontend-vue && npx vitest run tests/mount/keyword-share-page.mount.test.ts
* (tests/mount/** 由 vitest.config.ts 收,node --test 的 glob 抓不到这里。)
*/
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import ElementPlus from 'element-plus'
import KeywordSharePage from '@/pages/common/KeywordSharePage.vue'
// API 层整模块 mock:纯函数(buildKeywordStatsSections / mapKeywordShareLogs)保留真实现,
// 网络函数按用例给桩。页面经 shared/api/types/modules/keyword-share 调用。
const api = vi.hoisted(() => ({
fetchKeywordShareFilters: vi.fn(),
fetchKeywordShareKeywords: vi.fn(),
fetchKeywordShareStatsGrouped: vi.fn(),
addKeywordShareKeywords: vi.fn(),
deleteKeywordShareKeywords: vi.fn(),
markKeywordShareUsage: vi.fn(),
unmarkKeywordShareUsage: vi.fn(),
fetchKeywordShareLogs: vi.fn(),
fetchKeywordShareRandom: vi.fn(),
}))
vi.mock('@/shared/api/types/modules/keyword-share', async (importOriginal) => ({
...(await importOriginal<typeof import('@/shared/api/types/modules/keyword-share')>()),
...api,
}))
vi.mock('@/shared/api/permission', () => ({
getCurrentUserAppColumnKeys: vi.fn().mockResolvedValue([]),
}))
const ROWS = [
{
id: 1,
country: '英国',
keyword: 'wireless charger',
chinese: '无线充电器',
category: '电子',
subCategory: '配件',
categoryL3: '充电',
categoryL4: '无线充',
used: false,
usedTime: null,
usedUser: null,
},
{
id: 2,
country: '德国',
keyword: 'handtuch wärmer',
chinese: '毛巾架',
category: '家居',
subCategory: '浴室',
categoryL3: '毛巾架',
categoryL4: '加热',
used: true,
usedTime: '2026-10-20 10:00:00',
usedUser: '张三',
},
]
const LIST_VO = {
total: 2,
rows: ROWS,
stats: { hit: 2, used: 1, unused: 1, dup: 0 },
}
// happy-dom 没有ResizeObserver 时 el-table 会挂不上,补一个最小桩
class ResizeObserverStub {
observe() {}
unobserve() {}
disconnect() {}
}
let wrapper: VueWrapper | null = null
async function mountPage() {
wrapper = mount(KeywordSharePage, {
global: {
plugins: [ElementPlus],
stubs: {
RouterLink: true,
'router-link': true,
NotificationBell: true,
BrandApiSecretSettingsButton: true,
DownloadProgressPanel: true,
AmazonFooterBar: true,
},
},
})
await flushPromises()
await flushPromises()
return wrapper
}
function findButtonByText(text: string) {
const buttons = wrapper?.findAll('button') ?? []
return buttons.find((button) => button.text().trim() === text)
}
describe('五国关键词共享页', () => {
beforeEach(() => {
if (!(globalThis as Record<string, unknown>).ResizeObserver) {
;(globalThis as Record<string, unknown>).ResizeObserver = ResizeObserverStub
}
api.fetchKeywordShareFilters.mockResolvedValue({ countries: ['英国', '德国'], categories: [] })
api.fetchKeywordShareKeywords.mockResolvedValue(LIST_VO)
api.markKeywordShareUsage.mockResolvedValue({ marked: 1 })
api.unmarkKeywordShareUsage.mockResolvedValue({ unmarked: 1 })
})
afterEach(() => {
wrapper?.unmount()
wrapper = null
vi.clearAllMocks()
})
it('首屏渲染 API 返回的关键词行与统计卡(无假数据)', async () => {
const w = await mountPage()
expect(api.fetchKeywordShareKeywords).toHaveBeenCalledTimes(1)
const text = w.text()
expect(text, '行数据来自 /keywords 返回').toContain('wireless charger')
expect(text).toContain('handtuch wärmer')
expect(text).toContain('✓已使用·2026-10-20 10:00:00·张三')
expect(text).toContain('未使用')
// 统计卡四格来自返回的 stats
expect(text).toContain('命中总数')
expect(w.findAll('.stat-card .stat-value').map((node) => node.text())).toEqual(['2', '1', '1', '0'])
})
it('行内「标记已使用」打到 POST /usage/mark(country+keyword 载荷)并重拉列表', async () => {
await mountPage()
expect(api.markKeywordShareUsage).not.toHaveBeenCalled()
const markBtn = findButtonByText('标记已使用')
expect(markBtn, '未使用行应显示「标记已使用」').toBeTruthy()
await markBtn!.trigger('click')
await flushPromises()
expect(api.markKeywordShareUsage).toHaveBeenCalledTimes(1)
expect(api.markKeywordShareUsage).toHaveBeenCalledWith([{ country: '英国', keyword: 'wireless charger' }])
expect(api.fetchKeywordShareKeywords, '标记成功后应重拉列表').toHaveBeenCalledTimes(2)
})
it('已使用行的行内按钮是「标记未使用」,点击走 POST /usage/unmark', async () => {
await mountPage()
const unmarkBtn = findButtonByText('标记未使用')
expect(unmarkBtn, '已使用行应显示「标记未使用」').toBeTruthy()
await unmarkBtn!.trigger('click')
await flushPromises()
expect(api.unmarkKeywordShareUsage).toHaveBeenCalledWith([{ country: '德国', keyword: 'handtuch wärmer' }])
expect(api.markKeywordShareUsage).not.toHaveBeenCalled()
})
})