feat(jd): 京东数据库行级编辑与删除+人工编辑锁/删除忽略保护(V199,2026-11-15 用户口径「每条数据可以编辑/删除」)——主链:PUT /api/admin/jd-products/{id} 主字段全量提交即置 manual_locked=1(采集回传 upsert/purge 对锁定行跳过,XML 侧 AND manual_locked=0 铁律 20);attrGroups 只重建 attr_json 的 tabs 段保留其它顶层键(铁律 30),原文形状不识别拒绝;skus 按 (productId,skuId) 改价改库存缺失拒绝;deleteImageIds 先删桶(共用对象保留)计数按表实数刷;删除链成功后写 biz_jd_product_ignore 防重爬复活(幂等吞 DuplicateKey);采集回传 filterProtectedRows 跳过锁定/忽略行不登记子表。后管:列表 11 列操作列(编辑/删除,@click.stop 防冒泡)+ JdProductEditDrawer(主字段/属性键值行删/SKU 价格库存/图片标删,保存提示人工维护后果),updateJdProduct 带 company_id;company-tab-wiring SEND_POINTS 26→32(补详情/删除/分组/类目/删分组/编辑六口一函数一钉对平)。判据:JdProductUpdateServiceTest 8 例+SyncServiceTest 保护闸/绊线+DeleteServiceTest 忽略登记+mount 操作列防冒泡/编辑抽屉;后端整量 5,607 例、后管 vue-tsc+1903+113 全绿。同窗交织笔(另一路会话类目下拉已收尾,文件级无法拆分一并入库):selectProductCategories/GET /categories/JdProductCategoryVo 类目筛选下拉+MigratedSqlEquivalenceTest/SqlLayeringConventionTest 适配。图片上传/替换链路记 BACKLOG B109-01;RawExceptionMessageSinkGuard/CatchSilenceRatchet 随笔抬格逐处记名
This commit is contained in:
@@ -133,10 +133,19 @@ const SEND_POINTS: ReadonlyArray<SendPoint> = [
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'fetchAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items 无侵权只读列表' },
|
||||
{ menuKey: 'admin_appearance_patent_clean_items', file: 'src/pages/patent/appearance-patent-clean-api.ts', fn: 'exportAppearancePatentCleanList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /appearance-patent-clean-items/export 导出(2026-11-11 客户需求「数据得导出来」,与列表共用同一过滤面)' },
|
||||
// ↓ 批次 8(2026-11-14 v1.4 京东数据库):京麦店铺商品采集落库的只读镜像,归属物化在行
|
||||
// company_id 列(V193,同外观专利 V189 形状)⇒ 后端正门 readCompanyIdOrOwn。列表与导出
|
||||
// 共用同一过滤面,塞键行与外观专利逐字同行,但分属不同文件 ⇒ (文件, 整行) 各成一组。
|
||||
// company_id 列(V193,同外观专利 V189 形状)⇒ 后端正门 readCompanyIdOrOwn。
|
||||
// 导出发送口已随 2026-11-15 客户口径「导出也不用」从前端下线(后端 /export 端点保留,
|
||||
// 前端发送口撤,重上时从 git 历史找回发送行再登记——同批次 7 主管两口的先例)。
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /jd-products 京东数据库只读列表' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'exportJdProductList', line: 'if (params.companyId != null) query.company_id = params.companyId', window: 500, title: 'GET /jd-products/export 京东数据库导出(与列表共用同一过滤面)' },
|
||||
// ↓ 同文件其余 6 个发送口(payload 形签名,塞键行与列表口不同形):详情/删除/分组列表/
|
||||
// 类目列表/删分组都在 2026-11-14 v1.4 就带 company_id 下传,编辑口(2026-11-15 行级编辑,
|
||||
// PUT 保存、V199 人工编辑锁)同形状——6 处塞键行逐字同行走一组,一函数一钉对平。
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductDetail', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-products/{id} 详情抽屉取数' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'deleteJdProducts', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'DELETE /jd-products/{id} 与 POST batch-delete 删除' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductGroups', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-product-groups 分组下拉/管理列表' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'fetchJdProductCategories', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'GET /jd-products/categories 类目下拉' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'deleteJdProductGroup', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'DELETE /jd-product-groups/{id} 删分组' },
|
||||
{ menuKey: 'admin_jd_database', file: 'src/pages/jd/jd-product-api.ts', fn: 'updateJdProduct', line: 'if (companyId != null) query.company_id = companyId', window: 500, title: 'PUT /jd-products/{id} 行级编辑保存(V199 人工编辑锁)' },
|
||||
]
|
||||
|
||||
/** 任务看板那 5 处(1b ④ 那条用例按文件筛它们,沿用旧名字不漂;表只有一份,不会漂出两个口径)。 */
|
||||
@@ -260,7 +269,7 @@ const COMPANY_ID_SOURCE_PINS: Readonly<Record<string, readonly CompanyIdPin[]>>
|
||||
admin_columns: pinsFor('admin_columns'),
|
||||
// 批次 7(v1.3 无侵权只读页):同样由 SEND_POINTS 现算——只有一个发送口(列表)。
|
||||
admin_appearance_patent_clean_items: pinsFor('admin_appearance_patent_clean_items'),
|
||||
// 批次 8(v1.4 京东数据库):列表 + 导出两口,由 SEND_POINTS 现算。
|
||||
// 批次 8(v1.4 京东数据库):列表一口(导出发送口 2026-11-15 随客户口径下线),由 SEND_POINTS 现算。
|
||||
admin_jd_database: pinsFor('admin_jd_database'),
|
||||
}
|
||||
|
||||
@@ -360,8 +369,8 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
||||
// ⚠ 分母是本轮实扫的表条数(批次 1 的 5 + 批次 2 的 7 + 批次 3 的 4 + 批次 4 的 1 + 批次 5 的 1 + 批次 6 的 3;
|
||||
// 批次 2 原 12 条里的品牌库 1 条 + 商品类目 4 条随 2026-10-06「这两页退回全平台共享」摘掉)。
|
||||
// 这条只防"整表被摘空/被改窄",逐处脱管由下面两条(对平闸门 + 窗口对平)负责。
|
||||
assert.ok(SEND_POINTS.length >= 27,
|
||||
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条 + 批次 7 v1.3 无侵权列表/导出 2 条 + 主管聚合 1 条 + 按主管删除 1 条 + 批次 8 v1.4 京东数据库列表/导出 2 条 = 28 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
|
||||
assert.ok(SEND_POINTS.length >= 32,
|
||||
`发送口表只剩 ${SEND_POINTS.length} 条(批次 1+2+3+4+5+6 实扫 21 条 + 批次 7 v1.3 无侵权列表/导出 2 条 + 主管聚合 1 条 + 按主管删除 1 条 + 批次 8 v1.4 京东数据库列表/详情/删除/分组/类目/删分组/编辑 7 条(导出口 2026-11-15 随客户口径下线)= 32 条)⇒ 有人把钉从表里摘了,取值口看守成空`)
|
||||
for (const p of SEND_POINTS) {
|
||||
const shape = pointShape(p)
|
||||
const compliant = pointCompliant(p)
|
||||
@@ -393,8 +402,8 @@ test('正向:声明 companyScoped 的页,其 api 文件必须真的带 company
|
||||
if (hit) hit.pinned += 1
|
||||
else grouped.set(key, { file: p.file, line: p.line, pinned: 1 })
|
||||
}
|
||||
assert.equal(grouped.size, 20,
|
||||
`发送口表按 (文件, 整行) 应聚成 20 组(28 处发送口,批次 7 的列表/导出/主管聚合/按主管删除与批次 8 的京东列表/导出逐字同行各走同一组),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
|
||||
assert.equal(grouped.size, 21,
|
||||
`发送口表按 (文件, 整行) 应聚成 21 组(32 处发送口,批次 7 的列表/导出/主管聚合/按主管删除、批次 8 的京东详情/删除/分组/类目/删分组/编辑逐字同行各走同一组;京东导出口 2026-11-15 随客户口径下线),现在却有 ${grouped.size} 组 —— 表被改形状了,对平判据失去分母`)
|
||||
for (const g of grouped.values()) {
|
||||
const actual = occurrences(stripComments(read(g.file)), g.line)
|
||||
assert.equal(g.pinned, actual,
|
||||
@@ -750,14 +759,14 @@ const WATCH_BODY_PINS: ReadonlyArray<{
|
||||
{ file: 'src/pages/patent/appearance-patent-clean-api.ts', shapes: [/company_id\s*=\s*params\.companyId\b/] },
|
||||
],
|
||||
},
|
||||
// ↓ 批次 8(2026-11-14 v1.4 京东数据库):店铺/商品编码/标题是按行集筛的自由文本,分组选项集是
|
||||
// 公司隔离的(/jd-product-groups 带 company_id)⇒ 上一家的筛选值与 groupId 在新一家的行集/选项集
|
||||
// 里不存在,切 tab 必清且选项重取;页码回 1 同外观专利页。
|
||||
// ↓ 批次 8(2026-11-14 v1.4 京东数据库):店铺/商品编码/标题是按行集筛的自由文本,分组/类目
|
||||
// 选项集是公司隔离的(/jd-product-groups、/jd-products/categories 带 company_id)⇒ 上一家的
|
||||
// 筛选值与 groupId/category 在新一家的行集/选项集里不存在,切 tab 必清且选项重取;页码回 1 同外观专利页。
|
||||
{
|
||||
file: 'src/pages/jd/JdDatabasePage.vue',
|
||||
token: "filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.saleStatus = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void load()",
|
||||
token: "filter.shopName = ''; filter.productCode = ''; filter.titleKeyword = ''; filter.category = ''; filter.groupId = ''; filter.syncedFrom = ''; filter.syncedTo = ''; page.value = 1; void loadGroupOptions(); void loadCategoryOptions(); void load()",
|
||||
why: '店铺/商品编码/标题是按行集筛的自由文本,上一家的值在新一家的行里不存在 ⇒ 切 tab 后首屏被筛成「暂无商品」,'
|
||||
+ '而输入框还显示着上一家填的值;分组选项集是公司隔离的,上一家选的 groupId 在新一家的选项里不存在,'
|
||||
+ '而输入框还显示着上一家填的值;分组/类目选项集是公司隔离的,上一家选的 groupId/category 在新一家的选项里不存在,'
|
||||
+ '同罪必清且选项重取;页码回 1 是因为新一家的行数更少,末尾的 void load() 才让切 tab 真的换数据',
|
||||
premise: [
|
||||
{ file: 'src/pages/jd/jd-product-api.ts', shapes: [/company_id\s*=\s*params\.companyId\b/] },
|
||||
|
||||
@@ -60,3 +60,16 @@ test('缺 skuId 的行弃掉、空 skus 回空数组(旧数据不渲染空表
|
||||
assert.equal(parseJdProductDetail({ id: 3 }).skus.length, 0)
|
||||
assert.equal(jdSkuSummary([]), '')
|
||||
})
|
||||
|
||||
/** 类目筛选(2026-11-15):京麦末级类目等值过滤,空串不下发、非空透传 category。 */
|
||||
test('类目筛选参数序列化:空串不下发、非空下发 category(等值过滤)', async () => {
|
||||
const { createJdProductFilterState, toJdProductListParams, jdProductFilterActive } =
|
||||
await import('../src/pages/jd/jd-product-filter.ts')
|
||||
const empty = createJdProductFilterState()
|
||||
assert.equal('category' in toJdProductListParams(empty, 1, 20), false, '全部类目不下发 category')
|
||||
assert.equal(jdProductFilterActive(empty), false)
|
||||
|
||||
const filtered = { ...empty, category: ' 服饰内衣 ' }
|
||||
assert.equal(toJdProductListParams(filtered, 1, 20).category, '服饰内衣', '去空白透传(等值过滤)')
|
||||
assert.equal(jdProductFilterActive(filtered), true, '选中类目算激活筛选')
|
||||
})
|
||||
|
||||
@@ -6,8 +6,9 @@
|
||||
*
|
||||
* 覆盖:
|
||||
* 1. **snake 参数形状**:toJdProductListParams 产出 `page`/`page_size`(默认 20、上限 100)、
|
||||
* `shop_name`/`product_code`/`title_keyword`/`sale_status`/`group_id`/`synced_from`/`synced_to`
|
||||
* `shop_name`/`product_code`/`title_keyword`/`group_id`/`synced_from`/`synced_to`
|
||||
* (ISO yyyy-MM-dd;空白不下发;groupId 空串→不带、有值→snake group_id);分页钳制(铁律 15)。
|
||||
* 商品状态筛选与导出参数口已随 2026-11-15 客户口径下线,不再出现在参数面。
|
||||
* 2. **详情解析**:parseJdProductDetail 解析 attrGroups/images(camel 为正 snake 容错、缺 url 弃行),
|
||||
* attrGroups 解析不出时 attrJsonRaw 原文兜底;列表行解析缺 id 弃行。
|
||||
*
|
||||
@@ -19,7 +20,6 @@ import assert from 'node:assert/strict'
|
||||
import {
|
||||
JD_PRODUCT_MAX_PAGE,
|
||||
createJdProductFilterState,
|
||||
toJdProductExportParams,
|
||||
toJdProductListParams,
|
||||
} from '../src/pages/jd/jd-product-filter.ts'
|
||||
import {
|
||||
@@ -35,7 +35,6 @@ test('京东列表参数——snake 形状:groupId 空→不带、有值→gro
|
||||
shopName: ' 旗舰自营店 ',
|
||||
productCode: ' JD-10086 ',
|
||||
titleKeyword: ' 保温杯 ',
|
||||
saleStatus: '上架中',
|
||||
groupId: ' 7 ',
|
||||
syncedFrom: '2026-11-01',
|
||||
syncedTo: '2026-11-09',
|
||||
@@ -49,7 +48,6 @@ test('京东列表参数——snake 形状:groupId 空→不带、有值→gro
|
||||
shop_name: '旗舰自营店',
|
||||
product_code: 'JD-10086',
|
||||
title_keyword: '保温杯',
|
||||
sale_status: '上架中',
|
||||
group_id: 7,
|
||||
synced_from: '2026-11-01',
|
||||
synced_to: '2026-11-09',
|
||||
@@ -60,21 +58,12 @@ test('京东列表参数——snake 形状:groupId 空→不带、有值→gro
|
||||
assert.deepEqual(blank, { page: 1, page_size: 20 })
|
||||
assert.equal('group_id' in blank, false, 'groupId 空串不带 group_id')
|
||||
const dirty = toJdProductListParams(
|
||||
{ shopName: ' ', productCode: '', titleKeyword: '', saleStatus: '', groupId: 'abc', syncedFrom: '2026/11/01', syncedTo: 'not-a-date' },
|
||||
{ shopName: ' ', productCode: '', titleKeyword: '', groupId: 'abc', syncedFrom: '2026/11/01', syncedTo: 'not-a-date' },
|
||||
1,
|
||||
20,
|
||||
)
|
||||
assert.deepEqual(dirty, { page: 1, page_size: 20 }, '脏值不下发')
|
||||
|
||||
// 导出与列表同一过滤面单出口(无分页)。
|
||||
const state = { shopName: '旗舰自营店', productCode: '', titleKeyword: '', saleStatus: '已下架', groupId: '7', syncedFrom: '2026-11-01', syncedTo: '' }
|
||||
const list = toJdProductListParams(state, 3, 20)
|
||||
const exp = toJdProductExportParams(state)
|
||||
for (const key of Object.keys(exp) as Array<keyof typeof exp>) {
|
||||
assert.equal((list as Record<string, unknown>)[key], exp[key], `导出与列表的 ${key} 必须同源`)
|
||||
}
|
||||
assert.equal('page' in exp, false, '导出参数无分页')
|
||||
assert.deepEqual(exp, { shop_name: '旗舰自营店', sale_status: '已下架', group_id: 7, synced_from: '2026-11-01' })
|
||||
assert.equal('sale_status' in full, false, '商品状态筛选已下线,参数面不再出现 sale_status')
|
||||
})
|
||||
|
||||
test('京东列表参数——page 钳制防 (page-1)*page_size 溢出(铁律 15)', () => {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
/**
|
||||
* 京东数据库页(v1.4 Phase 5)的挂载契约。
|
||||
*
|
||||
* 形态:panel-box + 筛选行(店铺/商品编码/标题关键字/商品状态/分组/同步起止 date 对)+
|
||||
* 查询/导出/重置/管理分组 + 自绘明细表(点行开详情抽屉)+ OldPagination;
|
||||
* 形态:panel-box + 筛选行(店铺/商品编码/标题关键字/分组/同步起止 date 对)+
|
||||
* 查询/重置/管理分组 + 自绘明细表(点行开详情抽屉)+ OldPagination;
|
||||
* 公司 tab 切换=清筛选重取(company-tab-wiring 同口径)。
|
||||
* 商品状态筛选/列与导出按钮已随 2026-11-15 客户口径从前端下线(后端端点保留)。
|
||||
* 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。
|
||||
*
|
||||
* 跑法:`npx vitest run tests/mount/jd-database-page.mount.test.ts`
|
||||
@@ -22,12 +23,13 @@ const jdApi = vi.hoisted(() => ({
|
||||
JD_PRODUCT_GROUP_ENDPOINT: '/api/admin/jd-product-groups',
|
||||
fetchJdProductList: vi.fn(),
|
||||
fetchJdProductDetail: vi.fn(),
|
||||
exportJdProductList: vi.fn(),
|
||||
deleteJdProducts: vi.fn(),
|
||||
fetchJdProductGroups: vi.fn(),
|
||||
fetchJdProductCategories: vi.fn(),
|
||||
createJdProductGroup: vi.fn(),
|
||||
updateJdProductGroup: vi.fn(),
|
||||
deleteJdProductGroup: vi.fn(),
|
||||
updateJdProduct: vi.fn(),
|
||||
}))
|
||||
|
||||
const confirmMock = vi.hoisted(() => vi.fn())
|
||||
@@ -75,6 +77,7 @@ beforeEach(() => {
|
||||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||||
useCompanyTabStore().setActiveId(1)
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
||||
confirmMock.mockResolvedValue(true)
|
||||
})
|
||||
|
||||
@@ -98,34 +101,97 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(wrapper.find('.jd-summary').text()).toContain('共 42 条京东商品')
|
||||
})
|
||||
|
||||
it('行内容按京麦商品列表样式(2026-11-15 用户口径):勾选/店铺/分组/商品信息(图+标题+编码+货号+SKU/信息分)/品牌/价格/库存/状态/同步(9 列),类目等其余收进详情抽屉', async () => {
|
||||
it('行列字段与顺序对齐京麦(2026-11-15 用户口径):勾选/店铺/分组/商品信息(图+标题+编码+货号+品牌·类目+SKU/信息分)/总库存/价格/上架时间·商品状态/创建/修改/同步/操作(11 列)', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const cells = wrapper.findAll('tbody tr')[0].findAll('td')
|
||||
expect(cells).toHaveLength(9)
|
||||
expect(cells).toHaveLength(11)
|
||||
expect(cells[0].find('input[type="checkbox"]').exists()).toBe(true, '第 1 列是勾选框')
|
||||
expect(cells[1].text()).toBe('旗舰自营店', '第 2 列=店铺(用户口径前置为第 1 数据列)')
|
||||
expect(cells[2].text()).toBe('甲组', '第 3 列=分组')
|
||||
// 商品信息列=京麦同款合并布局:主图+信息分+标题+商品编码+货号+SKU 标签。
|
||||
expect(cells[1].text()).toBe('旗舰自营店', '第 2 列=店铺(admin 专属,置前)')
|
||||
expect(cells[2].text()).toBe('甲组', '第 3 列=分组(admin 专属)')
|
||||
// 商品信息列=京麦同款合并布局:主图+信息分+标题+商品编码+货号+品牌·类目行+SKU 标签。
|
||||
const info = cells[3]
|
||||
expect(info.find('.jd-thumb').exists()).toBe(true, '商品信息列含主图')
|
||||
expect(info.text()).toContain('304不锈钢保温杯')
|
||||
expect(info.text()).toContain('JD-1001', '商品编码并入商品信息列')
|
||||
expect(info.text()).toContain('ITEM-1', '货号并入商品信息列')
|
||||
expect(info.text()).toContain('锅宝', '品牌并入商品信息列(京麦品牌·类目行)')
|
||||
expect(info.text()).toContain('家居 > 厨具 > 保温杯', '类目随品牌·类目行上列表(京麦同款)')
|
||||
expect(info.text()).toContain('12个SKU')
|
||||
expect(info.text()).toContain('信息分 81')
|
||||
expect(cells[4].text()).toBe('锅宝')
|
||||
expect(cells[5].text()).toBe('12.90 ~ 15.90', '价格区间=min ~ max')
|
||||
expect(cells[6].text()).toBe('500', '总库存列')
|
||||
expect(cells[7].text()).toBe('上架中')
|
||||
expect(cells[8].text()).not.toBe('-', '同步时间格式化展示')
|
||||
// 类目/上架时间/京东创建/修改时间仍收进详情抽屉(信息分/SKU 数 2026-11-15 起随京麦样式回列表)。
|
||||
expect(cells[4].text()).toBe('500', '第 4 数据列=总库存(京麦第 2 列)')
|
||||
expect(cells[5].text()).toBe('12.90 ~ 15.90', '第 5 数据列=价格(京麦第 3 列)')
|
||||
expect(cells[6].text()).toContain('上架中', '第 6 数据列=上架时间/商品状态(京麦合并列)')
|
||||
expect(cells[6].find('.jd-sale-dot').exists()).toBe(true, '状态带京麦同款圆点')
|
||||
expect(cells[7].text()).not.toBe('-', '第 7 数据列=创建时间')
|
||||
expect(cells[8].text()).not.toBe('-', '第 8 数据列=修改时间')
|
||||
expect(cells[9].text()).not.toBe('-', '第 9 数据列=同步时间(admin 专属,置末)')
|
||||
expect(cells[10].text()).toContain('编辑', '第 10 数据列=操作(编辑/删除)')
|
||||
// 表头字段名与顺序与京麦一致;品牌/类目不再是独立列(收进商品信息)。
|
||||
const headerText = wrapper.find('thead').text()
|
||||
for (const gone of ['类目', '上架时间', '创建时间', '修改时间']) {
|
||||
expect(headerText).not.toContain(gone, `${gone}列已收进详情抽屉,不再上列表`)
|
||||
for (const gone of ['品牌', '类目']) {
|
||||
expect(headerText).not.toContain(gone, `${gone}不再是独立列(京麦把它们收进商品信息)`)
|
||||
}
|
||||
for (const head of ['商品信息', '总库存', '价格', '上架时间 / 商品状态', '创建时间', '修改时间', '同步时间']) {
|
||||
expect(headerText).toContain(head, `表头必须有「${head}」(京麦字段名)`)
|
||||
}
|
||||
expect(wrapper.find('.jd-thumb').exists()).toBe(true, '商品信息列渲染缩略图')
|
||||
})
|
||||
|
||||
it('操作列删除按钮防冒泡且走确认弹窗:确认后调 deleteJdProducts,取消不动(2026-11-15 行级删除)', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
// beforeEach 默认 confirm=true;本例先翻回 false 验「取消不动」。
|
||||
confirmMock.mockResolvedValue(false)
|
||||
const opsCell = wrapper.findAll('tbody tr')[0].findAll('td')[10]
|
||||
await opsCell.findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
// 防冒泡:点删除不得顺手打开详情抽屉(抽屉的可视判据=.drawer 出现)。
|
||||
expect(wrapper.find('.drawer').exists()).toBe(false, '删除按钮 @click.stop,点它不开详情抽屉')
|
||||
expect(confirmMock).toHaveBeenCalledTimes(1, '删除必须过二次确认')
|
||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(0, '确认弹窗取消时不发删除请求')
|
||||
// 确认后:deleteJdProducts 按公司 tab 下传(id, companyId)。
|
||||
confirmMock.mockResolvedValue(true)
|
||||
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
||||
await wrapper.findAll('tbody tr')[0].findAll('td')[10].findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1], 1)
|
||||
})
|
||||
|
||||
it('操作列编辑按钮防冒泡且打开编辑抽屉(抽屉自取详情回填,2026-11-15 行级编辑)', async () => {
|
||||
// fetchJdProductDetail 的返回已由 parseJdProductDetail 归一成 {item, attrGroups, images, skus, attrJsonRaw}。
|
||||
jdApi.fetchJdProductDetail.mockResolvedValue({
|
||||
item: {
|
||||
id: 1,
|
||||
title: '304不锈钢保温杯大容量便携',
|
||||
brand: '锅宝',
|
||||
categoryPath: '家居 > 厨具 > 保温杯',
|
||||
itemNum: 'ITEM-1',
|
||||
priceMin: '12.90',
|
||||
priceMax: '15.90',
|
||||
stockTotal: 500,
|
||||
saleStatus: '上架中',
|
||||
groupId: 7,
|
||||
groupName: '甲组',
|
||||
productCode: 'JD-1001',
|
||||
shopName: '旗舰自营店',
|
||||
},
|
||||
attrGroups: [],
|
||||
images: [],
|
||||
skus: [],
|
||||
attrJsonRaw: '',
|
||||
})
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const opsCell = wrapper.findAll('tbody tr')[0].findAll('td')[10]
|
||||
await opsCell.findAll('button').find((b) => b.text() === '编辑')!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
expect(wrapper.find('.drawer').exists()).toBe(true, '编辑抽屉打开')
|
||||
expect(wrapper.text()).toContain('编辑商品', '抽屉标题点商品')
|
||||
// 抽屉按 (id, companyId) 自取详情回填。
|
||||
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1, 1)
|
||||
// 编辑抽屉的保存提示文案点名人工编辑锁后果(用户保存前看得见「采集不再覆盖」)。
|
||||
expect(wrapper.text()).toContain('人工维护', '保存后果提示常驻(V199 人工编辑锁)')
|
||||
})
|
||||
|
||||
it('商品信息列:主图无 URL 显示「无图」占位、healthScore 为空不出信息分行、skuCount 为空不出 SKU 标签', async () => {
|
||||
const wrapper = await mountWith({
|
||||
items: [item(1), item(2, { mainImageUrl: '', healthScore: null, skuCount: null })],
|
||||
@@ -153,16 +219,15 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(wrapper.findAll('tbody tr')[0].findAll('td')[2].text()).toBe('未分组')
|
||||
})
|
||||
|
||||
it('筛选生效:店铺/编码/关键字/状态/分组/起止日期,查询回第一页重发', async () => {
|
||||
it('筛选生效:店铺/编码/关键字/分组/起止日期,查询回第一页重发', async () => {
|
||||
jdApi.fetchJdProductGroups.mockResolvedValue([{ id: 7, name: '甲组', sortOrder: 0, productCount: 3 }])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||||
expect(textInputs).toHaveLength(4, '店铺+商品编码+标题关键字+商品状态四个文本筛选框')
|
||||
expect(textInputs).toHaveLength(3, '店铺+商品编码+标题关键字三个文本筛选框(商品状态已下线)')
|
||||
await textInputs[0].setValue('旗舰自营店')
|
||||
await textInputs[1].setValue('JD-1001')
|
||||
await textInputs[2].setValue('保温杯')
|
||||
await textInputs[3].setValue('上架中')
|
||||
await wrapper.find('select').setValue('7')
|
||||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||||
await dateInputs[0].setValue('2026-11-01')
|
||||
@@ -175,13 +240,13 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
shopName: '旗舰自营店',
|
||||
productCode: 'JD-1001',
|
||||
titleKeyword: '保温杯',
|
||||
saleStatus: '上架中',
|
||||
groupId: '7',
|
||||
syncedFrom: '2026-11-01',
|
||||
syncedTo: '2026-11-09',
|
||||
page: 1,
|
||||
companyId: 1,
|
||||
})
|
||||
expect(last).not.toHaveProperty('saleStatus', '商品状态筛选已下线,入参不再带 saleStatus')
|
||||
})
|
||||
|
||||
it('分组下拉选中即查', async () => {
|
||||
@@ -204,6 +269,29 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
|
||||
})
|
||||
|
||||
it('类目下拉:选项来自 GET /categories(带商品数),选中即查回第一页', async () => {
|
||||
jdApi.fetchJdProductCategories.mockResolvedValue([
|
||||
{ name: '服饰内衣', productCount: 120 },
|
||||
{ name: '运动户外', productCount: 8 },
|
||||
])
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith(1)
|
||||
|
||||
// 第 1 个 select = 分组(既有契约不动),类目下拉紧随其后
|
||||
const selects = wrapper.findAll('.jd-filter-row select')
|
||||
expect(selects).toHaveLength(2)
|
||||
const categorySelect = selects[1]
|
||||
const optionTexts = categorySelect.findAll('option').map((o) => o.text())
|
||||
expect(optionTexts[0]).toBe('全部类目')
|
||||
expect(optionTexts).toContain('服饰内衣(120)')
|
||||
|
||||
const callsBeforeSelect = jdApi.fetchJdProductList.mock.calls.length
|
||||
await categorySelect.setValue('运动户外')
|
||||
await flushPromises()
|
||||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBeforeSelect + 1, '选中类目必须立刻重查')
|
||||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '运动户外', page: 1 })
|
||||
})
|
||||
|
||||
it('重置把筛选面回空并回第一页重取', async () => {
|
||||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 20 })
|
||||
const textInputs = wrapper.findAll('.form-group input[type="text"]')
|
||||
@@ -235,48 +323,11 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(last.page).toBe(1, '改每页条数后回第一页')
|
||||
})
|
||||
|
||||
it('导出=当前过滤面全量(含公司 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(() => {})
|
||||
jdApi.exportJdProductList.mockImplementation(() =>
|
||||
Promise.resolve({ blob: new Blob(['xlsx']), filename: '京东数据库-20261114090000.xlsx' }),
|
||||
)
|
||||
|
||||
try {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
const btn = wrapper.findAll('button').find((b) => b.text() === '导出')
|
||||
expect(btn, '筛选行必须有「导出」按钮').toBeTruthy()
|
||||
await btn!.trigger('click')
|
||||
await flushPromises()
|
||||
await flushPromises()
|
||||
|
||||
expect(jdApi.exportJdProductList).toHaveBeenCalledTimes(1)
|
||||
const call = jdApi.exportJdProductList.mock.calls[0][0]
|
||||
expect(call).toMatchObject({ shopName: '', groupId: '', companyId: 1 })
|
||||
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 () => {
|
||||
jdApi.exportJdProductList.mockImplementation(() => Promise.reject(new Error('京东商品共 80001 行,超过导出上限 50000 行,请缩小筛选范围后重试')))
|
||||
it('导出按钮已下线:筛选行不再出现「导出」(2026-11-15 客户口径「导出也不用」)', async () => {
|
||||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||
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)
|
||||
expect(btn, '导出按钮必须已从前端移除').toBeUndefined()
|
||||
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1, '下线导出不影响列表首屏')
|
||||
})
|
||||
|
||||
it('点行打开详情抽屉:按 (id, companyId) 取详情,attrGroups 分块渲染', async () => {
|
||||
@@ -460,6 +511,7 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
||||
expect(last.shopName).toBe('', '切公司必须清掉上一家的店铺名')
|
||||
expect(last.titleKeyword).toBe('', '切公司必须清掉上一家的标题关键字')
|
||||
expect(last.groupId).toBe('', '切公司必须清掉上一家选的分组')
|
||||
expect(last).not.toHaveProperty('category', '切公司必须清掉上一家选的类目')
|
||||
expect(last.page).toBe(1)
|
||||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(2)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user