1571 lines
90 KiB
TypeScript
1571 lines
90 KiB
TypeScript
/**
|
||
* 京东数据库页(v1.6 装配 → v1.7 对齐原型《商品数据商城》)的挂载契约。
|
||
*
|
||
* 形态:顶部通栏面板(v1.7 搜索行:合并搜索框+「筛选」按钮+弹层锚点+分组+归属三档
|
||
* +工具栏:全选本页/取消本页/归入分类/取消归属/删除商品(N),2026-11-21 用户口径
|
||
* 「放到上面筛选框」红框整体上移,不再住主面板)+横排体 .jd-body(左侧栏
|
||
* JdCategorySidebar:商品目录=京麦授权类目树+计数徽标+树外兜底/店铺分类=当前分组
|
||
* 分类平铺+新建+分类管理入口+主面板:回显条+卡片网格 JdProductCard+自绘分页条
|
||
* .jd-page-bar+底部已选条)+居中详情弹窗(编辑/删除入口收进弹窗顶部)。
|
||
* v1.7 五件:合并搜索(旧编码/标题两框退役)、筛选弹层(价格区间+同步起止+重置/应用)、
|
||
* 筛选回显条(芯片+共 N 条+清除筛选保留分组)、自绘顶部分页条(OldPagination 从本页
|
||
* 撤下,组件本体他页在用)、底部已选条(常驻悬浮)。
|
||
* 旧表格/类目级联面板/详情抽屉三件随 v1.6 Phase 5 退役(反向钉在本文件顶部用例)。
|
||
* 批量归类对话框与分类管理对话框是 v1.6 之前的既有组件(另有专属 mount 契约文件),
|
||
* 本文件只钉页面接线(勾选累计/三参提交/打开路径/changed 重取)。
|
||
* 公司维度 2026-11-16 整页摘除(「删除掉公司 tab,参考品牌数据库」):页面不消费公司 tab
|
||
* store、列表不带 company_id(反向钉在 company-tab-wiring「公司维度不得回流」)。
|
||
* 不用 readFileSync(source-pin-ratchet 对台账外新文件带读点即红),全部走真实挂载断言。
|
||
*
|
||
* 跑法:`npx vitest run tests/mount/jd-database-page.mount.test.ts`
|
||
*/
|
||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||
import { DOMWrapper, flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||
import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
||
import { ElOption, ElSelect } from 'element-plus'
|
||
|
||
import JdDatabasePage from '@/pages/jd/JdDatabasePage.vue'
|
||
import JdProductEditDrawer from '@/pages/jd/JdProductEditDrawer.vue'
|
||
|
||
import { useAdminSessionStore } from '@/stores/admin-session'
|
||
|
||
const jdApi = vi.hoisted(() => ({
|
||
JD_PRODUCT_ENDPOINT: '/api/admin/jd-products',
|
||
JD_PRODUCT_GROUP_ENDPOINT: '/api/admin/jd-product-groups',
|
||
fetchJdProductList: vi.fn(),
|
||
fetchJdProductDetail: vi.fn(),
|
||
deleteJdProducts: vi.fn(),
|
||
fetchJdProductGroups: vi.fn(),
|
||
fetchJdCategoryScope: vi.fn(),
|
||
fetchJdProductCategories: vi.fn(),
|
||
createJdProductGroup: vi.fn(),
|
||
updateJdProductGroup: vi.fn(),
|
||
deleteJdProductGroup: vi.fn(),
|
||
updateJdProduct: vi.fn(),
|
||
batchAssignJdProductGroup: vi.fn(),
|
||
// v1.7 CSV 导出(Phase 4 对齐原型):工具栏导出按钮走它(blob 下载在 api 层,测试 mock 掉)。
|
||
exportJdProductsCsv: vi.fn(),
|
||
// v1.7 店铺名单(V214):侧栏名单交互与添加店铺弹窗的 API 面。
|
||
removeJdGroupShop: vi.fn(),
|
||
renameJdGroupShop: vi.fn(),
|
||
fetchJdGroupShops: vi.fn(),
|
||
addJdGroupShops: vi.fn(),
|
||
fetchJdAvailableShops: vi.fn(),
|
||
}))
|
||
|
||
const confirmMock = vi.hoisted(() => vi.fn())
|
||
|
||
const groupApi = vi.hoisted(() => ({
|
||
createShopGroup: vi.fn(),
|
||
}))
|
||
|
||
vi.mock('@/pages/jd/jd-product-api.ts', () => jdApi)
|
||
vi.mock('@/pages/account/shop-group-api.ts', () => groupApi)
|
||
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmMock }))
|
||
|
||
function item(id: number, over: Record<string, unknown> = {}) {
|
||
return {
|
||
id,
|
||
shopId: 3,
|
||
shopName: '旗舰自营店',
|
||
productCode: `JD-100${id}`,
|
||
skuId: `SKU-${id}`,
|
||
itemNum: `ITEM-${id}`,
|
||
skuCount: 12,
|
||
healthScore: 81,
|
||
title: '304不锈钢保温杯大容量便携',
|
||
brand: '锅宝',
|
||
categoryPath: '家居 > 厨具 > 保温杯',
|
||
// 价格用 number 形状(2026-11-16 实录:后端 BigDecimal 序列化成 JSON number,
|
||
// 字符串夹具曾把「解析层丢数字形状」这个真红藏住=生产库有价、界面全「-」)。
|
||
priceMin: 12.9,
|
||
priceMax: 15.9,
|
||
stockTotal: 500,
|
||
saleStatus: '上架中',
|
||
listTab: 'search',
|
||
jdCreatedAt: '2026-11-07 18:49:47',
|
||
jdOnlineAt: '2026-11-12 15:03:37',
|
||
jdUpdatedAt: '2026-11-13 14:06:07',
|
||
mainImageUrl: `https://img.example/main-${id}.jpg`,
|
||
attrCount: 6,
|
||
imageCount: 9,
|
||
groupId: 7,
|
||
groupName: '甲组',
|
||
syncedAt: '2026-11-12 09:00:00',
|
||
...over,
|
||
}
|
||
}
|
||
|
||
let pinia: Pinia
|
||
|
||
/** 分组 id 常量:默认作用域就这一个可见且可写的组(组长档形状),分类与行集都按它取。 */
|
||
const GROUP_A = 11
|
||
|
||
/** 分类作用域夹具(GET /scope 的归一形状):单组默认场景。 */
|
||
function singleGroupScope(editable = true) {
|
||
return {
|
||
platformSuperAdmin: false,
|
||
defaultGroupId: GROUP_A,
|
||
groups: [{ id: GROUP_A, name: '甲组', label: '甲组', editable }],
|
||
}
|
||
}
|
||
|
||
/** 类目计数夹具:与侧栏组件 mount 测试同源(树内连衣裙支+树外历史名),
|
||
* 树内路径以 jd-category-tree 真树为准:连衣裙=服饰内衣/女装/连衣裙、
|
||
* 艺考形体服=运动户外/舞蹈体操鞋服/装备/艺考形体服。 */
|
||
const CATEGORY_OPTIONS = [
|
||
{ name: '连衣裙', productCount: 7 },
|
||
{ name: '艺考形体服', productCount: 5 },
|
||
{ name: '已下架历史类目', productCount: 12 },
|
||
]
|
||
|
||
const GROUPS = [
|
||
{ id: 7, name: '裙装', ownerGroupId: GROUP_A, sortOrder: 0, productCount: 3, shops: ['绿屿街道店', '花屿巷旗舰店'] },
|
||
{ id: 8, name: '裤装', ownerGroupId: GROUP_A, sortOrder: 1, productCount: 1 },
|
||
]
|
||
|
||
beforeEach(() => {
|
||
vi.clearAllMocks()
|
||
pinia = createPinia()
|
||
setActivePinia(pinia)
|
||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope())
|
||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||
jdApi.fetchJdProductCategories.mockResolvedValue([])
|
||
// 店铺名单(v1.7)默认空回执:只有名单用例显式变形。
|
||
jdApi.removeJdGroupShop.mockResolvedValue(undefined)
|
||
jdApi.renameJdGroupShop.mockResolvedValue(undefined)
|
||
jdApi.fetchJdAvailableShops.mockResolvedValue([])
|
||
jdApi.addJdGroupShops.mockResolvedValue(0)
|
||
// CSV 导出(v1.7)默认空回执:只有导出用例显式变形。
|
||
jdApi.exportJdProductsCsv.mockResolvedValue(undefined)
|
||
localStorage.removeItem('jd_db_downloaded_ids')
|
||
groupApi.createShopGroup.mockResolvedValue({ id: 21, name: '京东-团队', ownerGroupId: 21, sortOrder: 0, productCount: 0 })
|
||
confirmMock.mockResolvedValue(true)
|
||
})
|
||
|
||
async function mountWith(payload: unknown): Promise<VueWrapper<Element>> {
|
||
jdApi.fetchJdProductList.mockImplementation(() => Promise.resolve(payload))
|
||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||
await flushPromises()
|
||
await flushPromises()
|
||
return wrapper
|
||
}
|
||
|
||
// ---------------- 侧栏助手(双 Tab 体 v-show 共存于 DOM,按文案圈定行) ----------------
|
||
|
||
/** 切到指定侧栏 Tab(商品目录/店铺分类)。 */
|
||
async function pickSideTab(wrapper: VueWrapper<Element>, name: string): Promise<void> {
|
||
const tab = wrapper.findAll('.jd-sidebar-tab').find((t) => t.text() === name)
|
||
expect(tab, `应存在「${name}」侧栏 Tab`).toBeTruthy()
|
||
await tab!.trigger('click')
|
||
await flushPromises()
|
||
}
|
||
|
||
/** 在指定 Tab 体(.jd-side-catalog/.jd-side-custom)内按文案找侧栏行。 */
|
||
function sideRowBy(scope: VueWrapper<Element>, text: string) {
|
||
const row = scope.findAll('.jd-side-row').find((node) => node.text().includes(text))
|
||
expect(row, `侧栏应存在文案含「${text}」的行`).toBeTruthy()
|
||
return row!
|
||
}
|
||
|
||
const sideCustom = (wrapper: VueWrapper<Element>) => wrapper.get('.jd-side-custom')
|
||
|
||
/** 卡片勾选框(label.jd-card-check 内 input,aria-label=勾选商品)。 */
|
||
const cardBoxes = (wrapper: VueWrapper<Element>) => wrapper.findAll('.jd-card input[type="checkbox"]')
|
||
|
||
/** 工具栏按钮按文案找(全选本页/取消本页/归入分类/取消归属)。 */
|
||
function toolbarBtn(wrapper: VueWrapper<Element>, text: string) {
|
||
const btn = wrapper.findAll('.jd-toolbar button').find((b) => b.text() === text)
|
||
expect(btn, `工具栏应存在「${text}」按钮`).toBeTruthy()
|
||
return btn!
|
||
}
|
||
|
||
// ---------------- el-select 交互助手(归属三档/分组下拉仍是 el-select,与亚马逊面统一) ----------------
|
||
// aria-label 经 EP 的 ariaLabel prop 落在内层 combobox input 上;选项弹层 teleport 到 body,
|
||
// 但 ElOption/ElSelect 组件仍在挂载树里 ⇒ 选项清单走组件树读,点选走「点开→点选项」真实路径。
|
||
|
||
/** 按 aria-label 找对应的 ElSelect 组件实例(靠内层 input 的 aria-label 区分)。 */
|
||
function selectByLabel(wrapper: VueWrapper<Element>, label: string) {
|
||
const found = wrapper.findAllComponents(ElSelect).find((s) => s.find(`[aria-label="${label}"]`).exists())
|
||
expect(found, `应存在 aria-label="${label}" 的下拉`).toBeTruthy()
|
||
return found!
|
||
}
|
||
|
||
/** 读某颗下拉的全部选项文案(label prop;组件树查询不受弹层 teleport 影响)。 */
|
||
function optionLabels(wrapper: VueWrapper<Element>, label: string): string[] {
|
||
return selectByLabel(wrapper, label).findAllComponents(ElOption).map((o) => o.props('label') as string)
|
||
}
|
||
|
||
/** 点开指定下拉并点选目标文案的选项(触发 update:modelValue + change,与真实用户一致)。
|
||
* 面板按内层 input 的 aria-controls 圈定,避免另一颗(可能仍挂着的)弹层串台。 */
|
||
async function pickSelectOption(wrapper: VueWrapper<Element>, label: string, optionText: string): Promise<void> {
|
||
const input = wrapper.get(`[aria-label="${label}"]`)
|
||
await input.trigger('click')
|
||
await flushPromises()
|
||
const contentId = input.attributes('aria-controls')
|
||
const scope = (contentId && document.getElementById(contentId)) ?? document.body
|
||
const items = [...scope.querySelectorAll('.el-select-dropdown__item')]
|
||
.filter((el) => !el.classList.contains('is-hidden'))
|
||
const target = items.find((el) => (el.textContent ?? '').trim() === optionText)
|
||
expect(target, `下拉应弹出「${optionText}」选项`).toBeTruthy()
|
||
await new DOMWrapper(target as Element).trigger('click')
|
||
await flushPromises()
|
||
}
|
||
|
||
/** 打开筛选弹层(v1.7):点「筛选」按钮 toggle,返回弹层节点(弹层必须在 DOM)。 */
|
||
async function openFilterPopover(wrapper: VueWrapper<Element>): Promise<DOMWrapper<Element>> {
|
||
const trigger = wrapper.findAll('button').find((b) => b.text() === '筛选')
|
||
expect(trigger, '顶部应存在「筛选」按钮').toBeTruthy()
|
||
await trigger!.trigger('click')
|
||
await flushPromises()
|
||
return wrapper.get('.jd-filter-popover')
|
||
}
|
||
|
||
/** 详情弹窗取数 mock(已由 parseJdProductDetail 归一的形状)。 */
|
||
function detailPayload(id = 1) {
|
||
return {
|
||
item: item(id),
|
||
attrGroups: [{ groupName: '规格', attrs: [{ key: 'capacity', label: '容量', value: '500ml' }] }],
|
||
images: [
|
||
{ id: 1, imageType: 'MAIN', attrName: '', sortNo: 1, url: 'https://img.example/main-1.jpg', byteSize: null, width: 800, height: 800 },
|
||
{ id: 2, imageType: 'DETAIL', attrName: '', sortNo: 2, url: 'https://img.example/detail.jpg', byteSize: null, width: null, height: null },
|
||
],
|
||
skus: [
|
||
{ skuId: '10238877506570', skuName: '花屿巷… 上衣 S', skuSeq: '1', price: 162, stock: 200, sortNo: 0,
|
||
saleAttrs: [{ name: '颜色', value: '上衣' }, { name: '尺码', value: 'S' }] },
|
||
],
|
||
attrJsonRaw: '',
|
||
}
|
||
}
|
||
|
||
describe('京东数据库页(v1.6 装配:侧栏+卡片网格)', () => {
|
||
it('挂载后按首屏分页参数取列表(pageSize 默认 50、档位 50/100/200/500/1000、不带公司维度),卡片数=本页条数', async () => {
|
||
const wrapper = await mountWith({ items: [item(1), item(2), item(3)], total: 42, page: 1, pageSize: 50 })
|
||
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1)
|
||
const firstCall = jdApi.fetchJdProductList.mock.calls[0][0]
|
||
expect(firstCall.page).toBe(1)
|
||
expect(firstCall.pageSize).toBe(50, 'v1.6 新契约:每页默认 50(Phase 1 常量)')
|
||
// 公司维度 2026-11-16 整页摘除:入参层不再有 companyId 键(单参 toHaveProperty 才是「键不存在」的真判据)。
|
||
expect(firstCall).not.toHaveProperty('companyId')
|
||
expect(wrapper.findAll('.jd-card')).toHaveLength(3)
|
||
// 档位 50/100/200/500/1000(v1.7 对齐原型)收敛在 filter 层常量:分页条下拉按它出选项。
|
||
expect(optionLabels(wrapper, '每页条数')).toEqual(['50条/页', '100条/页', '200条/页', '500条/页', '1000条/页'])
|
||
})
|
||
|
||
it('旧装配反钉:自绘表格/类目级联面板/详情抽屉三件已退役,批量入口改「归入分类」', async () => {
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
expect(wrapper.find('table').exists()).toBe(false, '自绘明细表已退役(卡片网格替代)')
|
||
expect(wrapper.find('.cat-trigger').exists()).toBe(false, '类目级联面板已退役(侧栏商品目录替代)')
|
||
expect(wrapper.find('.drawer-mask').exists()).toBe(false, '详情抽屉已退役(居中弹窗替代)')
|
||
expect(wrapper.findAll('button').some((b) => b.text() === '批量编辑分类')).toBe(false,
|
||
'工具栏批量入口改名「归入分类」(v1.6 蓝图措辞)')
|
||
// 侧栏双 Tab 的「店铺分类」是 Tab 名不是入口按钮:独立入口的反钉圈定在筛选行+工具栏。
|
||
const actionButtons = [...wrapper.get('.jd-filter-row').findAll('button'), ...wrapper.findAll('.jd-toolbar button')]
|
||
expect(actionButtons.some((b) => b.text() === '店铺分类')).toBe(false,
|
||
'「店铺分类」独立入口不存在(侧栏店铺分类 Tab 替代)')
|
||
expect(wrapper.find('.group-modal').exists()).toBe(false)
|
||
// 汇总条(共 X 条京东商品)2026-11-17 用户口径删除:不再渲染(反钉延续)。
|
||
expect(wrapper.find('.jd-summary').exists()).toBe(false)
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('卡片字段映射(商城款式):主图/店铺徽标/标题/价格区间/编码/采集日期/信息分', async () => {
|
||
const wrapper = await mountWith({ items: [item(1), item(2, { mainImageUrl: '', healthScore: null })], total: 2, page: 1, pageSize: 50 })
|
||
const cards = wrapper.findAll('.jd-card')
|
||
expect(cards).toHaveLength(2)
|
||
const first = cards[0]
|
||
expect(first.find('img.jd-card-thumb').exists()).toBe(true, '有自有桶 URL 的卡片出真图')
|
||
expect(first.get('.jd-card-shop').text()).toBe('旗舰自营店', '店铺徽标浮在图底')
|
||
expect(first.get('.jd-card-title').text()).toContain('304不锈钢保温杯大容量便携')
|
||
expect(first.get('.jd-card-price').text()).toBe('12.9 ~ 15.9', '价格走 jdPriceRange(number 形状不显示 -)')
|
||
expect(first.get('.jd-card-code').text()).toContain('JD-1001')
|
||
expect(first.get('.jd-card-date').text()).toContain('采集:')
|
||
expect(first.get('.jd-card-health').text()).toContain('信息分 81')
|
||
const second = cards[1]
|
||
expect(second.find('.jd-card-thumb-empty').text()).toBe('无图', '无图占位是 span,不冒充 img')
|
||
expect(second.find('.jd-card-health').exists()).toBe(false, 'healthScore 为空不出信息分徽标')
|
||
expect(second.findAll('img.jd-card-thumb')).toHaveLength(0)
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
/** 布局钉(2026-11-21 用户口径「放到上面筛选框」红框整体上移;v1.7 主面板加回显条+
|
||
* 自绘分页条+已选条):筛选行+批量按钮条离开右侧主面板、提到页面最顶(操作提示条
|
||
* 正下方、通栏整行);侧栏与主面板(回显条+网格+分页条+已选条)归入横排体 .jd-body。
|
||
* 反向钉死「改回主面板内」与「横排体散架」两种回归。 */
|
||
describe('布局:筛选行+工具栏上移顶部通栏(2026-11-21 用户口径红框整体上移)', () => {
|
||
it('筛选行与工具栏同住顶部通栏面板且先于横排体;主面板=回显条+卡片网格+自绘分页条+已选条', async () => {
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
const topPanel = wrapper.get('.jd-top-panel')
|
||
expect(topPanel.find('.jd-filter-row').exists()).toBe(true, '筛选行住顶部通栏面板')
|
||
expect(topPanel.find('.jd-toolbar').exists()).toBe(true, '批量按钮条随筛选行整体上移(同面板)')
|
||
|
||
const mainPanel = wrapper.get('.jd-main-panel')
|
||
expect(mainPanel.find('.jd-filter-row').exists()).toBe(false, '筛选行改回主面板即红')
|
||
expect(mainPanel.find('.jd-toolbar').exists()).toBe(false, '工具栏改回主面板即红')
|
||
expect(mainPanel.find('.jd-card-grid').exists()).toBe(true, '主面板=卡片网格')
|
||
expect(mainPanel.find('.jd-page-bar').exists()).toBe(true, '主面板=自绘分页条(v1.7 对齐原型)')
|
||
expect(mainPanel.find('.jd-select-bar').exists()).toBe(true, '主面板=底部已选条(v1.7 常驻)')
|
||
expect(mainPanel.text()).toContain('已选 0 件', '已选条常驻:0 件也显示(不随勾选数显隐)')
|
||
expect(mainPanel.find('.jd-filter-chips').exists()).toBe(false, '出厂态(默认未分类档)无激活筛选,回显条不渲染')
|
||
|
||
// 顺序与归属:页面根下先是顶部通栏面板、后是横排体;侧栏与主面板都在横排体里。
|
||
const viewChildren = [...wrapper.get('.jd-database-view').element.children]
|
||
const topIndex = viewChildren.findIndex((el) => el.classList.contains('jd-top-panel'))
|
||
const bodyIndex = viewChildren.findIndex((el) => el.classList.contains('jd-body'))
|
||
expect(topIndex).toBeGreaterThanOrEqual(0)
|
||
expect(bodyIndex).toBeGreaterThan(topIndex, '顶部通栏面板必须先于横排体(通栏在上)')
|
||
const body = wrapper.get('.jd-body')
|
||
expect(body.find('.jd-sidebar').exists()).toBe(true, '侧栏住横排体(不再直接挂页面根)')
|
||
expect(body.find('.jd-main-panel').exists()).toBe(true, '主面板住横排体')
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
describe('侧栏商品目录(类目筛选迁移自级联面板)', () => {
|
||
it('授权类目树逐级下钻:一级行点行=选中即查(path 下发),末级点行单名/路径口径与级联面板等价', async () => {
|
||
jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS)
|
||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||
expect(jdApi.fetchJdProductCategories).toHaveBeenCalledWith()
|
||
|
||
const catalog = wrapper.get('.jd-side-catalog')
|
||
// 一级默认展开:二级「女装」首屏可见(侧栏与级联面板的关键差异——非末级也能直接选)。
|
||
const women = sideRowBy(catalog, '女装')
|
||
expect(women.classes()).toContain('depth-1')
|
||
|
||
// 点二级=选中即查(2026-11-18 客户口径「没办法选择一级跟二级类目」的侧栏形状)。
|
||
await women.trigger('click')
|
||
await flushPromises()
|
||
let last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({ category: '女装', categoryPath: ['服饰内衣', '女装'], page: 1 },
|
||
'一级/二级点行=带完整路径下发(序列化按子树展开 IN)')
|
||
|
||
// 展开到末级再点末级:艺考形体服(运动户外支)。
|
||
await catalog.get('[aria-label="展开或收起 舞蹈体操鞋服/装备"]').trigger('click')
|
||
await flushPromises()
|
||
await sideRowBy(catalog, '艺考形体服').trigger('click')
|
||
await flushPromises()
|
||
last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({
|
||
category: '艺考形体服',
|
||
categoryPath: ['运动户外', '舞蹈体操鞋服/装备', '艺考形体服'],
|
||
page: 1,
|
||
}, '末级点行带完整名称路径(同名跨支靠路径区分)')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('树外兜底组(已落库但京麦树里没有的历史名):点行单名等值下发;「全部商品」行清选重查', async () => {
|
||
jdApi.fetchJdProductCategories.mockResolvedValue(CATEGORY_OPTIONS)
|
||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||
|
||
const catalog = wrapper.get('.jd-side-catalog')
|
||
// 树外兜底段:树外历史行从兜底组搜出可选(path 空数组=页面按无路径序列化单名等值)。
|
||
const extra = catalog.get('.jd-side-extra')
|
||
expect(extra.text()).toContain('树外兜底')
|
||
await extra.findAll('.jd-side-row').find((row) => row.text().includes('已下架历史类目'))!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ category: '已下架历史类目', categoryPath: [] })
|
||
|
||
// 点「全部商品」行=清选重查(category 回空、query 层不下发,回第一页)。
|
||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||
await catalog.get('.jd-side-all').trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '清选也要重查')
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].category).toBe('')
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].categoryPath).toEqual([],
|
||
'清选后路径回空数组(api 序列化层对空 category 不下发参数)')
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
describe('侧栏店铺分类(分类筛选迁移自下拉)', () => {
|
||
it('点分类行 → groupId 下发回第一页;再点已选行=清选(与旧「全部分类」行同语义)', async () => {
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
const custom = sideCustom(wrapper)
|
||
expect(sideRowBy(custom, '裙装').text()).toContain('3', '分类行带商品数徽标')
|
||
|
||
await sideRowBy(custom, '裙装').trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 })
|
||
expect(sideRowBy(custom, '裙装').classes()).toContain('selected', '选中态高亮')
|
||
|
||
await sideRowBy(custom, '裙装').trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].groupId).toBe('', '再点已选=清选重查')
|
||
expect(sideRowBy(custom, '裙装').classes()).not.toContain('selected')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('新建分类(可写档):createJdProductGroup 落当前分组并刷新侧栏分类', async () => {
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
jdApi.createJdProductGroup.mockResolvedValue({ id: 9, name: '新分类', ownerGroupId: GROUP_A, sortOrder: 2, productCount: 0 })
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
|
||
const callsBefore = jdApi.fetchJdProductGroups.mock.calls.length
|
||
await sideCustom(wrapper).get('[aria-label="新分类名称"]').setValue('新分类')
|
||
await sideCustom(wrapper).findAll('button').find((b) => b.text() === '新建分类')!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.createJdProductGroup).toHaveBeenCalledWith({ name: '新分类', sortOrder: 0, ownerGroupId: GROUP_A })
|
||
expect(jdApi.fetchJdProductGroups.mock.calls.length).toBeGreaterThan(callsBefore, '成功后刷新侧栏分类')
|
||
expect(document.body.textContent).toContain('已创建分类「新分类」')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('普通员工(editable=false)无新建分类行,但分类管理入口仍在(读面,写控件由对话框分档)', async () => {
|
||
useAdminSessionStore().user = { id: 2, username: 'ops', role: 'normal' }
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false))
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
const custom = sideCustom(wrapper)
|
||
expect(custom.find('[aria-label="新分类名称"]').exists()).toBe(false, '不可写档没有新建行')
|
||
expect(custom.get('.jd-side-manage').exists()).toBe(true, '分类管理入口对所有人渲染(V203)')
|
||
|
||
const callsBefore = jdApi.fetchJdProductGroups.mock.calls.length
|
||
await custom.get('.jd-side-manage').trigger('click')
|
||
await flushPromises()
|
||
const modal = wrapper.get('.manage-modal')
|
||
expect(modal.text()).toContain('分类管理')
|
||
expect(jdApi.fetchJdProductGroups.mock.calls.length).toBeGreaterThan(callsBefore, '对话框打开时按当前分组自取列表')
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
describe('分类管理入口(V204 独立页并入侧栏「分类管理」对话框)', () => {
|
||
it('对话框内删分类成功(emit changed)后父页重取分类(侧栏行与商品数徽标同步刷新)', async () => {
|
||
// 取数按次序变形:页面首屏=裙装;对话框打开与 changed 后的重取=删后列表(只剩裤装)。
|
||
let groupFetchCount = 0
|
||
jdApi.fetchJdProductGroups.mockImplementation(() => {
|
||
groupFetchCount += 1
|
||
return groupFetchCount === 1
|
||
? Promise.resolve([{ id: 7, name: '裙装', ownerGroupId: GROUP_A, sortOrder: 0, productCount: 3 }])
|
||
: Promise.resolve([{ id: 8, name: '裤装', ownerGroupId: GROUP_A, sortOrder: 1, productCount: 1 }])
|
||
})
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
expect(sideRowBy(sideCustom(wrapper), '裙装').exists()).toBe(true)
|
||
|
||
await sideCustom(wrapper).get('.jd-side-manage').trigger('click')
|
||
await flushPromises()
|
||
const modal = wrapper.get('.manage-modal')
|
||
confirmMock.mockResolvedValue(true)
|
||
jdApi.deleteJdProductGroup.mockResolvedValueOnce(undefined)
|
||
await modal.findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.deleteJdProductGroup, '删除按钮属于当前列表行').toHaveBeenCalledWith(8)
|
||
// changed → 父页 loadGroupOptions:侧栏按新列表重取(最后一次调用拿到删后列表)。
|
||
expect(sideRowBy(sideCustom(wrapper), '裤装').exists()).toBe(true, '侧栏刷新出新一轮分类')
|
||
expect(sideCustom(wrapper).findAll('.jd-side-row').some((node) => node.text().includes('裙装'))).toBe(false,
|
||
'删掉的分类不再出现在侧栏')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('平台超管空态直建分组:弹窗出直建表单,建组走 POST(jd 档) 且作用域重取翻到新组', async () => {
|
||
let scopeFetchCount = 0
|
||
jdApi.fetchJdCategoryScope.mockImplementation(() => {
|
||
scopeFetchCount += 1
|
||
return scopeFetchCount === 1
|
||
? Promise.resolve({ platformSuperAdmin: true, defaultGroupId: null, groups: [] })
|
||
: Promise.resolve({
|
||
platformSuperAdmin: true,
|
||
defaultGroupId: 21,
|
||
groups: [{ id: 21, name: '京东-团队', label: '京东-团队', editable: true }],
|
||
})
|
||
})
|
||
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 50 })
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
await sideCustom(wrapper).get('.jd-side-manage').trigger('click')
|
||
await flushPromises()
|
||
const modal = wrapper.get('.manage-modal')
|
||
expect(modal.get('[aria-label="新分组名称"]').exists()).toBe(true, '超管空态不是死路文案')
|
||
|
||
await modal.get('[aria-label="新分组名称"]').setValue('京东-团队')
|
||
await modal.findAll('button').find((b) => b.text() === '新建分组')!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(groupApi.createShopGroup).toHaveBeenCalledWith('京东-团队', [], 1, 'jd')
|
||
expect(jdApi.fetchJdCategoryScope).toHaveBeenCalledTimes(2, 'group-created ⇒ 父页整条作用域重取')
|
||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(21)
|
||
expect(wrapper.find('[aria-label="新分组名称"]').exists()).toBe(false, '有组了直建口子关掉')
|
||
expect(wrapper.get('.manage-modal').text()).toContain('本组暂无分类,先新建一个', '接着就能建分类')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('非超管 + 京东侧零分组:弹窗维持空态文案,无直建表单(口子不开给组长/公司超管)', async () => {
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: false, defaultGroupId: null, groups: [] })
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
await sideCustom(wrapper).get('.jd-side-manage').trigger('click')
|
||
await flushPromises()
|
||
const modal = wrapper.get('.manage-modal')
|
||
expect(modal.text()).toContain('你还不属于任何数据权限分组')
|
||
expect(modal.find('[aria-label="新分组名称"]').exists()).toBe(false)
|
||
expect(groupApi.createShopGroup).not.toHaveBeenCalled()
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
describe('归属三档快筛(三档,默认卡未分类)', () => {
|
||
it('下拉三档且首屏就卡「未分类」(classified="ungrouped" 随首取下发)', async () => {
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
expect(optionLabels(wrapper, '筛选分类状态')).toEqual(['全部', '已分类', '未分类'])
|
||
expect(jdApi.fetchJdProductList.mock.calls[0][0].classified).toBe('ungrouped',
|
||
'首屏默认档=未分类——用户口径「默认卡在未分类上就行」')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('选「全部」下发不带 classified 键(查当前分组全部商品);选「已分类」下发 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]).not.toHaveProperty('classified',
|
||
'value=\'\' 序列化不下发 classified 参数=后端跳过谓词查全部')
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1 }, '选中即查回第一页')
|
||
|
||
await pickSelectOption(wrapper, '筛选分类状态', '已分类')
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('classified')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('「重置」(弹层里)不放开筛选,而是回默认未分类档', 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)
|
||
await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].classified).toBe('ungrouped',
|
||
'重置回出厂默认档(未分类),「全部」只是可选项不接默认')
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
describe('批量操作(勾选跨页累计+工具栏)', () => {
|
||
it('勾选跨页记忆:第 1 页勾 1 张卡片翻到第 2 页再勾 1 张,删除按累计 2 张提交;「清除勾选」按钮已删', async () => {
|
||
// total=80(50/页下两页):默认档从 20 改 50 后,翻页夹具的 total 必须跟着放大。
|
||
jdApi.fetchJdProductList
|
||
.mockImplementationOnce(() => Promise.resolve({ items: [item(1)], total: 80, page: 1, pageSize: 50 }))
|
||
.mockImplementation(() => Promise.resolve({ items: [item(2)], total: 80, page: 2, pageSize: 50 }))
|
||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||
await flushPromises()
|
||
await flushPromises()
|
||
const deleteBtn = () => wrapper.get('.jd-delete-btn')
|
||
|
||
await cardBoxes(wrapper)[0].setValue(true)
|
||
expect(deleteBtn().text()).toContain('删除商品(1)')
|
||
|
||
// 翻页:勾选不清(2026-11-17 口径「支持勾选翻页也要记住」)。
|
||
await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click')
|
||
await flushPromises()
|
||
expect(deleteBtn().text()).toContain('删除商品(1)', '翻页后第 1 页的勾选仍在累计集里')
|
||
await cardBoxes(wrapper)[0].setValue(true)
|
||
expect(deleteBtn().text()).toContain('删除商品(2)', '第 2 页再勾 1 张,累计 2 张')
|
||
expect(wrapper.findAll('button').some((b) => b.text() === '清除勾选')).toBe(false,
|
||
'「清除勾选」按钮 2026-11-17 用户口径删除(显式反悔口没了,勾选只在批量操作成功后自动清)')
|
||
|
||
// 累计勾选直达删除:跨页的行一起删(确认弹窗点名总数)。
|
||
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 2, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
||
await deleteBtn().trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(confirmMock.mock.calls.at(-1)![0].message).toContain('确定批量删除选中的 2 个商品吗', '确认文案点名累计总数')
|
||
// 跨页累计的 id 一起提交。
|
||
expect(jdApi.deleteJdProducts).toHaveBeenLastCalledWith([1, 2])
|
||
expect(deleteBtn().text()).toContain('删除商品(0)', '批量删除成功后自动清勾选')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('全选本页/取消本页:只动当前页行集(跨页累计集里其他页的勾选不动)', async () => {
|
||
jdApi.fetchJdProductList
|
||
.mockImplementationOnce(() => Promise.resolve({ items: [item(1)], total: 80, page: 1, pageSize: 50 }))
|
||
.mockImplementation(() => Promise.resolve({ items: [item(2)], total: 80, page: 2, pageSize: 50 }))
|
||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||
await flushPromises()
|
||
await flushPromises()
|
||
const deleteBtn = () => wrapper.get('.jd-delete-btn')
|
||
|
||
// 第 1 页先手动勾 1 张,再翻页「全选本页」:第 2 页整页进累计集,第 1 页的勾选保留。
|
||
await cardBoxes(wrapper)[0].setValue(true)
|
||
await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click')
|
||
await flushPromises()
|
||
await toolbarBtn(wrapper, '全选本页').trigger('click')
|
||
expect(deleteBtn().text()).toContain('删除商品(2)', '全选本页=第 2 页 1 张+第 1 页累计 1 张')
|
||
|
||
await toolbarBtn(wrapper, '取消本页').trigger('click')
|
||
expect(deleteBtn().text()).toContain('删除商品(1)', '取消本页只清当前页,第 1 页的勾选保留')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('归入分类:未勾选时入口置灰,勾选后打开对话框选目标分类,按 (ids, groupId, ownerGroupId) 三参提交并清勾选重取', async () => {
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
jdApi.batchAssignJdProductGroup.mockResolvedValue(2)
|
||
const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 50 })
|
||
const editBtn = () => toolbarBtn(wrapper, '归入分类')
|
||
|
||
expect(editBtn().attributes('disabled')).toBeDefined('勾选 0 时置灰(常显口径)')
|
||
const boxes = cardBoxes(wrapper)
|
||
await boxes[0].setValue(true)
|
||
await boxes[1].setValue(true)
|
||
expect(editBtn().attributes('disabled')).toBeUndefined()
|
||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||
await editBtn().trigger('click')
|
||
await flushPromises()
|
||
const modal = wrapper.get('.batch-modal')
|
||
expect(modal.text()).toContain('批量编辑分类')
|
||
expect(modal.text()).toContain('已勾选 2 个商品(翻页累计)', '对话框点名累计勾选数')
|
||
expect(modal.text()).toContain('甲组', '标题/上下文带当前分组名')
|
||
expect(modal.findAll('.option-row')).toHaveLength(3, '两个分类+一个移出选项')
|
||
|
||
await modal.findAll('.option-row')[0].trigger('click')
|
||
const confirmBtn = modal.findAll('button').find((b) => b.text() === '归入「裙装」')
|
||
expect(confirmBtn, '确认按钮文案带目标分类名').toBeTruthy()
|
||
await confirmBtn!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
// 铁律 33 判据③:归类必须带第三个参数 ownerGroupId(归属表写入按当前分组落)。
|
||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1, 2], 7, GROUP_A)
|
||
expect(document.body.textContent).toContain('已把 2 个商品归入「裙装」')
|
||
expect(wrapper.find('.batch-modal').exists()).toBe(false, '成功后对话框自动关闭')
|
||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore, '成功后重取列表')
|
||
expect(wrapper.get('.jd-delete-btn').text()).toContain('删除商品(0)', '成功后清勾选')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('工具栏「取消归属」=groupId null 三参直解挂(与对话框「移出分类」同端点同语义)', async () => {
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await cardBoxes(wrapper)[0].setValue(true)
|
||
await toolbarBtn(wrapper, '取消归属').trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], null, GROUP_A)
|
||
expect(document.body.textContent).toContain('已把 1 个商品移出分类')
|
||
expect(wrapper.get('.jd-delete-btn').text()).toContain('删除商品(0)', '成功后清勾选')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('本组暂无分类:对话框只留提示不给提交(移出对未分类行是无谓操作),引导去侧栏「分类管理」新建', async () => {
|
||
jdApi.fetchJdProductGroups.mockResolvedValue([])
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await cardBoxes(wrapper)[0].setValue(true)
|
||
await toolbarBtn(wrapper, '归入分类').trigger('click')
|
||
await flushPromises()
|
||
const modal = wrapper.get('.batch-modal')
|
||
expect(modal.text()).toContain('本组暂无分类')
|
||
expect(modal.text()).toContain('分类管理', '空态把维护入口指向侧栏「分类管理」')
|
||
expect(modal.findAll('button').some((b) => b.text() === '移出分类' && b.attributes('disabled') === undefined)).toBe(false,
|
||
'无分类时移出不可提交')
|
||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('删除二次确认点名桶清理;取消不发请求(防误删的第一道闸)', async () => {
|
||
jdApi.deleteJdProducts.mockResolvedValue({ deleted: 2, imagesDeleted: 18, objectsDeleted: 16, objectsKept: 2, objectsSkipped: 0 })
|
||
const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 50 })
|
||
|
||
// 批量删除常显:未勾选时就在,只是置灰。
|
||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
|
||
expect(wrapper.find('.jd-delete-btn').attributes('disabled')).toBeDefined()
|
||
const boxes = cardBoxes(wrapper)
|
||
await boxes[0].setValue(true)
|
||
await boxes[1].setValue(true)
|
||
expect(wrapper.find('.jd-delete-btn').attributes('disabled')).toBeUndefined('勾选后按钮可点')
|
||
await wrapper.find('.jd-delete-btn').trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
|
||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||
const options = confirmMock.mock.calls[0][0]
|
||
expect(options.title).toBe('删除京东商品')
|
||
expect(options.message).toContain('确定批量删除选中的 2 个商品吗')
|
||
expect(options.message).toContain('jd-products 桶内图片文件一并删除', '确认弹窗必须点名「桶文件也会删」')
|
||
expect(options.danger).toBe(true)
|
||
|
||
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(1)
|
||
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1, 2])
|
||
expect(document.body.textContent).toContain('已删除 2 个商品')
|
||
expect(document.body.textContent).toContain('2 个共用图片保留', '共用对象计数要透出到反馈')
|
||
// 成功后重取列表并清勾选:常显按钮回到置灰。
|
||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(1)
|
||
expect(wrapper.find('.jd-delete-btn').attributes('disabled')).toBeDefined()
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('删除:确认弹窗点取消就不发请求', async () => {
|
||
confirmMock.mockResolvedValue(false)
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await cardBoxes(wrapper)[0].setValue(true)
|
||
await wrapper.find('.jd-delete-btn').trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(confirmMock).toHaveBeenCalledTimes(1)
|
||
expect(jdApi.deleteJdProducts).not.toHaveBeenCalled()
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('删除失败把后端「本次未删除任何数据」文案弹出来(整批拒绝的语义必须到界面),失败后勾选保留', async () => {
|
||
jdApi.deleteJdProducts.mockRejectedValue(new Error('桶内对象删除失败,本次未删除任何数据(jd-products/5/a.jpg):oss 5xx'))
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await cardBoxes(wrapper)[0].setValue(true)
|
||
await wrapper.find('.jd-delete-btn').trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
|
||
expect(document.body.textContent).toContain('本次未删除任何数据')
|
||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
|
||
expect(wrapper.get('.jd-delete-btn').text()).toContain('删除商品(1)', '失败后勾选保留,用户可重试')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('末页删空页码回退:第 2 页只剩 1 行删掉后回第 1 页重取(Phase 0 黄金测试 ⑤)', async () => {
|
||
// total=51 让分页条出「下一页」;第 1 页夹具从简(2 张卡片),语义落在「末页删空回退」上。
|
||
jdApi.fetchJdProductList
|
||
.mockImplementationOnce(() => Promise.resolve({ items: [item(1), item(2)], total: 51, page: 1, pageSize: 50 }))
|
||
.mockImplementationOnce(() => Promise.resolve({ items: [item(21)], total: 51, page: 2, pageSize: 50 }))
|
||
.mockImplementation(() => Promise.resolve({ items: [], total: 50, page: 1, pageSize: 50 }))
|
||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||
await flushPromises()
|
||
await flushPromises()
|
||
await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].page).toBe(2, '先到第 2 页(该页只剩 1 张)')
|
||
|
||
// 工具栏批量删除(全选本页 → 删除商品(1))替代旧行级删除按钮。
|
||
await toolbarBtn(wrapper, '全选本页').trigger('click')
|
||
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
||
await wrapper.get('.jd-delete-btn').trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1, pageSize: 50 },
|
||
'末页删空后页码回退重取(停在空页会让用户误以为库空了)')
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
describe('详情弹窗(抽屉退役后的详情入口)', () => {
|
||
it('点卡片打开居中弹窗:按 id 取详情,hero/属性分组/SKU 矩阵断言与旧抽屉逐字等价', async () => {
|
||
jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload()))
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '初始不显示弹窗')
|
||
|
||
await wrapper.findAll('.jd-card')[0].trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
|
||
expect(wrapper.find('.jd-modal-mask').exists()).toBe(true)
|
||
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledTimes(1)
|
||
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1)
|
||
// 2026-11-16 客户口径「详情页的样式要和京麦商品详情一样」:hero 左图右信息布局,
|
||
// 断言随弹窗形状从 .drawer-mask 迁到 .jd-modal-mask(Phase 4 内容块逐字同源)。
|
||
expect(wrapper.find('.detail-hero').exists()).toBe(true, '顶部左图右信息 hero 布局')
|
||
expect(wrapper.find('.hero-main').exists()).toBe(true, '左侧主图大图')
|
||
expect(wrapper.find('.hero-info').text()).toContain('价格区间')
|
||
expect(wrapper.find('.hero-info').text()).toContain('12.9 ~ 15.9', '价格走 decimalText(number/字符串都收)')
|
||
expect(wrapper.find('.jd-modal-mask').text()).toContain('规格')
|
||
expect(wrapper.find('.jd-modal-mask').text()).toContain('容量')
|
||
expect(wrapper.find('.jd-modal-mask').text()).toContain('500ml')
|
||
expect(wrapper.find('.jd-modal-mask').text()).toContain('主图')
|
||
const modalText = wrapper.find('.jd-modal-mask').text()
|
||
expect(modalText).toContain('货号')
|
||
expect(modalText).toContain('ITEM-1')
|
||
expect(modalText).toContain('信息分')
|
||
expect(modalText).toContain('上架时间')
|
||
// B104:详情里全量可见(店铺/分组也上详情,卡片不带这些字段)。
|
||
expect(modalText).toContain('家居 > 厨具 > 保温杯')
|
||
expect(modalText).toContain('SKU 数')
|
||
expect(modalText).toContain('京东创建时间')
|
||
expect(modalText).toContain('京东修改时间')
|
||
expect(modalText).toContain('旗舰自营店')
|
||
expect(modalText).toContain('甲组')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('弹窗内的销售属性=京麦 SKU 矩阵:维度列从 saleAttrs 派生;旧行没有矩阵时给可解释的空态', async () => {
|
||
jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload()))
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await wrapper.findAll('.jd-card')[0].trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
|
||
expect(wrapper.find('.jd-modal-mask').text()).toContain('销售属性 / SKU 矩阵')
|
||
const headers = wrapper.findAll('.sku-table thead th').map((th) => th.text())
|
||
expect(headers).toEqual(['序号', '颜色', '尺码', '京东价', '库存', 'SKU ID', 'SKU 名称'],
|
||
'维度列从各 SKU 的 saleAttrs 派生(京麦「颜色/尺码」两列)')
|
||
const firstRow = wrapper.findAll('.sku-table tbody tr')[0].findAll('td').map((td) => td.text())
|
||
expect(firstRow).toEqual(['1', '上衣', 'S', '¥162', '200', '10238877506570', '花屿巷… 上衣 S'])
|
||
expect(wrapper.find('.jd-modal-mask').text()).toContain('1 个 SKU')
|
||
expect(wrapper.find('.jd-modal-mask').text()).toContain('库存 200')
|
||
wrapper.unmount()
|
||
|
||
// 旧行没有 SKU 矩阵:给可解释的空态(不渲染空表、不静默吞)。
|
||
jdApi.fetchJdProductDetail.mockImplementation(() =>
|
||
Promise.resolve({ item: item(1), attrGroups: [], images: [], skus: [], attrJsonRaw: '' }))
|
||
const empty = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await empty.findAll('.jd-card')[0].trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(empty.find('.sku-table').exists()).toBe(false)
|
||
expect(empty.find('.jd-modal-mask').text()).toContain('暂无 SKU 矩阵')
|
||
empty.unmount()
|
||
})
|
||
|
||
it('弹窗顶部「编辑」防冒泡:关详情开编辑抽屉(抽屉自取回填),保存成功(saved)→ 列表重取(黄金⑥)', async () => {
|
||
jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload()))
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await wrapper.findAll('.jd-card')[0].trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
|
||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||
await wrapper.get('.jd-modal-actions').findAll('button').find((b) => b.text() === '编辑')!.trigger('click')
|
||
await flushPromises()
|
||
expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '点编辑先关详情弹窗')
|
||
const drawer = wrapper.findComponent(JdProductEditDrawer)
|
||
expect(drawer.exists()).toBe(true, '编辑抽屉已打开(真实路径点弹窗「编辑」)')
|
||
expect(wrapper.text()).toContain('人工维护', '保存后果提示常驻(V199 人工编辑锁)')
|
||
// saved 是抽屉的对外契约(保存成功由抽屉内部流发出),页面消费它刷新列表。
|
||
drawer.vm.$emit('saved')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1,
|
||
'保存成功后重取列表(人工编辑锁置位与最新字段即时可见)')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('弹窗顶部「删除」防冒泡:确认后调 deleteJdProducts(与旧操作列删除同一条链)', async () => {
|
||
jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload()))
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await wrapper.findAll('.jd-card')[0].trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
|
||
// 先验「取消不动」:beforeEach 默认 confirm=true,本例先翻回 false。
|
||
confirmMock.mockResolvedValue(false)
|
||
await wrapper.get('.jd-modal-actions').findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||
await flushPromises()
|
||
expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '点删除先关详情弹窗')
|
||
expect(confirmMock).toHaveBeenCalledTimes(1, '删除必须过二次确认')
|
||
expect(jdApi.deleteJdProducts).toHaveBeenCalledTimes(0, '确认弹窗取消时不发删除请求')
|
||
|
||
// 确认后:deleteJdProducts 按 id 直删(公共库写侧无公司维度)。
|
||
confirmMock.mockResolvedValue(true)
|
||
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
||
await wrapper.findAll('.jd-card')[0].trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
await wrapper.get('.jd-modal-actions').findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.deleteJdProducts).toHaveBeenCalledWith([1])
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('商品编码旁复制按钮:写入剪贴板且不冒泡开弹窗', async () => {
|
||
const writeText = vi.fn().mockResolvedValue(undefined)
|
||
Object.defineProperty(navigator, 'clipboard', { value: { writeText }, configurable: true })
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '复制前弹窗未开')
|
||
await wrapper.get('.jd-card-copy').trigger('click')
|
||
expect(writeText).toHaveBeenCalledWith('JD-1001')
|
||
expect(wrapper.find('.jd-modal-mask').exists()).toBe(false, '点复制按钮不冒泡开弹窗')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('分组读不到的那行详情里展示「未分类」(不猜名字;表格分类列退役后语义收进 hero)', async () => {
|
||
jdApi.fetchJdProductDetail.mockImplementation(() =>
|
||
Promise.resolve({ ...detailPayload(), item: item(1, { groupId: null, groupName: '' }) }))
|
||
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 50 })
|
||
await wrapper.findAll('.jd-card')[0].trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(wrapper.find('.jd-modal-mask').text()).toContain('未分类')
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
describe('筛选与分页(v1.7:合并搜索+筛选弹层;AC-2/AC-4)', () => {
|
||
it('合并搜索+弹层条件生效:keyword/分组分类/起止日期一次下发,查询回第一页重发(旧两框停发)', async () => {
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||
|
||
// 合并搜索框(v1.7):一个框同时承载商品编码与标题(OR 语义在后端 SQL)。
|
||
const searchBox = wrapper.get('[aria-label="搜索商品"]')
|
||
expect(searchBox.attributes('placeholder')).toBe('搜索商品编码或标题')
|
||
await searchBox.setValue('保温杯')
|
||
// 分类筛选从侧栏店铺分类 Tab 来(旧「筛选店铺分类」下拉退役)。
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
await sideRowBy(sideCustom(wrapper), '裙装').trigger('click')
|
||
await flushPromises()
|
||
// 同步起止收进筛选弹层(v1.7):开弹层→填日期→「应用」。
|
||
await openFilterPopover(wrapper)
|
||
const dateInputs = wrapper.findAll('input[type="date"]')
|
||
expect(dateInputs).toHaveLength(2, '弹层里同步起止两个日期框')
|
||
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 = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({
|
||
keyword: '保温杯',
|
||
groupId: '7',
|
||
syncedFrom: '2026-11-01',
|
||
syncedTo: '2026-11-09',
|
||
page: 1,
|
||
})
|
||
// 单参 toHaveProperty 才是「键不存在」的真判据(第二参会稀释成值断言):
|
||
// 旧编码/标题两框 v1.7 前端停发(合并进 keyword)、商品状态筛选下线、公司维度摘除。
|
||
// shopName 键 v1.7 随店铺名单回归页面入参层(空串=不限,序列化层不下发 shop_name)。
|
||
expect(last).not.toHaveProperty('productCode')
|
||
expect(last).not.toHaveProperty('titleKeyword')
|
||
expect(last.shopName).toBe('', '店铺入参空串=不限(Phase 3 侧栏点店铺行才带值)')
|
||
expect(last).not.toHaveProperty('saleStatus')
|
||
expect(last).not.toHaveProperty('companyId')
|
||
expect(wrapper.find('.jd-filter-popover').exists()).toBe(false, '「应用」后弹层收起')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('价格区间从弹层下发(AC-2):min/max 合法值随「应用」走查询;倒挡在门口拦下不发请求', async () => {
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||
|
||
await openFilterPopover(wrapper)
|
||
await wrapper.get('[aria-label="最低价格"]').setValue('100')
|
||
await wrapper.get('[aria-label="最高价格"]').setValue('200')
|
||
await wrapper.findAll('button').find((b) => b.text() === '应用')!.trigger('click')
|
||
await flushPromises()
|
||
let last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({ minPrice: '100', maxPrice: '200', page: 1 },
|
||
'价格区间随「应用」下发(序列化层转 snake min_price/max_price)')
|
||
|
||
// 倒挡(100 > 200 形状反过来填):在弹层门口拦下,不发请求、弹层不收。
|
||
await openFilterPopover(wrapper)
|
||
await wrapper.get('[aria-label="最低价格"]').setValue('300')
|
||
await wrapper.get('[aria-label="最高价格"]').setValue('200')
|
||
const beforeInvalid = jdApi.fetchJdProductList.mock.calls.length
|
||
await wrapper.findAll('button').find((b) => b.text() === '应用')!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(beforeInvalid, '倒挡不发请求')
|
||
expect(wrapper.find('.jd-filter-popover').exists()).toBe(true, '倒挡时弹层不收(让用户改数)')
|
||
expect(document.body.textContent).toContain('价格区间最小值不能大于最大值')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('重置把筛选面回空并回第一页重取(入口在弹层里;归属三档回未分类档、侧栏选中态清空)', async () => {
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||
await wrapper.get('[aria-label="搜索商品"]').setValue('保温杯')
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
await sideRowBy(sideCustom(wrapper), '裙装').trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7' })
|
||
|
||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||
await openFilterPopover(wrapper)
|
||
await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
|
||
await flushPromises()
|
||
|
||
expect(jdApi.fetchJdProductList.mock.calls.length).toBeGreaterThan(callsBefore)
|
||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({ keyword: '', groupId: '', category: '', page: 1 }, '重置后筛选全空、回第一页')
|
||
expect(wrapper.find('.jd-filter-popover').exists()).toBe(false, '重置后弹层收起')
|
||
expect(sideCustom(wrapper).findAll('.jd-side-row.selected')).toHaveLength(0, '侧栏分类选中态随重置清空')
|
||
expect(sideCustom(wrapper).findAll('.jd-side-row')).toHaveLength(2,
|
||
'重置只清筛选面:侧栏分类清单(当前组)保留,清选语义=再点已选行')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('翻页与改每页条数都重发请求,改条数回第一页(档位 50/100/200/500/1000)', async () => {
|
||
// total=520(50/页下 11 页):第 2 页的「下一页」要有第 3 页可去。
|
||
const wrapper = await mountWith({ items: [item(1)], total: 520, page: 2, pageSize: 50 })
|
||
|
||
await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(2)
|
||
expect(jdApi.fetchJdProductList.mock.calls[1][0].page).toBe(3)
|
||
|
||
// 每页条数下拉随自绘分页条(v1.7):点开→点选项,不走原生 setValue。
|
||
expect(wrapper.find('.page-size-select').exists()).toBe(true, '分页条下拉保留 .page-size-select 定位类')
|
||
await pickSelectOption(wrapper, '每页条数', '200条/页')
|
||
await flushPromises()
|
||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last.pageSize).toBe(200)
|
||
expect(last.page).toBe(1, '改每页条数后回第一页')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('CSV 导出(v1.7 Phase 4 恢复,对齐原型):勾选后按钮可用并按累计 id 提交;成功出角标并入已下载记忆', async () => {
|
||
const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 50 })
|
||
// 勾选前置灰(勾选 0 不给导出)。
|
||
const exportBtn = toolbarBtn(wrapper, '导出 CSV(0)')
|
||
expect(exportBtn.attributes('disabled')).toBeDefined()
|
||
|
||
// 勾选两张(跨页累计集的形状由既有用例管,这里只验导出链)。
|
||
await cardBoxes(wrapper)[0]!.setValue(true)
|
||
await cardBoxes(wrapper)[1]!.setValue(true)
|
||
await flushPromises()
|
||
const armed = toolbarBtn(wrapper, '导出 CSV(2)')
|
||
expect(armed.attributes('disabled')).toBeUndefined()
|
||
await armed.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.exportJdProductsCsv).toHaveBeenCalledTimes(1)
|
||
expect(jdApi.exportJdProductsCsv).toHaveBeenCalledWith([1, 2])
|
||
expect(document.body.textContent).toContain('已导出 2 个商品的 CSV')
|
||
|
||
// 成功后本批 id 进已下载记忆:卡片出「已下载」角标+localStorage 持久化。
|
||
expect(wrapper.findAll('.jd-card-downloaded')).toHaveLength(2, '导出成功的卡片出已下载角标')
|
||
const stored = JSON.parse(localStorage.getItem('jd_db_downloaded_ids') || '[]')
|
||
expect([...stored].sort()).toEqual([1, 2])
|
||
|
||
// 合并写(铁律 30):再导出另一行,之前的记录不被抹掉。
|
||
await cardBoxes(wrapper)[0]!.setValue(false)
|
||
await cardBoxes(wrapper)[1]!.setValue(false)
|
||
jdApi.fetchJdProductList.mockResolvedValue({ items: [item(3)], total: 3, page: 1, pageSize: 50 })
|
||
await wrapper.findAll('button').find((b) => b.text() === '刷新')!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
await cardBoxes(wrapper)[0]!.setValue(true)
|
||
await toolbarBtn(wrapper, '导出 CSV(1)').trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.exportJdProductsCsv).toHaveBeenLastCalledWith([3])
|
||
const storedAfter = JSON.parse(localStorage.getItem('jd_db_downloaded_ids') || '[]')
|
||
expect([...storedAfter].sort()).toEqual([1, 2, 3], '并集合并写:本批不抹之前的记录')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('顶部分页五键(v1.7 F4):首页/上一页/刷新/下一页/末页边界置灰,刷新重发当前页', async () => {
|
||
// 夹具回显请求的 page:load() 会把服务端回的 page 写回页面态(result.page>=1 即采信),
|
||
// 固定 page:2 的夹具会把「首页」点击后的页面态拉回第 2 页、刷新就不是当前页语义了。
|
||
jdApi.fetchJdProductList.mockImplementation((params: { page: number }) =>
|
||
Promise.resolve({ items: [item(params.page)], total: 120, page: params.page, pageSize: 50 }))
|
||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||
await flushPromises()
|
||
await flushPromises()
|
||
// 先翻到第 2 页再验五键。
|
||
await wrapper.findAll('button').find((b) => b.text() === '下一页')!.trigger('click')
|
||
await flushPromises()
|
||
const bar = wrapper.get('.jd-page-bar')
|
||
expect(bar.get('.jd-page-info').text()).toBe('第 2 / 3 页 · 共 120 条', '页码信息条文案逐字同')
|
||
|
||
const btn = (text: string) => [...bar.findAll('button')].find((b) => b.text() === text)
|
||
expect(btn('首页')!.attributes('disabled')).toBeUndefined('第 2 页可回首')
|
||
expect(btn('上一页')!.attributes('disabled')).toBeUndefined()
|
||
expect(btn('下一页')!.attributes('disabled')).toBeUndefined()
|
||
expect(btn('末页')!.attributes('disabled')).toBeUndefined()
|
||
|
||
await btn('首页')!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].page).toBe(1)
|
||
|
||
// 第 1 页:首页/上一页置灰;刷新重发当前页。
|
||
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||
await btn('刷新')!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1, '刷新重发当前页')
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].page).toBe(1)
|
||
expect(btn('首页')!.attributes('disabled')).toBeDefined('第 1 页首页置灰')
|
||
expect(btn('上一页')!.attributes('disabled')).toBeDefined()
|
||
|
||
await btn('末页')!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].page).toBe(3, '末页直达第 3 页')
|
||
expect(btn('下一页')!.attributes('disabled')).toBeDefined('末页上下一页置灰')
|
||
expect(btn('末页')!.attributes('disabled')).toBeDefined()
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('筛选回显条(v1.7 F5):激活筛选出芯片+共 N 条+清除筛选;清除保留分组作用域(AC-4)', async () => {
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
const wrapper = await mountWith({ items: [item(1)], total: 7, page: 1, pageSize: 50 })
|
||
expect(wrapper.find('.jd-filter-chips').exists()).toBe(false, '出厂态(默认未分类档)不渲染回显条')
|
||
|
||
// 激活一批筛选:搜索词+侧栏分类+弹层价格区间+同步区间。
|
||
await wrapper.get('[aria-label="搜索商品"]').setValue('保温杯')
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
await sideRowBy(sideCustom(wrapper), '裙装').trigger('click')
|
||
await flushPromises()
|
||
await openFilterPopover(wrapper)
|
||
await wrapper.get('[aria-label="最低价格"]').setValue('100')
|
||
await wrapper.get('[aria-label="最高价格"]').setValue('200')
|
||
await wrapper.get('[aria-label="同步开始日期"]').setValue('2026-11-01')
|
||
await wrapper.get('[aria-label="同步结束日期"]').setValue('2026-11-09')
|
||
await wrapper.findAll('button').find((b) => b.text() === '应用')!.trigger('click')
|
||
await flushPromises()
|
||
|
||
const chips = wrapper.get('.jd-filter-chips')
|
||
const chipText = chips.text()
|
||
expect(chipText).toContain('搜索:保温杯')
|
||
expect(chipText).toContain('分类:裙装', '侧栏分类选中按分类名回显(groupOptions 里查名,不裸显 id)')
|
||
expect(chipText).toContain('价格:100 ~ 200')
|
||
expect(chipText).toContain('同步:2026-11-01 ~ 2026-11-09')
|
||
expect(chipText).toContain('共 7 条', '「共 N 条」给行集规模')
|
||
expect(chips.get('.jd-chip-clear').text()).toBe('清除筛选')
|
||
|
||
// 清除筛选:筛选面回出厂(含三档回未分类),分组作用域保留。
|
||
await chips.get('.jd-chip-clear').trigger('click')
|
||
await flushPromises()
|
||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({ keyword: '', groupId: '', minPrice: '', maxPrice: '', syncedFrom: '', syncedTo: '' },
|
||
'清除筛选后筛选面回空')
|
||
expect(last.ownerGroupId).toBe(11, '清除筛选保留分组作用域(分组是作用域不是筛选条件)')
|
||
expect(last.classified).toBe('ungrouped', '归属三档回默认未分类档')
|
||
expect(wrapper.find('.jd-filter-chips').exists()).toBe(false, '清除后回显条消失(无激活筛选)')
|
||
expect(sideCustom(wrapper).findAll('.jd-side-row.selected')).toHaveLength(0, '侧栏分类选中态随清除清空')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('底部已选条(v1.7 F7 骨架):勾选随卡片勾选框累计,「已选 N 件」实时可见', async () => {
|
||
const wrapper = await mountWith({ items: [item(1), item(2)], total: 2, page: 1, pageSize: 50 })
|
||
const bar = wrapper.get('.jd-select-bar')
|
||
expect(bar.text()).toBe('已选 0 件')
|
||
await cardBoxes(wrapper)[0].setValue(true)
|
||
expect(wrapper.get('.jd-select-bar').text()).toBe('已选 1 件')
|
||
await cardBoxes(wrapper)[1].setValue(true)
|
||
expect(wrapper.get('.jd-select-bar').text()).toBe('已选 2 件')
|
||
// 批量删除成功清勾选后回 0(条常驻不消失)。
|
||
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 2, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
||
await toolbarBtn(wrapper, '全选本页').trigger('click')
|
||
await wrapper.get('.jd-delete-btn').trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(wrapper.get('.jd-select-bar').text()).toBe('已选 0 件')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('空态与加载失败条(失败给重试,不把整页打死)', async () => {
|
||
const empty = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||
const tip = empty.find('.jd-empty-tip')
|
||
expect(tip.exists()).toBe(true)
|
||
expect(tip.text()).toContain('暂无京东商品数据')
|
||
empty.unmount()
|
||
|
||
jdApi.fetchJdProductList.mockRejectedValue(new Error('上游 502'))
|
||
const failed = mount(JdDatabasePage, { global: { plugins: [pinia] } })
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(failed.find('.load-failure-bar').exists()).toBe(true)
|
||
expect(failed.find('.load-failure-bar').text()).toContain('京东商品列表加载失败')
|
||
failed.unmount()
|
||
})
|
||
})
|
||
|
||
/** 写权限分档(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」,铁律 33
|
||
* 判据②语义等价迁移:操作列/勾选列的档位判定原样落到「卡片勾选框+工具栏+详情弹窗
|
||
* 动作区」三种新 DOM 上;分组筛选=超管档专属口径不动)。 */
|
||
describe('京东数据库写权限分档(商品行写=超管+管理员;分组筛选=超管档;分类写=本组 editable)', () => {
|
||
it('普通员工且本组不可写:无勾选框、无工具栏写按钮、无删除商品、无归入分类、无分组控件;列表/筛选/详情照常', async () => {
|
||
useAdminSessionStore().user = { id: 2, username: 'ops', role: 'normal' }
|
||
// 普通员工:可见但不可写(editable=false)。
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false))
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
jdApi.fetchJdProductDetail.mockImplementation(() => Promise.resolve(detailPayload()))
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
|
||
expect(cardBoxes(wrapper)).toHaveLength(0, '不可写分类的普通员工没有勾选框')
|
||
expect(wrapper.find('.jd-toolbar').exists()).toBe(false, '工具栏(全选/归类/删除)整块不渲染')
|
||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(false, '删除商品按钮不渲染')
|
||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '普通员工不出分组下拉')
|
||
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '普通员工不出分组锁定芯片')
|
||
expect(wrapper.text()).toContain('只读:编辑/删除需超级管理员或管理员', '只读提示必须看得见并区分两类写权限')
|
||
expect(wrapper.text()).toContain('分类在左侧「分类管理」查看与维护', '提示把分类维护入口指向侧栏「分类管理」')
|
||
|
||
// 读面不受影响:筛选、侧栏分类行、点卡片开只读详情都还在。
|
||
expect(wrapper.findAll('.jd-card')).toHaveLength(1)
|
||
await wrapper.findAll('.jd-card')[0].trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(wrapper.find('.jd-modal-mask').exists()).toBe(true, '点卡片仍可开只读详情弹窗')
|
||
expect(jdApi.fetchJdProductDetail).toHaveBeenCalledWith(1)
|
||
expect(wrapper.find('.jd-modal-actions').exists()).toBe(false, '只读档详情弹窗无动作区(普通账号只读)')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('超管保留全部写入口(勾选框+工具栏整排+删除商品),且不显示只读提示', async () => {
|
||
// beforeEach 默认 super_admin;这里显式再钉一次,防默认值漂移把这条闸门变成恒绿。
|
||
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
|
||
expect(cardBoxes(wrapper)).toHaveLength(1)
|
||
expect(toolbarBtn(wrapper, '全选本页').exists()).toBe(true)
|
||
expect(toolbarBtn(wrapper, '取消本页').exists()).toBe(true)
|
||
expect(toolbarBtn(wrapper, '归入分类').exists()).toBe(true)
|
||
expect(toolbarBtn(wrapper, '取消归属').exists()).toBe(true)
|
||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
|
||
expect(wrapper.text()).not.toContain('只读:')
|
||
expect(wrapper.find('.jd-group-locked').exists()).toBe(true, '超管档保留分组控件(单组=锁定芯片)')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('公司超级管理员属超管档:写入口齐+分组控件在(单组=锁定芯片)', async () => {
|
||
useAdminSessionStore().user = { id: 4, username: 'company-root', role: 'company_super_admin' }
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
|
||
expect(cardBoxes(wrapper)).toHaveLength(1)
|
||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '删除商品对公司超管渲染')
|
||
expect(toolbarBtn(wrapper, '取消归属').exists()).toBe(true)
|
||
expect(wrapper.text()).not.toContain('只读:')
|
||
expect(wrapper.find('.jd-group-locked').exists()).toBe(true, '公司超管保留分组控件')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('管理员(admin 档):商品行写全放开(勾选框+工具栏整排),分组控件整块不渲染;归类带三参', async () => {
|
||
useAdminSessionStore().user = { id: 3, username: 'leader', role: 'admin' }
|
||
// 组长档形状:可见组可写 ⇒ editable=true;商品行写按管理员档判(2026-11-17 口径)。
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(true))
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
expect(cardBoxes(wrapper)).toHaveLength(1, '管理员有勾选框(服务批量删除与归类)')
|
||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true, '删除商品(商品行写)对管理员渲染')
|
||
expect(wrapper.text()).not.toContain('只读:')
|
||
// 分组筛选=超管档专属:管理员即使本组可写分类,也不出下拉/锁定芯片。
|
||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '管理员不出分组下拉')
|
||
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '管理员不出分组锁定芯片')
|
||
|
||
// 管理员可勾选并走一遍归类(2026-11-17 弹窗下线后唯一的归类路径;铁律 33 判据③)。
|
||
jdApi.batchAssignJdProductGroup.mockResolvedValue(1)
|
||
await cardBoxes(wrapper)[0].setValue(true)
|
||
await toolbarBtn(wrapper, '归入分类').trigger('click')
|
||
await flushPromises()
|
||
const modal = wrapper.get('.batch-modal')
|
||
await modal.findAll('.option-row')[0].trigger('click')
|
||
await modal.findAll('button').find((b) => b.text() === '归入「裙装」')!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.batchAssignJdProductGroup).toHaveBeenCalledWith([1], 7, GROUP_A)
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('管理员多组可见也不出「分组」下拉(超管档专属),写入口与默认组取数照常', async () => {
|
||
useAdminSessionStore().user = { id: 3, username: 'leader', role: 'admin' }
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue({
|
||
platformSuperAdmin: false,
|
||
defaultGroupId: 11,
|
||
groups: [
|
||
{ id: 11, name: 'A组', label: '甲公司 / A组', editable: true },
|
||
{ id: 12, name: 'B组', label: '甲公司 / B组', editable: false },
|
||
],
|
||
})
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
|
||
// 多组对管理员也不渲染切换下拉(作用域静默落在默认组)。
|
||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '多组也不给管理员出分组下拉')
|
||
// 写入口不受影响:工具栏整排都在,列表按默认组取。
|
||
expect(wrapper.find('.jd-delete-btn').exists()).toBe(true)
|
||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(11)
|
||
expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: 11 })
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('公司超级管理员多组可见:分组下拉在(超管档专属),可切组取数(铁律 33 判据①)', async () => {
|
||
useAdminSessionStore().user = { id: 4, username: 'company-root', role: 'company_super_admin' }
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue({
|
||
platformSuperAdmin: false,
|
||
defaultGroupId: 11,
|
||
groups: [
|
||
{ id: 11, name: 'A组', label: '甲公司 / A组', editable: true },
|
||
{ id: 12, name: 'B组', label: '甲公司 / B组', editable: true },
|
||
],
|
||
})
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
|
||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(true, '公司超管保留分组下拉')
|
||
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(12)
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12, page: 1 })
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
||
it('多组可见:筛选行出带标签的「分组」下拉,切换后侧栏分类与列表一并用新组取', async () => {
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue({
|
||
platformSuperAdmin: true,
|
||
defaultGroupId: 11,
|
||
groups: [
|
||
{ id: 11, name: 'A组', label: '甲公司 / A组', editable: true },
|
||
{ id: 12, name: 'B组', label: '甲公司 / B组', editable: true },
|
||
],
|
||
})
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
// 首屏就按默认组取(不是先不带 ownerGroupId 再补一次)。
|
||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(11)
|
||
expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: 11 })
|
||
|
||
const picker = wrapper.get('[aria-label="当前分组"]')
|
||
// 分组在筛选行里是带标签的表单控件(与其他筛选同壳同圆角),不再是工具栏裸下拉。
|
||
const groupField = picker.element.closest('.form-group')
|
||
expect(groupField?.querySelector('label')?.textContent).toBe('分组')
|
||
expect(optionLabels(wrapper, '当前分组')).toEqual(['甲公司 / A组', '甲公司 / B组'],
|
||
'跨公司组名由后端拼进 label,前端不解析公司字段')
|
||
|
||
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductGroups).toHaveBeenLastCalledWith(12)
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12, page: 1 },
|
||
'切组后列表按新组重取并回第一页')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('只有一组:不出下拉(锁定显示组名),分类与行集仍按该组取', async () => {
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '单组不渲染切换下拉')
|
||
expect(wrapper.get('.jd-group-locked').text()).toBe('甲组', '锁定芯片只放组名,「分组」二字在上方标签里')
|
||
expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: GROUP_A })
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('分组住进筛选行但仍是作用域不是筛选条件:重置(弹层里)只清筛选面,分组保持当前组', async () => {
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue({
|
||
platformSuperAdmin: true,
|
||
defaultGroupId: 11,
|
||
groups: [
|
||
{ id: 11, name: 'A组', label: '甲公司 / A组', editable: true },
|
||
{ id: 12, name: 'B组', label: '甲公司 / B组', editable: true },
|
||
],
|
||
})
|
||
const wrapper = await mountWith({ items: [], total: 0, page: 1, pageSize: 50 })
|
||
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12 })
|
||
await openFilterPopover(wrapper)
|
||
await wrapper.findAll('button').find((b) => b.text() === '重置')!.trigger('click')
|
||
await flushPromises()
|
||
expect(selectByLabel(wrapper, '当前分组').props('modelValue')).toBe(12, '重置不清当前分组(作用域语义,搬进筛选行也不变)')
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ ownerGroupId: 12 },
|
||
'重置后的重取仍带当前分组')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('不属于任何数据权限分组:侧栏分类全空、不给切换也不给批量归类入口', async () => {
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue({ platformSuperAdmin: false, defaultGroupId: null, groups: [] })
|
||
const wrapper = await mountWith({ items: [item(1, { groupId: null, groupName: '' })], total: 1, page: 1, pageSize: 50 })
|
||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false)
|
||
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有分组就没有可锁定的组名')
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
expect(sideCustom(wrapper).text()).toContain('本组暂无分类', '侧栏分类面空态')
|
||
expect(sideCustom(wrapper).find('[aria-label="新分类名称"]').exists()).toBe(false)
|
||
expect(wrapper.findAll('.jd-toolbar button').some((b) => b.text() === '归入分类')).toBe(false,
|
||
'没有分组就没有可写的分类面')
|
||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('切组三联动补齐(Phase 0 黄金测试 ③):分类筛选随上一组清空,重取 groupId 回空并回第一页', async () => {
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue({
|
||
platformSuperAdmin: true,
|
||
defaultGroupId: 11,
|
||
groups: [
|
||
{ id: 11, name: 'A组', label: '甲公司 / A组', editable: true },
|
||
{ id: 12, name: 'B组', label: '甲公司 / B组', editable: true },
|
||
],
|
||
})
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
await sideRowBy(sideCustom(wrapper), '裙装').trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', page: 1 },
|
||
'先选中本组分类(带 groupId 查)')
|
||
|
||
await pickSelectOption(wrapper, '当前分组', '甲公司 / B组')
|
||
await flushPromises()
|
||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({ ownerGroupId: 12, page: 1 }, '切组后回第一页按新组重取')
|
||
expect(last.groupId).toBe('', '上一组的分类 id 不能带进新组(changeOwnerGroup 清 filter.groupId)')
|
||
expect(sideCustom(wrapper).findAll('.jd-side-row.selected')).toHaveLength(0, '侧栏分类选中态随切组清空')
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
/** 首屏作用域同源与静默降级(Phase 0 黄金测试,2026-11-21 蓝图缺口清单 ①②):
|
||
* 铁律 30 同形——「先解析作用域再取列表」是首屏顺序契约:scope 未回前列表不发请求,
|
||
* 首调即带默认组 owner_group_id(两请求落在同一组上,不得先发一条不带分组的列表再补);
|
||
* scope 拉取失败静默降级——分类面回空(侧栏分类空态、无分组控件与锁定芯片)
|
||
* 而商品行集照常渲染(分类只是筛选/归类面,不拦首屏行集)。 */
|
||
describe('首屏作用域同源与静默降级(Phase 0 黄金测试)', () => {
|
||
it('首屏先作用域后列表:scope 未回前列表不发请求,首调即带默认组(铁律 30 同源)', async () => {
|
||
jdApi.fetchJdProductList.mockImplementation(() =>
|
||
Promise.resolve({ items: [item(1)], total: 1, page: 1, pageSize: 50 }))
|
||
let resolveScope!: (value: unknown) => void
|
||
jdApi.fetchJdCategoryScope.mockImplementation(() =>
|
||
new Promise((resolve) => { resolveScope = resolve }))
|
||
const wrapper = mount(JdDatabasePage, { global: { plugins: [pinia, ElSelect, ElOption] } })
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList,
|
||
'scope 未回前不得先发列表请求(先发=不带 owner_group_id 的孤儿请求)').not.toHaveBeenCalled()
|
||
|
||
resolveScope(singleGroupScope())
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList).toHaveBeenCalledTimes(1)
|
||
expect(jdApi.fetchJdProductList.mock.calls[0][0]).toMatchObject({ ownerGroupId: GROUP_A, page: 1 },
|
||
'列表首调即带作用域默认组(与侧栏分类同一个组)')
|
||
expect(jdApi.fetchJdProductGroups).toHaveBeenCalledWith(GROUP_A)
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('scope 拉取失败静默降级:分类面回空而商品行集照常渲染(不拦首屏)', async () => {
|
||
jdApi.fetchJdCategoryScope.mockRejectedValue(new Error('scope 上游 502'))
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
expect(wrapper.findAll('.jd-card')).toHaveLength(1, '商品行集不受 scope 失败影响')
|
||
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '没有作用域就没有分组切换')
|
||
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有作用域就没有锁定芯片')
|
||
expect(sideCustom(wrapper).text()).toContain('本组暂无分类', '侧栏分类面空态(降级不冒充有数据)')
|
||
wrapper.unmount()
|
||
})
|
||
})
|
||
|
||
/** 店铺名单接线(v1.7 F6,2026-11-21 拍板「完整对齐」):侧栏点店铺行→列表按
|
||
* group_id+shop_name 成对过滤;行内改名/移除与分类行删除走对应 API;添加店铺弹窗
|
||
* 开合与批量提交。API 全部 mock(端点形状在 jd-product-api 与后端 controller 对撞)。 */
|
||
describe('店铺名单接线(v1.7:点店铺过滤+名单维护+添加店铺弹窗)', () => {
|
||
/** 挂载带名单的页面并展开裙装的名单。 */
|
||
async function mountWithShops(): Promise<VueWrapper<Element>> {
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
await sideCustom(wrapper).get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||
await flushPromises()
|
||
return wrapper
|
||
}
|
||
|
||
function shopRows(wrapper: VueWrapper<Element>) {
|
||
return sideCustom(wrapper).findAll('.jd-side-shop')
|
||
}
|
||
|
||
it('点店铺行 → 列表按 (groupId, shopName) 成对过滤回第一页;回显条出店铺芯片;再点已选=清店铺保留分类', async () => {
|
||
const wrapper = await mountWithShops()
|
||
await shopRows(wrapper)[0]!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject(
|
||
{ groupId: '7', shopName: '绿屿街道店', page: 1 },
|
||
'点店铺=该分类归属 ∩ 该店铺(精确 eq,后端 SQL 谓词)')
|
||
expect(wrapper.get('.jd-filter-chips').text()).toContain('店铺:绿屿街道店', '回显条带店铺芯片')
|
||
|
||
await shopRows(wrapper)[0]!.trigger('click')
|
||
await flushPromises()
|
||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last.shopName).toBe('', '再点已选=清店铺筛选')
|
||
expect(last.groupId).toBe('7', '分类选中保留(每层独立 toggle)')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('分类行内删除:二次确认(点名只解挂归属)→ deleteJdProductGroup → 停在该分类的筛选清空并重取', async () => {
|
||
const wrapper = await mountWithShops()
|
||
await shopRows(wrapper)[0]!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7' })
|
||
|
||
await sideCustom(wrapper).get('[aria-label="删除分类 裙装"]').trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
const options = confirmMock.mock.calls.at(-1)![0]
|
||
expect(options.title).toBe('删除分类')
|
||
expect(options.message).toContain('商品本身保留在公共库', '确认弹窗点名删除语义(只解挂归属)')
|
||
expect(options.danger).toBe(true)
|
||
expect(jdApi.deleteJdProductGroup).toHaveBeenCalledWith(7)
|
||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last).toMatchObject({ groupId: '', shopName: '' }, '停在该分类(含店铺行)的筛选随删除清空')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('店铺行内改名:renameJdGroupShop 三参提交并刷新名单;筛选正停在该店时筛选词同步成新名', async () => {
|
||
const wrapper = await mountWithShops()
|
||
await shopRows(wrapper)[0]!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].shopName).toBe('绿屿街道店')
|
||
|
||
const custom = sideCustom(wrapper)
|
||
await custom.get('[aria-label="改名店铺 绿屿街道店"]').trigger('click')
|
||
await flushPromises()
|
||
await custom.get('[aria-label="修改店铺名称(原:绿屿街道店)"]').setValue('绿屿新址店')
|
||
await custom.get('[aria-label="确认改名店铺 绿屿街道店"]').trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.renameJdGroupShop).toHaveBeenCalledWith(7, '绿屿街道店', '绿屿新址店')
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0].shopName).toBe('绿屿新址店',
|
||
'筛选词同步成新名(不然界面按旧店名查,名单里已没有这一行)')
|
||
expect(document.body.textContent).toContain('已把店铺「绿屿街道店」改名为「绿屿新址店」')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('店铺行移除:removeJdGroupShop 提交;筛选正停在该店时清店铺筛选重取(可重做不设确认)', async () => {
|
||
const wrapper = await mountWithShops()
|
||
await shopRows(wrapper)[0]!.trigger('click')
|
||
await flushPromises()
|
||
|
||
await sideCustom(wrapper).get('[aria-label="移除店铺 绿屿街道店"]').trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.removeJdGroupShop).toHaveBeenCalledWith(7, '绿屿街道店')
|
||
expect(confirmMock).not.toHaveBeenCalledWith(expect.objectContaining({ title: '移除店铺' }),
|
||
'移除可重做(再加回名单即可),不设二次确认')
|
||
const last = jdApi.fetchJdProductList.mock.calls.at(-1)![0]
|
||
expect(last.shopName).toBe('', '筛选正停在移除的店上=清店铺筛选')
|
||
expect(last.groupId).toBe('7', '分类选中保留')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('添加店铺弹窗:打开即拉候选(排除本分类已有名单),勾选+手输合并批量提交,done 刷新名单', async () => {
|
||
jdApi.fetchJdAvailableShops.mockResolvedValue(['旗舷店', '望江路店'])
|
||
jdApi.addJdGroupShops.mockResolvedValue(2)
|
||
const wrapper = await mountWithShops()
|
||
const custom = sideCustom(wrapper)
|
||
const groupsCallsBefore = jdApi.fetchJdProductGroups.mock.calls.length
|
||
|
||
await custom.get('.jd-side-shop-add').trigger('click')
|
||
await flushPromises()
|
||
const modal = wrapper.get('.shop-picker-modal')
|
||
expect(modal.text()).toContain('添加店铺')
|
||
expect(modal.text()).toContain('裙装', '标题带目标分类名')
|
||
expect(jdApi.fetchJdAvailableShops).toHaveBeenCalledWith('', 7)
|
||
|
||
// 勾选一个候选+手输一个自定义项。
|
||
await modal.findAll('.shop-candidate-row')[0]!.trigger('click')
|
||
await modal.get('[aria-label="自定义店铺名"]').setValue('手输新店')
|
||
await modal.findAll('button').find((b) => b.text() === '加入')!.trigger('click')
|
||
await flushPromises()
|
||
expect(modal.text()).toContain('手输新店', '自定义项进待添加清单')
|
||
expect(modal.text()).toContain('添加(2)')
|
||
|
||
await modal.findAll('button').find((b) => /^添加(2)$/.test(b.text()))!.trigger('click')
|
||
await flushPromises()
|
||
await flushPromises()
|
||
expect(jdApi.addJdGroupShops).toHaveBeenCalledWith(7, ['旗舷店', '手输新店'])
|
||
expect(document.body.textContent).toContain('已把 2 个店铺加进「裙装」')
|
||
expect(wrapper.find('.shop-picker-modal').exists()).toBe(false, '成功后弹窗自动关闭')
|
||
expect(jdApi.fetchJdProductGroups.mock.calls.length).toBeGreaterThan(groupsCallsBefore, 'done 刷新名单')
|
||
wrapper.unmount()
|
||
})
|
||
|
||
it('普通员工(editable=false):侧栏无名单写入口(无添加店铺/无行内改名移除),点店铺过滤照常', async () => {
|
||
useAdminSessionStore().user = { id: 2, username: 'ops', role: 'normal' }
|
||
jdApi.fetchJdCategoryScope.mockResolvedValue(singleGroupScope(false))
|
||
jdApi.fetchJdProductGroups.mockResolvedValue(GROUPS)
|
||
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 50 })
|
||
await pickSideTab(wrapper, '店铺分类')
|
||
await sideCustom(wrapper).get('[aria-label="展开或收起 裙装 的店铺名单"]').trigger('click')
|
||
await flushPromises()
|
||
const custom = sideCustom(wrapper)
|
||
expect(custom.findAll('.jd-side-shop')).toHaveLength(2, '店铺行照常可见(读面)')
|
||
expect(custom.find('.jd-side-shop-add').exists()).toBe(false, '只读档无添加店铺入口')
|
||
expect(custom.find('[aria-label="改名店铺 绿屿街道店"]').exists()).toBe(false)
|
||
|
||
await custom.findAll('.jd-side-shop')[0]!.trigger('click')
|
||
await flushPromises()
|
||
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ groupId: '7', shopName: '绿屿街道店' },
|
||
'只读档点店铺照常过滤')
|
||
wrapper.unmount()
|
||
})
|
||
})
|