test(phase-0): 京东数据库 UI 改造蓝图 Phase 0——基线全绿锁定+补 5 条黄金测试(缺口①②③⑤⑥)
This commit is contained in:
@@ -23,6 +23,7 @@ import { createPinia, setActivePinia, type Pinia } from 'pinia'
|
|||||||
import { ElOption, ElSelect } from 'element-plus'
|
import { ElOption, ElSelect } from 'element-plus'
|
||||||
|
|
||||||
import JdDatabasePage from '@/pages/jd/JdDatabasePage.vue'
|
import JdDatabasePage from '@/pages/jd/JdDatabasePage.vue'
|
||||||
|
import JdProductEditDrawer from '@/pages/jd/JdProductEditDrawer.vue'
|
||||||
import OldPagination from '@/components/OldPagination.vue'
|
import OldPagination from '@/components/OldPagination.vue'
|
||||||
|
|
||||||
import { useAdminSessionStore } from '@/stores/admin-session'
|
import { useAdminSessionStore } from '@/stores/admin-session'
|
||||||
@@ -920,6 +921,46 @@ describe('京东数据库页(v1.4 Phase 5)', () => {
|
|||||||
expect(failed.find('.load-failure-bar').exists()).toBe(true)
|
expect(failed.find('.load-failure-bar').exists()).toBe(true)
|
||||||
expect(failed.find('.load-failure-bar').text()).toContain('京东商品列表加载失败')
|
expect(failed.find('.load-failure-bar').text()).toContain('京东商品列表加载失败')
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('末页删空页码回退:第 2 页只剩 1 行删掉后回第 1 页重取(Phase 0 黄金测试 ⑤)', async () => {
|
||||||
|
// total=21 让分页条出「下一页」;第 1 页夹具从简(2 行),语义落在「末页删空回退」上。
|
||||||
|
jdApi.fetchJdProductList
|
||||||
|
.mockImplementationOnce(() => Promise.resolve({ items: [item(1), item(2)], total: 21, page: 1, pageSize: 20 }))
|
||||||
|
.mockImplementationOnce(() => Promise.resolve({ items: [item(21)], total: 21, page: 2, pageSize: 20 }))
|
||||||
|
.mockImplementation(() => Promise.resolve({ items: [], total: 20, page: 1, pageSize: 20 }))
|
||||||
|
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 行)')
|
||||||
|
|
||||||
|
jdApi.deleteJdProducts.mockResolvedValueOnce({ deleted: 1, imagesDeleted: 0, objectsDeleted: 0, objectsKept: 0, objectsSkipped: 0 })
|
||||||
|
await wrapper.findAll('tbody tr')[0].findAll('td')[6].findAll('button').find((b) => b.text() === '删除')!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.at(-1)![0]).toMatchObject({ page: 1, pageSize: 20 },
|
||||||
|
'末页删空后页码回退重取(停在空页会让用户误以为库空了)')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('编辑保存成功(抽屉 emit saved)→ 列表重取(Phase 0 黄金测试 ⑥)', async () => {
|
||||||
|
jdApi.fetchJdProductDetail.mockResolvedValue({
|
||||||
|
item: item(1), attrGroups: [], images: [], skus: [], attrJsonRaw: '',
|
||||||
|
})
|
||||||
|
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||||
|
const callsBefore = jdApi.fetchJdProductList.mock.calls.length
|
||||||
|
await wrapper.findAll('tbody tr')[0].findAll('td')[6].findAll('button').find((b) => b.text() === '编辑')!.trigger('click')
|
||||||
|
await flushPromises()
|
||||||
|
const drawer = wrapper.findComponent(JdProductEditDrawer)
|
||||||
|
expect(drawer.exists()).toBe(true, '编辑抽屉已打开(真实路径点「编辑」)')
|
||||||
|
// saved 是抽屉的对外契约(保存成功由抽屉内部流发出),页面消费它刷新列表。
|
||||||
|
drawer.vm.$emit('saved')
|
||||||
|
await flushPromises()
|
||||||
|
expect(jdApi.fetchJdProductList.mock.calls.length).toBe(callsBefore + 1,
|
||||||
|
'保存成功后重取列表(人工编辑锁置位与最新字段即时可见)')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
/** 写权限分档(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」,推翻
|
/** 写权限分档(2026-11-17 用户口径「超管+管理员都可以,只有普通员工不能操作」,推翻
|
||||||
@@ -1132,4 +1173,68 @@ describe('京东数据库分类按数据权限分组隔离(V203)', () => {
|
|||||||
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
expect(jdApi.batchAssignJdProductGroup).not.toHaveBeenCalled()
|
||||||
wrapper.unmount()
|
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([{ id: 7, name: '裙装', sortOrder: 0, productCount: 3 }])
|
||||||
|
const wrapper = await mountWith({ items: [item(1)], total: 1, page: 1, pageSize: 20 })
|
||||||
|
await pickSelectOption(wrapper, '筛选店铺分类', '裙装')
|
||||||
|
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(selectByLabel(wrapper, '筛选店铺分类').props('modelValue')).toBe('', '分类筛选下拉回显回「全部分类」')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
/** 首屏作用域同源与静默降级(Phase 0 黄金测试,2026-11-21 蓝图缺口清单 ①②):
|
||||||
|
* 铁律 30 同形——「先解析作用域再取列表」是首屏顺序契约:scope 未回前列表不发请求,
|
||||||
|
* 首调即带默认组 owner_group_id(两请求落在同一组上,不得先发一条不带分组的列表再补);
|
||||||
|
* scope 拉取失败静默降级——分类面回空(分类下拉只剩「全部分类」、无分组控件与锁定芯片)
|
||||||
|
* 而商品行集照常渲染(分类只是筛选/归类面,不拦首屏行集)。Phase 5 重写页面装配层时
|
||||||
|
* 这两条是装配顺序与降级语义的安全网。 */
|
||||||
|
describe('首屏作用域同源与静默降级(Phase 0 黄金测试)', () => {
|
||||||
|
it('首屏先作用域后列表:scope 未回前列表不发请求,首调即带默认组(铁律 30 同源)', async () => {
|
||||||
|
jdApi.fetchJdProductList.mockImplementation(() =>
|
||||||
|
Promise.resolve({ items: [item(1)], total: 1, page: 1, pageSize: 20 }))
|
||||||
|
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: 20 })
|
||||||
|
expect(wrapper.findAll('tbody tr')).toHaveLength(1, '商品行集不受 scope 失败影响')
|
||||||
|
expect(optionLabels(wrapper, '筛选店铺分类')).toEqual(['全部分类'], '分类下拉只剩「全部分类」')
|
||||||
|
expect(wrapper.find('[aria-label="当前分组"]').exists()).toBe(false, '没有作用域就没有分组切换')
|
||||||
|
expect(wrapper.find('.jd-group-locked').exists()).toBe(false, '没有作用域就没有锁定芯片')
|
||||||
|
wrapper.unmount()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user