Files
crawler-plugin/admin-frontend-vue/tests/mount/appearance-patent-clean-page.test.ts
huangzd1997 7299166e96 style(admin): 全站原生下拉统一换 el-select——弹层圆角与亚马逊面一致(2026-11-17 用户口径「样式咋不是圆角 和亚马逊不统一 其他地方也要看看」)
范围:src 里原生 <select> 由 36 处清零(含全站共享分页条),15 个页面 + 1 个组件。
换法统一:class="admin-filter"(main.css 皮肤 42px/9px/#f8fbfd/focus ring)+
aria-label 定位 + el-option 显式 label;「全部 XX」空值行与 value 形状逐字保留
('' / null / String(id) / '1'/'0' / `${source}|${deviceId}` 等,下游查询参数与后端枚举不动)。

- OldPagination:每页条数下拉换 el-select(局部 import,挂载测试单 mount 也能渲染),壳压回分页条 30px/8px 档
- account 三页(菜单类型/密钥状态/分组)+ GroupsPage/UsersPage 清死 select 规则
- asin 三页(国家/弹窗分组):弹窗分组用 placeholder+clearable+:value-on-clear 钉回 null,守 number|null 契约
- patent 页(国家/分组)
- records 两页(来源/用户/终端覆盖):终端覆盖 value 仍 source|deviceId
- tasks 四页 + 任务看板(业务/状态/类型/来源/店铺/分组/场景):BrandGating/DuplicateCheck/KeywordUsage 三页本地是 34px 紧凑档,
  故把 el-select 壳压回本地 34px/7px 与同行输入框齐高(否则高 8px 错位)

测试:mount 全量 21 文件 164 passed;node --test 1924 例 1922 passed(2 红为在册:
date-range-order 环境红、company-config-entry-super-only 由 ee613db0 引入与本次无关);
vue-tsc rc=0。新增 account-select-el / records-select-el 两支换壳契约(值形状 + 空值行 + 点开→点选项)。
2026-11-17 13:49:39 +08:00

365 lines
18 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 外观专利数据库页(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 { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
import { createPinia, setActivePinia, type Pinia } from 'pinia'
import { ElOption, ElSelect } from 'element-plus'
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, ElSelect, ElOption] } })
await flushPromises()
await flushPromises()
return wrapper
}
// ---------------- el-select 交互助手(2026-11-17 筛选行/分页条下拉换 el-select,与亚马逊面统一) ----------------
// aria-label 经 EP 的 ariaLabel prop 落在内层 combobox input 上;弹层 teleport 到 body,
// ElOption 仍在挂载树里 ⇒ 选项清单走组件树读,点选走「点开→点选项」真实路径。
function selectByLabel(wrapper: VueWrapper<Element>, label: string) {
const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists())
expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy()
return found!
}
function optionLabels(wrapper: VueWrapper<Element>, label: string): string[] {
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('label') as string)
}
async function pickSelectOption(wrapper: VueWrapper<Element>, label: string, optionText: string): Promise<void> {
const input = wrapper.get(`[aria-label="${label}"]`)
await input.trigger('click')
await flushPromises()
const contentId = input.attributes('aria-controls')
const scope = (contentId && document.getElementById(contentId)) ?? document.body
const items = [...scope.querySelectorAll('.el-select-dropdown__item')]
.filter((el) => !el.classList.contains('is-hidden'))
const target = items.find((el) => (el.textContent ?? '').trim() === optionText)
expect(target, `下拉应弹出「${optionText}」选项`).toBeTruthy()
await new DOMWrapper(target as Element).trigger('click')
await flushPromises()
}
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"]:not(.el-select__input)')
expect(textInputs).toHaveLength(2, '任务号+ASIN 两个筛选框恢复(客户要一目了然)')
await textInputs[0].setValue('33874')
await textInputs[1].setValue('B0CLEAN')
await pickSelectOption(wrapper, '筛选国家', '德国') // 国家排在前(模板顺序:任务号/ASIN/国家/分组)
await pickSelectOption(wrapper, '筛选分组', '甲组') // 分组(主管=组长)
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 groups = optionLabels(wrapper, '筛选分组')
expect(groups).toContain('全部分组')
expect(groups).toContain('甲组')
const callsBeforeSelect = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
await pickSelectOption(wrapper, '筛选分组', '甲组')
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"]:not(.el-select__input)')
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)
// 每页条数下拉 2026-11-17 随分页条一起换 el-select(OldPagination 内局部注册)。
expect(wrapper.find('.page-size-select').exists()).toBe(true, '分页条下拉保留 .page-size-select 定位类')
await pickSelectOption(wrapper, '每页条数', '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"]:not(.el-select__input)')
await textInputs[0].setValue('33874')
await textInputs[1].setValue('B0CLEAN')
await pickSelectOption(wrapper, '筛选分组', '甲组')
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)
})
})