feat(phase-3): 后管无侵权只读页——私有鉴权闸+readCompanyIdOrOwn 公司隔离+分页钳制;前端自绘表格页与路由/操作提示/五护栏同轮记账
后端:AdminAppearancePatentCleanItemsController(GET /api/admin/appearance-patent-clean-items,requireCleanItemsAccess 照去重页形状)+ AppearancePatentCleanItemQueryService(page≤10000/size≤100 钳制防 (page-1)*page_size 溢出)+两 VO;PageDefaults 第五种 page_size=10 显式登记。前端:AppearancePatentCleanItemsPage(自绘 table+OldPagination,companyScoped)+api/filter/model 拆件;routes/company-scope/operation-guides 收口。护栏:company-tab-wiring 24 处发送口、date-range-order 分母 21 实例/9 对、date-guard EXEMPT、ChunkRow 无侵权白名单四件(LlmClient 仍是唯一结论值来源)、SourceScan 52 支、G2 WIRED_PAGE_KEYS 第七支。判据修正:columnKey→getColumnKey 对齐代码库命名。
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/**
|
||||
* 外观专利无侵权数据页(v1.3 AC-5)的挂载契约 —— Pending Phase 3。
|
||||
* 外观专利无侵权数据页(v1.3 AC-5)的挂载契约 —— Phase 3 激活。
|
||||
*
|
||||
* 用户拍板(2026-11-10):展示形式参照「去重数据库」页(DedupeRegistryPage 形态:自绘
|
||||
* `<table>` 行列表 + `OldPagination.vue` 分页,**不做卡片宫格**);`companyScoped: true`
|
||||
@@ -7,29 +7,78 @@
|
||||
* `{items, total, page, pageSize}`。默认仅 super_admin 可见(菜单不预授权,判据在后端
|
||||
* AdminAppearancePatentCleanItemsControllerTest 的菜单迁移支,这里只管前端接线)。
|
||||
*
|
||||
* Phase 0 预置的判据(接缝名是判据的一部分,Phase 3 微调必须同步改本文件并登记蓝图 §5):
|
||||
* ① 页面组件落位 `src/pages/patent/AppearancePatentCleanItemsPage.vue`,且确实是
|
||||
* 自绘 table + OldPagination 的分页列表(不是卡片宫格);
|
||||
* ② routes.ts 注册 `patent-center/clean-items`(menuKey `admin_appearance_patent_clean_items`,
|
||||
* companyScoped: true),COMPANY_SCOPED_PAGES 同步登记(company-tab-wiring 护栏随注册自动覆盖);
|
||||
* ③ 挂载行为样本(激活时补齐):mock api 模块 → mount → 翻页/改每页条数、切公司 Tab 重取、
|
||||
* 任务号/ASIN/国家/起止时间筛选生效、空态与加载失败条。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/appearance-patent-clean-page.test.ts`
|
||||
*/
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { fileURLToPath, URL } from 'node:url'
|
||||
import { describe, expect, it } from 'vitest'
|
||||
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'
|
||||
|
||||
describe.skip('Pending Phase 3: AC-5 外观专利无侵权数据页(分页列表,参照去重数据库页)', () => {
|
||||
const cleanApi = vi.hoisted(() => ({
|
||||
fetchAppearancePatentCleanList: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/pages/patent/appearance-patent-clean-api.ts', () => cleanApi)
|
||||
|
||||
function row(id: number, over: Record<string, unknown> = {}) {
|
||||
return {
|
||||
id,
|
||||
resultId: 900 + id,
|
||||
taskId: 33179,
|
||||
userId: 7,
|
||||
companyId: 1,
|
||||
rowNo: id,
|
||||
asin: `B0AB8CDEF${id}`,
|
||||
country: 'DE',
|
||||
sku: `SKU-${id}`,
|
||||
brand: 'Anker',
|
||||
price: '29.99',
|
||||
title: `无侵权商品 ${id}`,
|
||||
imageUrl: '',
|
||||
itemUrl: '',
|
||||
conclusion: '无侵权',
|
||||
titleReason: '',
|
||||
appearanceReason: '',
|
||||
patentReason: '',
|
||||
sourceFilename: 'list.xlsx',
|
||||
syncedAt: '2026-11-10T10:30:00',
|
||||
...over,
|
||||
}
|
||||
}
|
||||
|
||||
let pinia: Pinia
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
pinia = createPinia()
|
||||
setActivePinia(pinia)
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
useCompanyTabStore().setActiveId(1)
|
||||
})
|
||||
|
||||
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('AC-5 外观专利无侵权数据页(分页列表,参照去重数据库页)', () => {
|
||||
it('页面组件落位且是自绘 table + OldPagination 的分页列表', () => {
|
||||
const src = readFileSync(fileURLToPath(new URL(`../../${PAGE_PATH}`, import.meta.url)), 'utf-8')
|
||||
// vitest 的 cwd = admin-frontend-vue 根(Phase 0 预置用 new URL 模板串,被 vite 静态分析成
|
||||
// undefined——skip 期间从未执行所以没暴露,激活时改走 cwd 解析)。
|
||||
const src = readFileSync(resolve(process.cwd(), PAGE_PATH), 'utf-8')
|
||||
expect(src).toContain('OldPagination')
|
||||
expect(src).toContain('<table')
|
||||
expect(src).not.toContain('el-card')
|
||||
@@ -46,16 +95,90 @@ describe.skip('Pending Phase 3: AC-5 外观专利无侵权数据页(分页列
|
||||
expect(scoped?.pageFiles).toContain(PAGE_PATH)
|
||||
})
|
||||
|
||||
it('挂载后走 snake 分页参数且切公司 Tab 重取(激活时用真组件挂载补齐)', async () => {
|
||||
// 页面组件 Phase 3 才落盘,vite 的 import-analysis 会在收集期解析动态导入 ⇒
|
||||
// 这里必须用运行期字符串 + @vite-ignore 推迟解析;skip 期间永不执行。
|
||||
const pageModule = '@/pages/patent/AppearancePatentCleanItemsPage.vue'
|
||||
// 激活时补齐:vi.mock('@/pages/patent/appearance-patent-clean-api.ts') →
|
||||
// const { default: Page } = await import(pageModule)
|
||||
// mount(Page, { global: { plugins: [createPinia()] } }) →
|
||||
// 断言首次请求 query 的 page/page_size(snake)与 {items,total,page,pageSize} 解包;
|
||||
// 改每页条数/翻页重发;companyTab.activeId 变化触发重取(护栏 company-tab-wiring 同口径)。
|
||||
const { default: Page } = await import(/* @vite-ignore */ pageModule)
|
||||
expect(Page).toBeTruthy()
|
||||
it('挂载后按首屏 snake 分页参数取数并解包 {items,total,page,pageSize}', async () => {
|
||||
const wrapper = await mountWith({ items: [row(1), row(2)], 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(2)
|
||||
expect(wrapper.text()).toContain('共 42 条')
|
||||
expect(wrapper.text()).toContain('B0AB8CDEF1')
|
||||
expect(wrapper.text()).toContain('无侵权')
|
||||
})
|
||||
|
||||
it('翻页与改每页条数都重发请求,改条数回第一页', async () => {
|
||||
const wrapper = await mountWith({ items: [row(11)], 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('任务号/ASIN/国家/起止时间筛选生效', async () => {
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
|
||||
const textInputs = wrapper.findAll('input[type="text"]')
|
||||
await textInputs[0].setValue('33179')
|
||||
await textInputs[1].setValue('B0AB8CDEF1')
|
||||
await wrapper.find('select').setValue('DE')
|
||||
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: '33179',
|
||||
asin: 'B0AB8CDEF1',
|
||||
country: 'DE',
|
||||
startDate: '2026-11-01',
|
||||
endDate: '2026-11-09',
|
||||
page: 1,
|
||||
})
|
||||
})
|
||||
|
||||
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
|
||||
const empty = await mountWith({ items: [], total: 0, page: 1, pageSize: 10 })
|
||||
const thCount = empty.findAll('thead th').length
|
||||
const emptyRow = empty.find('tbody tr')
|
||||
expect(emptyRow.text()).toContain('暂无无侵权数据')
|
||||
expect(Number(emptyRow.find('td').attributes('colspan'))).toBe(thCount, '空态 colspan 跟着列数走')
|
||||
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 () => {
|
||||
const wrapper = await mountWith({ items: [row(1)], total: 1, page: 1, pageSize: 10 })
|
||||
const textInputs = wrapper.findAll('input[type="text"]')
|
||||
await textInputs[0].setValue('33179')
|
||||
const callsAfterMount = cleanApi.fetchAppearancePatentCleanList.mock.calls.length
|
||||
|
||||
useCompanyTabStore().setActiveId(2)
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(cleanApi.fetchAppearancePatentCleanList.mock.calls.length).toBeGreaterThan(callsAfterMount)
|
||||
const last = cleanApi.fetchAppearancePatentCleanList.mock.calls.at(-1)![0]
|
||||
expect(last.companyId).toBe(2)
|
||||
expect(last.taskId).toBe('', '切公司必须清掉上一家填的任务号')
|
||||
expect(last.page).toBe(1)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user