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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user