feat(jd-database): 归属筛选查询——归属下拉追加「按分类查询」组(2026-11-22 用户口径「还要加个归属筛选查询」,11-17 三档快筛升级):四类档位互斥单值(全部/已分类/未分类+当前分组分类项 cat:<id>),分类档走既有 group_id 归属表 EXISTS 下推与侧栏点分类同一条谓词=后端零改动;选分类清店铺孤儿谓词(侧栏同形);下拉值=filter 派生态单真源(jd-product-filter 纯函数 node --test 直测);el-option-group 按 EP 按需注册规矩补样式导入(perf 护栏钉住)

This commit is contained in:
2026-11-22 02:53:21 +08:00
parent 19b32414ac
commit 64e426a941
5 changed files with 219 additions and 23 deletions
@@ -24,11 +24,14 @@ import { test } from 'node:test'
import assert from 'node:assert/strict'
import {
JD_OWNERSHIP_CATEGORY_PREFIX,
JD_PRODUCT_MAX_PAGE,
JD_PRODUCT_MAX_PAGE_SIZE,
JD_PRODUCT_PAGE_SIZE,
JD_PRODUCT_PAGE_SIZE_OPTIONS,
applyJdOwnershipSelection,
createJdProductFilterState,
jdOwnershipSelectValue,
toJdProductListParams,
} from '../src/pages/jd/jd-product-filter.ts'
import {
@@ -169,6 +172,59 @@ test('京东列表参数——classified 默认全部:已分类→true、未
}
})
/** 归属筛选查询(2026-11-22 用户口径「还要加个归属筛选查询」):归属下拉在状态三档之外
* 追加「按分类查询」组(cat:<id>),四类档位互斥单值。派生(jdOwnershipSelectValue)与
* 回写(applyJdOwnershipSelection)都在 filter 层纯函数里,本组用例钉三件事:
* ① 派生档位——分类档优先于状态档(groupId 非空必须卡 cat:<id>,否则同一颗下拉会同时
* 显示「已分类」和某分类、界面说谎);② 选分类档写 groupId、清状态档、清店铺孤儿谓词
* (店铺名单挂在分类下,换分类后旧店铺词会命中别组同名店——侧栏 onSelectGroup 同纪律);
* ③ 状态档清 groupId 不动店铺词(店铺不属分类维度,与既有三档行为一致);
* 脏值按「全部」兜底,不拿脏值冒充档位。 */
test('归属筛选查询——派生档位:分类档 cat:<id> 优先于状态档、默认卡全部', () => {
assert.equal(jdOwnershipSelectValue(createJdProductFilterState()), '',
'出厂态(groupId 空+classified 全部)下拉派生「全部」档')
assert.equal(
jdOwnershipSelectValue({ ...createJdProductFilterState(), classified: 'ungrouped' }),
'ungrouped',
'状态档原样派生',
)
const state = { ...createJdProductFilterState(), classified: 'classified', groupId: '7' }
assert.equal(jdOwnershipSelectValue(state), `${JD_OWNERSHIP_CATEGORY_PREFIX}7`,
'groupId 非空时分类档优先——下拉只显示分类,不显示状态档(否则界面说谎)')
})
test('归属筛选查询——选分类档写 groupId 清状态档清店铺词;状态档清 groupId 不动店铺词', () => {
// 选分类档:groupId 写入、状态档清空、店铺词清空(孤儿谓词纪律)
const catState = { ...createJdProductFilterState(), classified: 'classified', shopName: '绿屿街道店' }
applyJdOwnershipSelection(catState, `${JD_OWNERSHIP_CATEGORY_PREFIX}7`)
assert.equal(catState.groupId, '7', '选分类=按归属表查该分类(group_id EXISTS 下推)')
assert.equal(catState.classified, '', '分类档与状态档互斥——同一颗下拉选了分类就清状态档')
assert.equal(catState.shopName, '', '换分类必须清店铺词:旧店铺词是孤儿谓词(侧栏 onSelectGroup 同形)')
// 状态档:清 groupId、店铺词不动(店铺不属分类维度)
const stateState = { ...createJdProductFilterState(), groupId: '7', shopName: '绿屿街道店' }
applyJdOwnershipSelection(stateState, 'ungrouped')
assert.equal(stateState.groupId, '', '状态档与分类档互斥——选状态档清 groupId')
assert.equal(stateState.classified, 'ungrouped')
assert.equal(stateState.shopName, '绿屿街道店', '状态档不动店铺词(与既有三档行为一致)')
// 「全部」档:两字段都清
const allState = { ...createJdProductFilterState(), groupId: '7', classified: 'classified' }
applyJdOwnershipSelection(allState, '')
assert.equal(allState.groupId, '', '全部档清分类档')
assert.equal(allState.classified, '', '全部档清状态档')
// 脏值兜底:未知前缀/非数字 id 都按「全部」档,不拿脏值冒充档位
for (const dirty of ['cat:abc', 'cat:0', 'cat:-1', 'shop:9', 'nonsense']) {
const dirtyState = { ...createJdProductFilterState(), groupId: '7', classified: 'classified' }
applyJdOwnershipSelection(dirtyState, dirty)
assert.equal(dirtyState.groupId, '', `脏值 ${dirty} 按「全部」兜底清分类档`)
assert.equal(dirtyState.classified, '', `脏值 ${dirty} 按「全部」兜底清状态档`)
}
})
test('详情解析——attrGroups/images 结构化解析(snake 容错、缺 url 弃行)', () => {
const detail = parseJdProductDetail({
code: 0,
@@ -1,7 +1,7 @@
/**
* 京东数据库页(v1.6 装配 → v1.7 对齐原型《商品数据商城》)的挂载契约。
*
* 形态:顶部通栏面板(v1.7 搜索行:合并搜索框+「筛选」按钮+弹层锚点+分组+归属三档
* 形态:顶部通栏面板(v1.7 搜索行:合并搜索框+「筛选」按钮+弹层锚点+分组+归属筛选查询
* +工具栏:全选本页/取消本页/归入分类/取消归属/删除商品(N),2026-11-21 用户口径
* 「放到上面筛选框」红框整体上移,不再住主面板)+横排体 .jd-body(左侧栏
* JdCategorySidebar:商品目录=京麦授权类目树+计数徽标+树外兜底/店铺分类=当前分组
@@ -509,15 +509,16 @@ describe('分类管理入口(V204 独立页并入侧栏「分类管理」对
})
})
describe('归属三档快筛(三档,2026-11-21 用户口径默认改卡「全部」)', () => {
it('下拉三档且首屏就卡「全部」(首取不带 classified 键=后端跳过谓词查全量)', async () => {
describe('归属筛选查询(2026-11-22 用户口径「还要加个归属筛选查询」,11-17 三档快筛升级)', () => {
it('下拉四类档位互斥单值:状态三档+「按分类查询」组;首屏卡「全部」(首取不带 classified 键)', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
expect(optionLabels(wrapper, '筛选分类状态')).toEqual(['全部', '已分类', '未分类'])
// 空分组(beforeEach 默认):只有状态三档,分类组 v-if 不渲染。
expect(optionLabels(wrapper, '筛选归属')).toEqual(['全部', '已分类', '未分类'])
// 首屏可见文案(2026-11-22 用户口径「文字也要改一下 默认全部」):'' 值被 el-select
// 按空值处理(useSelect.hasModelValue 把 '' 算空)⇒ 界面显示的是 placeholder 灰字,
// 不是「全部」选项的 label——placeholder 必须与默认档同词「全部」;写「未分类」=
// 逻辑已查全量、界面却谎称卡在未分类(0a769fa8 后的漏改半边)。
const placeholderEl = selectByLabel(wrapper, '筛选分类状态').find('.el-select__placeholder')
const placeholderEl = selectByLabel(wrapper, '筛选归属').find('.el-select__placeholder')
expect(placeholderEl.exists(), '归属快筛缺 placeholder 节点').toBe(true)
expect(placeholderEl.text()).toBe('全部')
expect(jdApi.fetchJdProductList.mock.calls[0][0]).not.toHaveProperty('classified',
@@ -525,21 +526,68 @@ describe('归属三档快筛(三档,2026-11-21 用户口径默认改卡「
wrapper.unmount()
})
it('有分类时下拉追加「按分类查询」组(当前分组分类项,cat:<id> 值形状)', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
expect(optionLabels(wrapper, '筛选归属')).toEqual(['全部', '已分类', '未分类', '裙装', '裤装'],
'三档之后追加当前分组的分类项(el-option-group 不产生额外 ElOption label)')
wrapper.unmount()
})
it('选「未分类」下发 classified:false;选「已分类」下发 classified 态', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSelectOption(wrapper, '筛选分类状态', '未分类')
await pickSelectOption(wrapper, '筛选归属', '未分类')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('ungrouped',
'未分类是显式选档(api 序列化层再转 classified:false)')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1 }, '选中即查回第一页')
await pickSelectOption(wrapper, '筛选分类状态', '已分类')
await pickSelectOption(wrapper, '筛选归属', '已分类')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified')
wrapper.unmount()
})
it('「重置」(弹层里)不放开筛选,而是回默认「全部」档(首取不带 classified 键)', async () => {
it('按分类查询:选「裙装」→ groupId 下发(归属表 EXISTS 谓词)且不带 classified 键;侧栏选中态同步高亮+回显芯片', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSelectOption(wrapper, '筛选分类状态', '已分类')
await pickSelectOption(wrapper, '筛选归属', '裙装')
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last).toMatchObject({ groupId: '7', page: 1 }, '选分类=按 group_id 归属表查询(与侧栏点分类同一条谓词)')
expect(last.classified).toBe('', '分类档与状态档互斥——classified 回空(序列化层不下发,键缺省钉在 jd-product-group.test.ts)')
// 下拉是 filter 的视图:侧栏分类行按同一真源(selectedGroupIdNum)高亮。
await pickSideTab(wrapper, '店铺分类')
expect(sideRowBy(sideCustom(wrapper), '裙装').classes()).toContain('selected',
'下拉选分类=侧栏同真源,选中态必须同步高亮')
// 回显条出「分类:裙装」芯片(激活筛选)。
const chips = wrapper.get('.jd-filter-chips')
expect(chips.text()).toContain('分类:裙装')
wrapper.unmount()
})
it('下拉选分类清店铺孤儿谓词(店铺名单挂在分类下);状态档再选=分类档清空(互斥)', async () => {
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
// 先经侧栏点店铺(groupId=7 + shopName),再在下拉里换到另一个分类。
await pickSideTab(wrapper, '店铺分类')
await sideRowBy(sideCustom(wrapper), '绿屿街道店').trigger('click')
await flushPromises()
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', shopName: '绿屿街道店' })
await pickSelectOption(wrapper, '筛选归属', '裤装')
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(last).toMatchObject({ groupId: '8' }, '下拉换分类=切到新分类的归属查询')
expect(last.shopName).toBe('', '换分类必须清店铺词:旧店铺词是孤儿谓词(会命中别组同名店)')
// 分类档 → 状态档:groupId 清空(同一颗下拉四类档位互斥)。
await pickSelectOption(wrapper, '筛选归属', '已分类')
const after = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(after.groupId).toBe('', '选状态档清分类档')
expect(after.classified).toBe('classified')
wrapper.unmount()
})
it('「重置」(弹层里)不放开筛选,而是回默认「全部」档(首取不带 classified 键);选分类后重置连分类档一起清', async () => {
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSelectOption(wrapper, '筛选归属', '已分类')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified')
await openFilterPopover(wrapper)
@@ -548,6 +596,20 @@ describe('归属三档快筛(三档,2026-11-21 用户口径默认改卡「
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).not.toHaveProperty('classified',
'重置回出厂默认档(全部=不带 classified 参数),不是回未分类')
wrapper.unmount()
// 分类档同链:重置清 groupId(回全部档),下拉派生值随之回「全部」。
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
const wrapper2 = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
await pickSelectOption(wrapper2, '筛选归属', '裙装')
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].groupId).toBe('7')
await openFilterPopover(wrapper2)
await wrapper2.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
await flushPromises()
const reset = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
expect(reset.groupId).toBe('', '重置连分类档一起清——归属筛选查询回全部档')
expect(reset.classified).toBe('', '重置回状态档「全部」')
wrapper2.unmount()
})
})