338 lines
17 KiB
TypeScript
338 lines
17 KiB
TypeScript
/**
|
||
* 外观专利数据库页(v1.3 AC-5,2026-11-11 晚间恢复明细表)的挂载契约。
|
||
*
|
||
* 形态(客户当日口径「不是这种格式 你就按照昨天那个格式」):撤掉一主管一卡视图,
|
||
* 恢复只读明细表(自绘 table + OldPagination,参照「去重数据库」页);表头第二列=「管理员」
|
||
* (后端读侧现算 supervisorName,读不到展示 -);「添加个管理员 跟导出数据就可以」——
|
||
* 筛选行有「导出」(当前过滤面+公司 tab 全量出 xlsx,与去重页同款);「任务号/ASIN 两个
|
||
* 筛选框恢复」(客户要「一目了然」选数据);分组(主管)下拉保留选中即查。
|
||
* 卡片级下载/删除入口随卡片视图一并下架(删除入口先撤,防误删;后端 /supervisors 接口保留)。
|
||
* 数据按 ASIN 累计(同 ASIN 只保留一条,V192 唯一键),页面零写操作。
|
||
*
|
||
* 跑法:`npx vitest run tests/mount/appearance-patent-clean-page.test.ts`
|
||
*/
|
||
import { readFileSync } from 'node:fs'
|
||
import { resolve } from 'node:path'
|
||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||
|
||
import AppearancePatentCleanItemsPage from '@/pages/patent/AppearancePatentCleanItemsPage.vue'
|
||
import { adminPages } from '@/router/routes'
|
||
import { COMPANY_SCOPED_PAGES } from '@/config/company-scope'
|
||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||
import { useCompanyTabStore } from '@/stores/company-tab'
|
||
|
||
const PAGE_PATH = 'src/pages/patent/AppearancePatentCleanItemsPage.vue'
|
||
const MENU_KEY = 'admin_appearance_patent_clean_items'
|
||
|
||
const cleanApi = vi.hoisted(() => ({
|
||
fetchAppearancePatentCleanList: vi.fn(),
|
||
exportAppearancePatentCleanList: vi.fn(),
|
||
fetchDedupeTotalGroups: vi.fn(),
|
||
}))
|
||
|
||
vi.mock('@/pages/patent/appearance-patent-clean-api.ts', () => cleanApi)
|
||
|
||
function item(id: number, over: Record<string, unknown> = {}) {
|
||
return {
|
||
id,
|
||
resultId: 36800 + id,
|
||
taskId: 33874,
|
||
userId: 9,
|
||
supervisorName: '主管9',
|
||
companyId: 1,
|
||
rowNo: id,
|
||
asin: `B0CLEAN00${id}`,
|
||
country: 'DE',
|
||
sku: `SKU-00${id}`,
|
||
brand: 'Nike',
|
||
price: '12.99',
|
||
title: 'Women Floral Dress Summer Casual',
|
||
imageUrl: '',
|
||
itemUrl: '',
|
||
conclusion: '无侵权',
|
||
titleReason: '',
|
||
appearanceReason: '',
|
||
patentReason: '',
|
||
sourceFilename: 'appearance_patent_33874.xlsx',
|
||
syncedAt: '2026-11-11T11:34:29',
|
||
...over,
|
||
}
|
||
}
|
||
|
||
let pinia: Pinia
|
||
|
||
beforeEach(() => {
|
||
vi.clearAllMocks()
|
||
pinia = createPinia()
|
||
setActivePinia(pinia)
|
||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||
useCompanyTabStore().setActiveId(1)
|
||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([])
|
||
})
|
||
|
||
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||
cleanApi.fetchAppearancePatentCleanList.mockImplementation(() => Promise.resolve(payload))
|
||
const wrapper = mount(AppearancePatentCleanItemsPage, { global: { plugins: [pinia] } })
|
||
await flushPromises()
|
||
await flushPromises()
|
||
return wrapper
|
||
}
|
||
|
||
describe('外观专利数据库页(明细表,2026-11-11 恢复「昨天那个格式」)', () => {
|
||
it('页面组件落位:明细表 + 明细端点 + 导出,卡片视图与删除入口已下架', () => {
|
||
const src = readFileSync(resolve(process.cwd(), PAGE_PATH), 'utf-8')
|
||
expect(src).toContain('OldPagination')
|
||
expect(src).toContain('<table', '恢复自绘明细表(客户「按照昨天那个格式」)')
|
||
expect(src).toContain('管理员', '表头必须有「管理员」列(客户「添加个管理员」)')
|
||
expect(src).toContain('fetchAppearancePatentCleanList', '必须走明细分页端点')
|
||
expect(src).toContain('exportAll', '筛选行要有「导出」(客户「跟数据去重一样 能导出来就可以」)')
|
||
expect(src).toContain('cleanItemReasonTooltip', '结论列带三因原因提示')
|
||
expect(src).toContain('filter.taskId', '任务号筛选框恢复')
|
||
expect(src).toContain('filter.asin', 'ASIN 筛选框恢复')
|
||
// 卡片视图与删除入口下架:这些符号只该在后端/历史里,不该再出现在本页
|
||
expect(src).not.toContain('clean-card-grid', '一主管一卡视图已撤')
|
||
expect(src).not.toContain('fetchAppearancePatentCleanSupervisors', '主管聚合取数口已撤')
|
||
expect(src).not.toContain('deleteAppearancePatentCleanSupervisor', '按主管删除的页面入口已撤')
|
||
expect(src).not.toContain('openAdminConfirm', '本页零写操作,不该再有任何确认弹窗')
|
||
expect(src).not.toContain('el-card')
|
||
})
|
||
|
||
it('路由与公司 Tab 注册齐备(companyScoped: true)', () => {
|
||
const page = adminPages.find((p) => p.path === 'patent-center/clean-items')
|
||
expect(page).toBeTruthy()
|
||
expect(page?.menuKey).toBe(MENU_KEY)
|
||
expect(page?.title).toBe('外观专利数据库')
|
||
expect(page?.companyScoped).toBe(true)
|
||
const scoped = COMPANY_SCOPED_PAGES.find((p) => p.menuKey === MENU_KEY)
|
||
expect(scoped).toBeTruthy()
|
||
expect(scoped?.pageFiles).toContain(PAGE_PATH)
|
||
})
|
||
|
||
it('挂载后按首屏分页参数取明细列表,行数=本页明细条数', async () => {
|
||
const wrapper = await mountWith({
|
||
items: [item(1), item(2), item(3)],
|
||
total: 42,
|
||
page: 1,
|
||
pageSize: 10,
|
||
})
|
||
|
||
expect(cleanApi.fetchAppearancePatentCleanList).toHaveBeenCalledTimes(1)
|
||
const firstCall = cleanApi.fetchAppearancePatentCleanList.mock.calls[0][0]
|
||
expect(firstCall.page).toBe(1)
|
||
expect(firstCall.pageSize).toBe(10)
|
||
expect(firstCall.companyId).toBe(1)
|
||
expect(wrapper.findAll('tbody tr')).toHaveLength(3)
|
||
expect(wrapper.find('.clean-summary').text()).toContain('共 42 条', '汇总按明细条数(不是主管数)')
|
||
})
|
||
|
||
it('行内容=任务号/管理员/ASIN/国家/SKU/品牌/价格/标题/结论/同步时间', async () => {
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 10 })
|
||
const cells = wrapper.findAll('tbody tr')[0].findAll('td')
|
||
expect(cells).toHaveLength(10)
|
||
expect(cells[0].text()).toBe('33874', '任务号')
|
||
expect(cells[1].text()).toBe('主管9', '管理员(supervisorName 读侧现算列)')
|
||
expect(cells[2].text()).toBe('B0CLEAN001')
|
||
expect(cells[3].text()).toBe('德国', '国家码翻中文')
|
||
expect(cells[4].text()).toBe('SKU-001')
|
||
expect(cells[5].text()).toBe('Nike')
|
||
expect(cells[6].text()).toBe('12.99')
|
||
expect(cells[7].text()).toContain('Women Floral Dress')
|
||
expect(cells[8].text()).toBe('无侵权')
|
||
expect(cells[9].text()).not.toBe('-', '同步时间格式化展示')
|
||
const headers = wrapper.findAll('thead th').map((th) => th.text())
|
||
expect(headers).toContain('管理员')
|
||
expect(headers).not.toContain('所属主管', '列名按客户口径叫「管理员」')
|
||
})
|
||
|
||
/** 客户 2026-11-12 反馈「外观专利数据库的日期显示不全」:全局 `* { box-sizing: border-box }` 把左右 24px
|
||
* 内边距算进列宽,旧的 150px 只剩 126px 内容宽,而 `YYYY-MM-DD HH:mm:ss` 十九字符在 13.5px 下实测约
|
||
* 133px ⇒ 末尾被 ellipsis 吃掉(表格单元格是 nowrap + text-overflow: ellipsis)。判据钉列宽下限:
|
||
* ≥160px 才有 ≥136px 内容宽放得下完整时间;回退到 150px 即红。 */
|
||
it('同步时间列宽够放十九字符时间(列宽下限 160px,防 ellipsis 再截断)', async () => {
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 10 })
|
||
const headers = wrapper.findAll('thead th')
|
||
const dateHeader = headers[headers.length - 1]
|
||
expect(dateHeader.text()).toBe('同步时间')
|
||
const declared = Number.parseFloat(dateHeader.element.style.width)
|
||
expect(Number.isFinite(declared), '同步时间列必须显式声明宽度(table-layout: fixed 下靠它定列宽)').toBe(true)
|
||
expect(declared).toBeGreaterThanOrEqual(160, '150px − 24px 内边距 = 126px < 133px,时间会被截断')
|
||
})
|
||
|
||
it('读不到主管的那一行管理员列展示 -(不猜名字)', async () => {
|
||
const wrapper = await mountWith({ items: [item(1, { supervisorName: '' })], total: 1, page: 1, pageSize: 10 })
|
||
expect(wrapper.findAll('tbody tr')[0].findAll('td')[1].text()).toBe('-')
|
||
})
|
||
|
||
it('导出=当前过滤面全量(含任务号/ASIN 与公司 tab),不传按主管参数', async () => {
|
||
const createObjectURL = vi.fn(() => 'blob:mock-url')
|
||
const revokeObjectURL = vi.fn()
|
||
const urlRecord = URL as unknown as Record<string, unknown>
|
||
Object.defineProperty(URL, 'createObjectURL', { value: createObjectURL, configurable: true, writable: true })
|
||
Object.defineProperty(URL, 'revokeObjectURL', { value: revokeObjectURL, configurable: true, writable: true })
|
||
const clickSpy = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => {})
|
||
cleanApi.exportAppearancePatentCleanList.mockImplementation(() =>
|
||
Promise.resolve({ blob: new Blob(['xlsx']), filename: '外观专利数据库-20261111235900.xlsx' }),
|
||
)
|
||
|
||
try {
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 10 })
|
||
const btn = wrapper.findAll('button').find((b) => b.text() === '导出')
|
||
expect(btn, '筛选行必须有「导出」按钮').toBeTruthy()
|
||
await btn!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
|
||
expect(cleanApi.exportAppearancePatentCleanList).toHaveBeenCalledTimes(1)
|
||
const call = cleanApi.exportAppearancePatentCleanList.mock.calls[0][0]
|
||
expect(call).toMatchObject({ taskId: '', asin: '', country: '', groupId: '', companyId: 1 })
|
||
expect(call.supervisorUserId).toBeUndefined()
|
||
expect(createObjectURL).toHaveBeenCalledTimes(1)
|
||
expect(clickSpy).toHaveBeenCalled()
|
||
expect(document.body.textContent).toContain('已导出', '成功反馈点名落盘文件')
|
||
} finally {
|
||
Object.defineProperty(URL, 'createObjectURL', { value: undefined, configurable: true, writable: true })
|
||
Object.defineProperty(URL, 'revokeObjectURL', { value: undefined, configurable: true, writable: true })
|
||
clickSpy.mockRestore()
|
||
}
|
||
})
|
||
|
||
it('导出失败把服务端业务文案弹出来,不许静默;在途标记复位', async () => {
|
||
cleanApi.exportAppearancePatentCleanList.mockImplementation(() =>
|
||
Promise.reject(new Error('无侵权数据共 90001 行,超过导出上限 50000 行,请缩小筛选范围后重试')))
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 10 })
|
||
await wrapper.findAll('button').find((b) => b.text() === '导出')!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(document.body.textContent).toContain('超过导出上限')
|
||
const btn = wrapper.findAll('button').find((b) => b.text() === '导出')
|
||
expect(btn!.text()).toBe('导出', '失败后在途标记必须复位')
|
||
expect((btn!.element as HTMLButtonElement).disabled).toBe(false)
|
||
})
|
||
|
||
it('任务号/ASIN/国家/分组/起止时间筛选生效', async () => {
|
||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([{ id: 7, name: '甲组', leaderUserId: 9 }])
|
||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||
|
||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||
expect(textInputs).toHaveLength(2, '任务号+ASIN 两个筛选框恢复(客户要一目了然)')
|
||
await textInputs[0].setValue('33874')
|
||
await textInputs[1].setValue('B0CLEAN')
|
||
|
||
const selects = wrapper.findAll('select')
|
||
await selects[0].setValue('DE') // 国家排在前(模板顺序:任务号/ASIN/国家/分组)
|
||
await selects[1].setValue('7') // 分组(主管=组长)
|
||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||
await dateInputs[0].setValue('2026-11-01')
|
||
await dateInputs[1].setValue('2026-11-09')
|
||
await wrapper.findAll('button').find((b) => b.text() === '查询')!.trigger('click')
|
||
await flushPromises()
|
||
|
||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({
|
||
taskId: '33874',
|
||
asin: 'B0CLEAN',
|
||
country: 'DE',
|
||
groupId: '7',
|
||
startDate: '2026-11-01',
|
||
endDate: '2026-11-09',
|
||
page: 1,
|
||
})
|
||
})
|
||
|
||
it('分组下拉(主管=组长)选中即查', async () => {
|
||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([
|
||
{ id: 7, name: '甲组', leaderUserId: 9 },
|
||
{ id: 8, name: '乙组', leaderUserId: 10 },
|
||
])
|
||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||
expect(cleanApi.fetchDedupeTotalGroups).toHaveBeenCalledWith(1)
|
||
|
||
const groupSelect = wrapper.findAll('select')[1] // 模板顺序:国家在前、分组在后
|
||
const optionTexts = groupSelect.findAll('option').map((o) => o.text())
|
||
expect(optionTexts).toContain('全部分组')
|
||
expect(optionTexts).toContain('甲组')
|
||
|
||
const callsBeforeSelect = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||
await groupSelect.setValue('7')
|
||
await flushPromises()
|
||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.length).toBe(callsBeforeSelect + 1,
|
||
'选中分组必须立刻重查')
|
||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]).toMatchObject({
|
||
groupId: '7',
|
||
page: 1,
|
||
})
|
||
})
|
||
|
||
it('重置把筛选面回空并回第一页重取', async () => {
|
||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||
await textInputs[0].setValue('33874')
|
||
await textInputs[1].setValue('B0CLEAN')
|
||
const callsBefore = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||
|
||
await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.length).toBeGreaterThan(callsBefore)
|
||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({ taskId: '', asin: '', page: 1 }, '重置后筛选全空、回第一页')
|
||
})
|
||
|
||
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
|
||
const wrapper = await mountWith({ items: [item(1)], total: 42, page: 2, pageSize: 10 })
|
||
|
||
await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click')
|
||
await flushPromises()
|
||
expect(cleanApi.fetchAppearancePatentCleanList).toHaveBeenCalledTimes(2)
|
||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls[1][0].page).toBe(3)
|
||
|
||
const sizeSelect = wrapper.find('.page-size-select')
|
||
await sizeSelect.setValue('50')
|
||
await flushPromises()
|
||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||
expect(last.pageSize).toBe(50)
|
||
expect(last.page).toBe(1, '改每页条数后回第一页')
|
||
})
|
||
|
||
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
|
||
const empty = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||
const tip = empty.find('.empty-tip')
|
||
expect(tip.exists()).toBe(true)
|
||
expect(tip.text()).toContain('暂无无侵权数据')
|
||
empty.unmount()
|
||
|
||
cleanApi.fetchAppearancePatentCleanList.mockRejectedValue(new Error('上游 502'))
|
||
const failed = mount(AppearancePatentCleanItemsPage, { global: { plugins: [pinia] } })
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(failed.find('.load-failure-bar').exists()).toBe(true)
|
||
expect(failed.find('.load-failure-bar').text()).toContain('无侵权数据加载失败')
|
||
})
|
||
|
||
it('切公司 Tab 重取并清掉上一家的筛选(company-tab-wiring 同口径)', async () => {
|
||
cleanApi.fetchDedupeTotalGroups.mockResolvedValue([{ id: 7, name: '甲组', leaderUserId: 9 }])
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 10 })
|
||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||
await textInputs[0].setValue('33874')
|
||
await textInputs[1].setValue('B0CLEAN')
|
||
const groupSelect = wrapper.findAll('select')[1]
|
||
await groupSelect.setValue('7')
|
||
const callsBefore = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||
|
||
useCompanyTabStore().setActiveId(2)
|
||
await flushPromises()
|
||
await flushPromises()
|
||
|
||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.length).toBeGreaterThan(callsBefore)
|
||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||
expect(last.companyId).toBe(2)
|
||
expect(last.taskId).toBe('', '切公司必须清掉上一家的任务号')
|
||
expect(last.asin).toBe('', '切公司必须清掉上一家的 ASIN')
|
||
expect(last.groupId).toBe('', '切公司必须清掉上一家选的分组')
|
||
expect(last.page).toBe(1)
|
||
expect(cleanApi.fetchDedupeTotalGroups).toHaveBeenLastCalledWith(2)
|
||
})
|
||
})
|