feat(jd): 采集分类换 el-select 下拉多选(2026-11-17 客户口径「不要全展示出来,弄个下拉式多选」)——9 行复选列表收进 collapse-tags 下拉(+N 徽标),选择模型改 id 数组、双键按快照原序同源反查(点选先后不进请求体);暗色主题套壳。判据:纯测试钉 el-select multiple 在册+shop-cat-list 旧形状反向钉;挂载两格改用真实 ElementPlus 经 update:modelValue 模拟点选(轮询格保持轻量桩——真件在 fake timers 下会打断任务面板轮询链,实测教训写进注释)。node --test 9 例+vitest 挂载 10 例+vue-tsc rc=0
This commit is contained in:
@@ -71,6 +71,10 @@ test('分类多选来自京麦店内分类快照,平台分组从本页下线',
|
||||
'JdCollectTab.vue 必须消费京麦店内分类快照(jd-shop-category.ts)作采集分类多选选项')
|
||||
assert.ok(page.includes('采集分类(可选,多选)'),
|
||||
'JdCollectTab.vue 必须以「采集分类(可选,多选)」展示分类块')
|
||||
assert.ok(page.includes('<el-select') && page.includes('multiple'),
|
||||
'采集分类必须是下拉式多选(el-select multiple,2026-11-17 客户口径「不要全展示出来,弄个下拉式的多选」)')
|
||||
assert.ok(!page.includes('shop-cat-list'),
|
||||
'JdCollectTab.vue 不得再回到逐条复选框列表(旧形状 2026-11-17 下线)')
|
||||
assert.ok(!page.includes('JdCategoryCascader'),
|
||||
'JdCollectTab.vue 不得再引用类目级联(2026-11-16 客户口径「类目不需要」)')
|
||||
assert.ok(!page.includes('fetchJdCollectGroups'),
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import ElementPlus, { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
import JdCollectTab from '@/pages/jd/JdCollectTab.vue'
|
||||
|
||||
@@ -101,13 +102,33 @@ function batchOf(item: Record<string, unknown>) {
|
||||
|
||||
let wrapper: VueWrapper | null = null
|
||||
|
||||
async function mountPage() {
|
||||
/** el-select/el-option 轻量桩:轮询组用例不带真实 ElementPlus——真件在 fake timers 下
|
||||
* 的内部计时/Popper 会被 `advanceTimersByTimeAsync(60s)` 一并点燃、打断任务面板轮询链
|
||||
* (2026-11-17 改版实测 SUCCESS/FAILED 两格因此转红)。下拉形状由分类两格的真实组件
|
||||
* 用例兜底,这里只保证模板可解析、v-model 透传、选项渲染计数。 */
|
||||
const ElSelectStub = {
|
||||
name: 'ElSelect',
|
||||
props: ['modelValue'],
|
||||
emits: ['update:modelValue'],
|
||||
template: '<div class="shop-cat-select"><slot /></div>',
|
||||
}
|
||||
const ElOptionStub = {
|
||||
name: 'ElOption',
|
||||
props: ['label', 'value'],
|
||||
template: '<div class="shop-cat-option">{{ label }}</div>',
|
||||
}
|
||||
|
||||
async function mountPage(realSelect = false) {
|
||||
wrapper = mount(JdCollectTab, {
|
||||
global: {
|
||||
// 分类两格用真实 ElementPlus 组件树(经 update:modelValue 模拟点选,
|
||||
// 弹层 teleport 到 body,不依赖开合动画);其余格用桩。
|
||||
...(realSelect ? { plugins: [ElementPlus] } : {}),
|
||||
stubs: {
|
||||
NotificationBell: true,
|
||||
RouterLink: { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
'router-link': { template: '<a class="router-link-stub"><slot /></a>' },
|
||||
...(realSelect ? {} : { 'el-select': ElSelectStub, 'el-option': ElOptionStub }),
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -284,52 +305,52 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
expect(w.find('.feedback.error').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('勾选分类后建单:店内分类双键随建单请求体与推送载荷同链下发', async () => {
|
||||
// 2026-11-16 客户口径「类目不需要只要分类」「选京麦的内部分类去采集」+「做成多选的」:
|
||||
// 选项集=京麦「店内分类」快照(jd-shop-category.ts,getShopCategoryList 取证 9 个),
|
||||
// checkbox 多选;建单请求体与推送载荷带 label+id 双键(行级填充形状未取证,客户端
|
||||
// 任一键命中即命中)——mock 选中项用快照真实行(拉丁舞服/1024347572),贴合下发形状。
|
||||
const w = await mountPage()
|
||||
it('下拉选分类后建单:店内分类双键随建单请求体与推送载荷同链下发', async () => {
|
||||
// 2026-11-16 客户口径「类目不需要只要分类」「选京麦的内部分类去采集」;
|
||||
// 2026-11-17 客户口径「不要全展示出来,弄个下拉式多选」:checkbox 列表换 el-select
|
||||
// 多选(collapse-tags)。选项集=京麦「店内分类」快照(jd-shop-category.ts,取证 9 个),
|
||||
// 选择模型是 id 数组;建单请求体与推送载荷带 label+id 双键、按快照原序反查(行级填充
|
||||
// 形状未取证,客户端任一键命中即命中)——选中项用快照真实行,贴合下发形状。
|
||||
const w = await mountPage(true)
|
||||
|
||||
const rows = w.findAll('.shop-cat-item')
|
||||
expect(rows.length).toBeGreaterThan(0, '分类多选列表必须渲染快照选项')
|
||||
const latinRow = rows.find((row) => row.text().includes('拉丁舞服'))
|
||||
expect(latinRow, '快照里必须有「拉丁舞服」').toBeTruthy()
|
||||
await latinRow!.find('input').setValue(true)
|
||||
const uniformRow = rows.find((row) => row.text().includes('工作制服'))
|
||||
await uniformRow!.find('input').setValue(true)
|
||||
const select = w.findComponent(ElSelect)
|
||||
expect(select.exists(), '采集分类必须是下拉多选(el-select),不再是逐条复选框').toBe(true)
|
||||
await select.vm.$emit('update:modelValue', ['1024347572', '1024347567'])
|
||||
await flushPromises()
|
||||
|
||||
await startCollect(w)
|
||||
|
||||
// 双键顺序恒等于快照序(工作制服在前),与点选先后无关——同源反查,不随 UI 顺序漂。
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, [],
|
||||
['拉丁舞服', '工作制服'], ['1024347572', '1024347567'])
|
||||
['工作制服', '拉丁舞服'], ['1024347567', '1024347572'])
|
||||
const payload = api.enqueue.mock.calls[0][0]
|
||||
expect(payload.data).toEqual({
|
||||
taskId: 88,
|
||||
shopName: '京麦后台',
|
||||
listTabs: ['ONSALE', 'OFFSALE'],
|
||||
maxProducts: 0,
|
||||
shopCategoryNames: ['拉丁舞服', '工作制服'],
|
||||
shopCategoryIds: ['1024347572', '1024347567'],
|
||||
shopCategoryNames: ['工作制服', '拉丁舞服'],
|
||||
shopCategoryIds: ['1024347567', '1024347572'],
|
||||
})
|
||||
})
|
||||
|
||||
it('采集分类块:快照选项全量渲染并可取消勾选(清空恢复全店采集)', async () => {
|
||||
const w = await mountPage()
|
||||
it('采集分类块:下拉渲染快照全量选项并可清空(恢复全店采集)', async () => {
|
||||
const w = await mountPage(true)
|
||||
|
||||
const block = w.findAll('.category-block').find((el) => el.text().includes('采集分类'))
|
||||
expect(block, '必须有「采集分类(可选,多选)」块').toBeTruthy()
|
||||
expect(block!.text()).toContain('采集分类(可选,多选)')
|
||||
// 快照 9 项全渲染(客户端「能看见管理员/商家建的分类」口径落点就在这)
|
||||
expect(block!.findAll('.shop-cat-item').length).toBe(9)
|
||||
// 快照 9 项全进下拉选项(客户端「能看见管理员/商家建的分类」口径落点就在这;
|
||||
// 弹层 teleport 到 body,选项组件仍挂在页面组件树里,按组件计数不按 DOM)
|
||||
expect(w.findAllComponents(ElOption).length).toBe(9)
|
||||
expect(block!.find('.shop-cat-select').exists(), '分类块必须是 el-select 下拉').toBe(true)
|
||||
expect(block!.text()).toContain('不选=全店采集')
|
||||
|
||||
const first = block!.findAll('.shop-cat-item')[0]
|
||||
await first.find('input').setValue(true)
|
||||
const select = block!.findComponent(ElSelect)
|
||||
await select.vm.$emit('update:modelValue', ['1024347567'])
|
||||
await flushPromises()
|
||||
expect(block!.text()).toContain('只采选中 1 个分类的商品')
|
||||
expect(block!.find('.shop-cat-clear').exists()).toBe(true, '选中后出「清空」')
|
||||
expect(block!.find('.shop-cat-clear').exists(), '选中后出「清空」').toBe(true)
|
||||
await block!.find('.shop-cat-clear').trigger('click')
|
||||
await flushPromises()
|
||||
expect(block!.text()).toContain('不选=全店采集')
|
||||
|
||||
Reference in New Issue
Block a user