feat(jd): 采集分类改「同步分类」按店实时拉取+回补 4.0.78 窗用户端 amber notice 源码
This commit is contained in:
@@ -50,8 +50,11 @@ test('endpoints 注册采集类目 categories 端点(数据面保留)', () =
|
||||
})
|
||||
|
||||
/** 2026-11-16 口径修订:客户参照系是京麦后台的「店内分类」,平台分组 chips 从本页下线
|
||||
* (分组数据面归后管京东数据库与商品上架,端点与 fetch 函数保留)。 */
|
||||
test('分类多选来自京麦店内分类快照,平台分组从本页下线', () => {
|
||||
* (分组数据面归后管京东数据库与商品上架,端点与 fetch 函数保留)。
|
||||
* 2026-11-19 客户口径「每一家店铺的分类都会不一样」:选项集正本从冻结快照改为按店
|
||||
* 实时拉取——「同步分类」按钮 → 桥 get_jd_shop_categories → 客户端用本机已登录京麦
|
||||
* profile 现拉 getShopCategoryList(执行体 amazon/jd/shop_categories.py)。 */
|
||||
test('分类多选改桥实时拉取,快照与平台分组从本页退役', () => {
|
||||
const endpoints = readIfExists(ENDPOINTS, 'endpoints.ts')
|
||||
assert.ok(endpoints.includes("groups: '/api/jd-collect/groups'"),
|
||||
'endpoints.ts jdCollect 组仍须登记 groups(冻结快照口径;建单页 UI 已下线,仅数据面保留)')
|
||||
@@ -67,8 +70,12 @@ test('分类多选来自京麦店内分类快照,平台分组从本页下线',
|
||||
join(process.cwd(), 'src', 'pages', 'jd', 'JdCollectTab.vue'),
|
||||
'JdCollectTab.vue',
|
||||
)
|
||||
assert.ok(page.includes('JD_SHOP_CATEGORY_SNAPSHOT'),
|
||||
'JdCollectTab.vue 必须消费京麦店内分类快照(jd-shop-category.ts)作采集分类多选选项')
|
||||
assert.ok(page.includes('get_jd_shop_categories'),
|
||||
'JdCollectTab.vue 必须经桥 get_jd_shop_categories 拉店内分类(冻结快照已退役:每家店的分类不同)')
|
||||
assert.ok(page.includes('同步分类'),
|
||||
'JdCollectTab.vue 必须有「同步分类」按钮(2026-11-19 用户口径:店内分类旁边加个同步按钮)')
|
||||
assert.ok(!page.includes('JD_SHOP_CATEGORY_SNAPSHOT') && !page.includes('jd-shop-category'),
|
||||
'JdCollectTab.vue 不得再消费冻结快照(jd-shop-category.ts 已删除:快照只对取证那一家店正确)')
|
||||
assert.ok(page.includes('采集分类(可选,多选)'),
|
||||
'JdCollectTab.vue 必须以「采集分类(可选,多选)」展示分类块')
|
||||
assert.ok(page.includes('<el-select') && page.includes('multiple'),
|
||||
@@ -81,6 +88,38 @@ test('分类多选来自京麦店内分类快照,平台分组从本页下线',
|
||||
'JdCollectTab.vue 不得再消费平台分组接口(两套「分类」并存必混)')
|
||||
})
|
||||
|
||||
/** 同步按钮的失败分档:busy 是设计内等待(amber notice),登录失效/页面结构变更才是
|
||||
* 红色 error;把 busy 塞进红色 error 即红(与推送失败 notice 通道同口径)。 */
|
||||
test('同步分类失败按 code 分档:busy 走 notice,其余走 error', () => {
|
||||
const page = readIfExists(
|
||||
join(process.cwd(), 'src', 'pages', 'jd', 'JdCollectTab.vue'),
|
||||
'JdCollectTab.vue',
|
||||
)
|
||||
const startAt = page.indexOf('async function syncShopCategories')
|
||||
assert.ok(startAt > 0, 'JdCollectTab.vue 缺 syncShopCategories')
|
||||
const body = page.slice(startAt, page.indexOf('function clearShopCategories'))
|
||||
assert.ok(body.includes("code === 'jd_busy'") && body.includes('noticeMessage.value'),
|
||||
'同步返回 jd_busy 必须走 amber notice(京东任务在跑是设计内等待,不是错误)')
|
||||
assert.ok(body.includes('errorMessage.value = result?.error'),
|
||||
'jd_login/jd_page/未知失败必须走红色 error(京麦未登录要用户去登录)')
|
||||
assert.ok(page.includes('SYNC_UNAVAILABLE_NOTE') && page.includes('升级到最新版'),
|
||||
'无桥/老客户端点同步必须给出升级指引(按钮置灰是第一道,提示文案是兜底)')
|
||||
assert.ok(!page.includes('jd-shop-category'),
|
||||
'同步失败路径不得再回落到冻结快照(快照已删除,回落即编译错)')
|
||||
})
|
||||
|
||||
/** 快照正本退役:选项集不再有仓库内的静态正本文件(每家店不同,写死必错)。 */
|
||||
test('店内分类快照文件已删除,无残留引用', () => {
|
||||
assert.ok(!existsSync(join(process.cwd(), 'src', 'pages', 'jd', 'jd-shop-category.ts')),
|
||||
'jd-shop-category.ts 必须删除(快照只对 2026-11-16 取证那一家店正确)')
|
||||
const bridge = readIfExists(
|
||||
join(process.cwd(), 'src', 'shared', 'bridges', 'pywebview.ts'),
|
||||
'pywebview.ts',
|
||||
)
|
||||
assert.ok(bridge.includes('get_jd_shop_categories'),
|
||||
'pywebview.ts 必须登记 get_jd_shop_categories 桥类型(老客户端无此方法 ⇒ 按钮置灰提示升级)')
|
||||
})
|
||||
|
||||
test('建单请求体与推送载荷都带店内分类双键', () => {
|
||||
const api = readIfExists(
|
||||
join(process.cwd(), 'src', 'shared', 'api', 'types', 'modules', 'jd-collect.ts'),
|
||||
@@ -155,3 +194,26 @@ test('建单后先激活再推客户端队列', () => {
|
||||
assert.ok(activateAt < pushAt,
|
||||
'激活必须排在推送之前(PENDING 状态下推给客户端=分片全被拒)')
|
||||
})
|
||||
|
||||
/** 2026-11-19 用户实录:建单撞上客户端升级重启窗口,推送失败被渲染成红色「推送失败」
|
||||
* 横幅(兜底拉取 2 分钟后照常认领,任务没坏)。推送失败是设计内慢路径不是错误——文案
|
||||
* 改中性动作句、展示走 amber notice 通道,红色 error 只留给真失败(建单/激活失败)。
|
||||
* 把提示改回塞进 errorMessage 即红。 */
|
||||
test('推送失败的兜底提示走 notice 通道,不占红色 error', () => {
|
||||
const page = readIfExists(
|
||||
join(process.cwd(), 'src', 'pages', 'jd', 'JdCollectTab.vue'),
|
||||
'JdCollectTab.vue',
|
||||
)
|
||||
assert.ok(page.includes('PUSH_FALLBACK_NOTE'),
|
||||
'推送失败提示必须收敛到单一常量 PUSH_FALLBACK_NOTE(两分支各写一份会漂)')
|
||||
assert.ok(page.includes('noticeMessage.value = pushError') && page.includes('noticeMessage.value = PUSH_FALLBACK_NOTE'),
|
||||
'推送失败提示必须写进 noticeMessage(amber notice 通道)')
|
||||
const startAt = page.indexOf('async function startCollect')
|
||||
assert.ok(startAt > 0, 'JdCollectTab.vue 缺 startCollect')
|
||||
assert.ok(!page.slice(startAt).includes('errorMessage.value = pushNote'),
|
||||
'startCollect 不得再把推送失败提示塞进红色 error 横幅(errorMessage 只留激活/建单真失败)')
|
||||
assert.ok(page.includes('class="feedback notice"'),
|
||||
'模板必须有 feedback notice 档(amber),红色 error 不得再兜住推送失败')
|
||||
assert.ok(!page.includes('推送本机队列失败,任务将由'), '旧「推送失败」横幅文案必须下线')
|
||||
assert.ok(page.includes('约 1 分钟内自动领取'), '兜底提示必须给出预期时长(约 1 分钟内自动领取)')
|
||||
})
|
||||
|
||||
@@ -1,54 +0,0 @@
|
||||
import { test } from 'node:test'
|
||||
import assert from 'node:assert/strict'
|
||||
import { existsSync, readFileSync } from 'node:fs'
|
||||
import { join } from 'node:path'
|
||||
|
||||
/** 京麦「店内分类」快照契约(2026-11-16 真机取证,建单页采集分类多选的选项集)。
|
||||
*
|
||||
* 快照是纯前端静态数据(getShopCategoryList 的 label/value 对,扁平单层)。判据钉四件:
|
||||
* ① 快照非空且形状齐(label/value 都非空字符串);② label 不重复(多选以 label 下发,
|
||||
* 重名会让客户端过滤语义歧义);③ 取证出处注释在位(后人按原路重抓,防止当它错改);
|
||||
* ④ 建单页消费快照(对手面 jd-collect-tab.test.ts 的发送口断言)。 */
|
||||
|
||||
const SNAPSHOT = join(process.cwd(), 'src', 'pages', 'jd', 'jd-shop-category.ts')
|
||||
|
||||
function readIfExists(path: string, what: string): string {
|
||||
assert.ok(existsSync(path), `${what} 尚未落地:${path}`)
|
||||
return readFileSync(path, 'utf8')
|
||||
}
|
||||
|
||||
test('店内分类快照非空且每项 label/value 齐全', async () => {
|
||||
const mod = await import('../src/pages/jd/jd-shop-category.ts')
|
||||
const { JD_SHOP_CATEGORY_SNAPSHOT } = mod as {
|
||||
JD_SHOP_CATEGORY_SNAPSHOT: { label: string; value: string }[]
|
||||
}
|
||||
assert.ok(Array.isArray(JD_SHOP_CATEGORY_SNAPSHOT) && JD_SHOP_CATEGORY_SNAPSHOT.length > 0,
|
||||
'快照不得为空(2026-11-16 取证 9 个)')
|
||||
for (const item of JD_SHOP_CATEGORY_SNAPSHOT) {
|
||||
assert.ok(typeof item.label === 'string' && item.label.trim().length > 0,
|
||||
`label 必须是非空字符串: ${JSON.stringify(item)}`)
|
||||
assert.ok(typeof item.value === 'string' && item.value.trim().length > 0,
|
||||
`value(京麦分类 id)必须是非空字符串: ${JSON.stringify(item)}`)
|
||||
}
|
||||
})
|
||||
|
||||
test('快照 label 不重复(多选按 label 下发,重名会让过滤语义歧义)', async () => {
|
||||
const mod = await import('../src/pages/jd/jd-shop-category.ts')
|
||||
const { JD_SHOP_CATEGORY_SNAPSHOT } = mod as {
|
||||
JD_SHOP_CATEGORY_SNAPSHOT: { label: string }[]
|
||||
}
|
||||
const labels = JD_SHOP_CATEGORY_SNAPSHOT.map((item) => item.label)
|
||||
assert.equal(new Set(labels).size, labels.length,
|
||||
`label 有重复: ${labels.join(', ')}`)
|
||||
})
|
||||
|
||||
test('取证出处与边界注释在位(防后人当它错改)', () => {
|
||||
const body = readIfExists(SNAPSHOT, 'jd-shop-category.ts')
|
||||
assert.ok(body.includes('getShopCategoryList'),
|
||||
'快照文件必须写明数据来源接口(ShopCategoryReadViewService.getShopCategoryList)')
|
||||
assert.ok(body.includes('2026-11-16'), '快照文件必须带取证日期')
|
||||
assert.ok(body.includes('shopCategorys') || body.includes('shopCategoryPath'),
|
||||
'快照文件必须写明行级过滤键(shopCategorys/shopCategoryPath/groupId)')
|
||||
assert.ok(body.includes('0/450') || body.includes('没给商品挂分类'),
|
||||
'快照文件必须写明「采样店铺 0 商品挂分类」的现状边界(选分类=0 行命中是已知形状)')
|
||||
})
|
||||
@@ -32,6 +32,8 @@ const api = vi.hoisted(() => ({
|
||||
interruptJdCollectTask: vi.fn(),
|
||||
retryClientTask: vi.fn(),
|
||||
enqueue: vi.fn(),
|
||||
// 2026-11-19「同步分类」:选项集正本从冻结快照改为桥实时拉取(每家店的店内分类不同)。
|
||||
syncCategories: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/shared/api/types/modules/jd-collect', () => ({
|
||||
@@ -50,7 +52,7 @@ vi.mock('@/shared/api/task-retry', () => ({
|
||||
retryClientTask: api.retryClientTask,
|
||||
}))
|
||||
vi.mock('@/shared/bridges/pywebview', () => ({
|
||||
getPywebviewApi: () => ({ enqueue_json: api.enqueue }),
|
||||
getPywebviewApi: () => ({ enqueue_json: api.enqueue, get_jd_shop_categories: api.syncCategories }),
|
||||
}))
|
||||
|
||||
const EMPTY_DASHBOARD = {
|
||||
@@ -141,10 +143,29 @@ async function startCollect(w: VueWrapper) {
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
/** 「同步分类」拉回的当前店铺分类样本(label/value 与旧快照同形;顺序=同步序/orderNo)。 */
|
||||
const SYNCED_CATEGORIES = [
|
||||
{ label: '工作制服', value: '1024347567' },
|
||||
{ label: '礼服/演出服', value: '1024347568' },
|
||||
{ label: '拉丁舞服', value: '1024347572' },
|
||||
]
|
||||
|
||||
function syncedResult(over: Record<string, unknown> = {}) {
|
||||
return { success: true, shopName: '花屿巷旗舰店', shopId: '165515933', categories: SYNCED_CATEGORIES, ...over }
|
||||
}
|
||||
|
||||
async function syncCategories(w: VueWrapper) {
|
||||
await w.find('.shop-cat-sync').trigger('click')
|
||||
await flushPromises()
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
localStorage.setItem('username', 'admin')
|
||||
for (const mock of Object.values(api)) mock.mockReset()
|
||||
for (const mock of Object.values(api)) {
|
||||
// 无桥用例会把 syncCategories 覆写成 undefined,这里按可重置性防御(保持全量 reset 语义)。
|
||||
if (typeof (mock as { mockReset?: unknown })?.mockReset === 'function') mock.mockReset()
|
||||
}
|
||||
api.createJdCollectTask.mockResolvedValue({ taskId: 88, taskNo: 'JD-1', collectChannel: 'LOCAL' })
|
||||
api.activateJdCollectTask.mockResolvedValue(null)
|
||||
api.fetchJdCollectCategories.mockResolvedValue([])
|
||||
@@ -305,13 +326,47 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
expect(w.find('.feedback.error').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('推送本机队列失败:走 amber notice 提示(不占红色 error),建单与轮询照常', async () => {
|
||||
// 2026-11-19 用户实录:建单撞上客户端升级重启窗口,推送失败被渲染成红色「推送失败」
|
||||
// 横幅;实为设计内兜底慢路径(客户端 60 秒一轮 pull-pending 自动认领,最多晚约 1
|
||||
// 分钟)。桥返回失败必须按提示展示,红色 error 只留给真失败(建单/激活失败)。
|
||||
api.enqueue.mockResolvedValue({ success: false, error: 'queue is closing' })
|
||||
const w = await mountPage()
|
||||
await startCollect(w)
|
||||
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledTimes(1)
|
||||
const notice = w.find('.feedback.notice')
|
||||
expect(notice.exists()).toBe(true)
|
||||
expect(notice.text()).toContain('任务已创建')
|
||||
expect(notice.text()).toContain('自动领取')
|
||||
expect(notice.text()).not.toContain('失败')
|
||||
expect(w.find('.feedback.error').exists()).toBe(false)
|
||||
// 建单成功即进轮询:兜底拉取认领后进度照常上屏
|
||||
expect(api.fetchJdCollectTaskProgressBatch).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('推送抛异常:同样走 notice 提示、不回滚建单', async () => {
|
||||
api.enqueue.mockRejectedValue(new Error('bridge gone'))
|
||||
const w = await mountPage()
|
||||
await startCollect(w)
|
||||
|
||||
const notice = w.find('.feedback.notice')
|
||||
expect(notice.exists()).toBe(true)
|
||||
expect(notice.text()).toContain('自动领取')
|
||||
expect(notice.text()).not.toContain('失败')
|
||||
expect(w.find('.feedback.error').exists()).toBe(false)
|
||||
expect(api.fetchJdCollectTaskProgressBatch).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('下拉选分类后建单:店内分类双键随建单请求体与推送载荷同链下发', async () => {
|
||||
// 2026-11-16 客户口径「类目不需要只要分类」「选京麦的内部分类去采集」;
|
||||
// 2026-11-17 客户口径「不要全展示出来,弄个下拉式多选」:checkbox 列表换 el-select
|
||||
// 多选(collapse-tags)。选项集=京麦「店内分类」快照(jd-shop-category.ts,取证 9 个),
|
||||
// 选择模型是 id 数组;建单请求体与推送载荷带 label+id 双键、按快照原序反查(行级填充
|
||||
// 形状未取证,客户端任一键命中即命中)——选中项用快照真实行,贴合下发形状。
|
||||
// 2026-11-17 客户口径「不要全展示出来,弄个下拉式多选」;2026-11-19 选项集改
|
||||
// 「同步分类」桥实时拉取(每家店的店内分类名字与 id 都不同,冻结快照已退役)。
|
||||
// 建单请求体与推送载荷带 label+id 双键、按选项集原序反查(行级填充形状未取证,
|
||||
// 客户端任一键命中即命中)——选中项用同步样本真实行,贴合下发形状。
|
||||
api.syncCategories.mockResolvedValue(syncedResult())
|
||||
const w = await mountPage(true)
|
||||
await syncCategories(w)
|
||||
|
||||
const select = w.findComponent(ElSelect)
|
||||
expect(select.exists(), '采集分类必须是下拉多选(el-select),不再是逐条复选框').toBe(true)
|
||||
@@ -320,7 +375,7 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
|
||||
await startCollect(w)
|
||||
|
||||
// 双键顺序恒等于快照序(工作制服在前),与点选先后无关——同源反查,不随 UI 顺序漂。
|
||||
// 双键顺序恒等于选项集序(工作制服在前),与点选先后无关——同源反查,不随 UI 顺序漂。
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, [],
|
||||
['工作制服', '拉丁舞服'], ['1024347567', '1024347572'])
|
||||
const payload = api.enqueue.mock.calls[0][0]
|
||||
@@ -334,26 +389,103 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
})
|
||||
})
|
||||
|
||||
it('采集分类块:下拉渲染快照全量选项并可清空(恢复全店采集)', async () => {
|
||||
it('同步分类成功:选项集换成当前店铺实时分类并显示店铺名(不再是 9 个冻结快照)', async () => {
|
||||
const w = await mountPage(true)
|
||||
|
||||
const block = w.findAll('.category-block').find((el) => el.text().includes('采集分类'))
|
||||
expect(block, '必须有「采集分类(可选,多选)」块').toBeTruthy()
|
||||
expect(block!.text()).toContain('采集分类(可选,多选)')
|
||||
// 快照 9 项全进下拉选项(客户端「能看见管理员/商家建的分类」口径落点就在这;
|
||||
// 弹层 teleport 到 body,选项组件仍挂在页面组件树里,按组件计数不按 DOM)
|
||||
expect(w.findAllComponents(ElOption).length).toBe(9)
|
||||
expect(block!.find('.shop-cat-select').exists(), '分类块必须是 el-select 下拉').toBe(true)
|
||||
expect(block!.text()).toContain('默认全店采集')
|
||||
// 未同步:选项集为空(不预置任何快照),提示指向「同步分类」;空选=全店采集。
|
||||
expect(w.findAllComponents(ElOption).length).toBe(0)
|
||||
expect(block!.text()).toContain('未同步或空选=全店采集')
|
||||
expect(block!.text()).not.toContain('2026-11-16 快照')
|
||||
expect(block!.findComponent(ElSelect).props('placeholder')).toBe('全店采集(点击选择分类)')
|
||||
|
||||
const select = block!.findComponent(ElSelect)
|
||||
await select.vm.$emit('update:modelValue', ['1024347567'])
|
||||
api.syncCategories.mockResolvedValue(syncedResult())
|
||||
await syncCategories(w)
|
||||
|
||||
expect(w.findAllComponents(ElOption).length).toBe(SYNCED_CATEGORIES.length,
|
||||
'选项集必须等于桥拉回的当前店铺分类,不是冻结快照的 9 个')
|
||||
expect(block!.text()).toContain('已同步店铺「花屿巷旗舰店」:3 个分类')
|
||||
expect(block!.text()).not.toContain('未同步')
|
||||
// 按钮回到可再同步态(店铺侧改了分类可随时重拉)
|
||||
const syncBtn = w.find('.shop-cat-sync')
|
||||
expect(syncBtn.text()).toBe('同步分类')
|
||||
expect(syncBtn.attributes('disabled')).toBeUndefined()
|
||||
})
|
||||
|
||||
it('同步失败 jd_busy:京东任务在跑是设计内等待,走 amber notice 不占红色 error', async () => {
|
||||
api.syncCategories.mockResolvedValue(
|
||||
syncedResult({ success: false, code: 'jd_busy', error: '京东采集/发布任务正在运行,请等任务结束后再同步分类' }))
|
||||
const w = await mountPage(true)
|
||||
await syncCategories(w)
|
||||
|
||||
const notice = w.find('.feedback.notice')
|
||||
expect(notice.exists()).toBe(true)
|
||||
expect(notice.text()).toContain('任务正在运行')
|
||||
expect(w.find('.feedback.error').exists()).toBe(false)
|
||||
// 分类照常未同步:选项集仍空(busy 后不得回落假数据)
|
||||
expect(w.findAllComponents(ElOption).length).toBe(0)
|
||||
})
|
||||
|
||||
it('同步失败 jd_login:京麦未登录要用户去登录,走红色 error', async () => {
|
||||
api.syncCategories.mockResolvedValue(
|
||||
syncedResult({ success: false, code: 'jd_login', error: '京麦未登录(登录态失效),请先在客户端登录京麦' }))
|
||||
const w = await mountPage(true)
|
||||
await syncCategories(w)
|
||||
|
||||
const error = w.find('.feedback.error')
|
||||
expect(error.exists()).toBe(true)
|
||||
expect(error.text()).toContain('京麦未登录')
|
||||
expect(w.find('.feedback.notice').exists()).toBe(false)
|
||||
expect(w.findAllComponents(ElOption).length).toBe(0)
|
||||
})
|
||||
|
||||
it('老客户端无同步桥:按钮置灰,全店采集不受影响', async () => {
|
||||
const originalSync = api.syncCategories
|
||||
api.syncCategories = undefined as unknown as typeof api.syncCategories
|
||||
try {
|
||||
const w = await mountPage(true)
|
||||
await flushPromises()
|
||||
|
||||
const syncBtn = w.find('.shop-cat-sync')
|
||||
expect(syncBtn.exists()).toBe(true)
|
||||
// 桥上没有 get_jd_shop_categories(老客户端/浏览器打开)⇒ 按钮置灰,
|
||||
// 用户根本点不到(无桥提示 SYNC_UNAVAILABLE_NOTE 的形状由 jd-collect-tab 纯测试钉住)
|
||||
expect(syncBtn.attributes('disabled')).toBeDefined()
|
||||
expect(w.findAllComponents(ElOption).length).toBe(0)
|
||||
// 全店采集主链路不依赖分类:建单双键空数组照常
|
||||
await startCollect(w)
|
||||
expect(api.createJdCollectTask).toHaveBeenCalledWith('京麦后台', ['ONSALE', 'OFFSALE'], 0, [], [], [])
|
||||
} finally {
|
||||
// 覆写必须还原:hoisted 对象的 undefined 会穿过 beforeEach 的 mockReset 泄漏到后续用例
|
||||
api.syncCategories = originalSync
|
||||
}
|
||||
})
|
||||
|
||||
it('重同步换店:清掉不属于当前店铺的已选分类,防止跨店 id 误过滤', async () => {
|
||||
api.syncCategories.mockResolvedValue(syncedResult())
|
||||
const w = await mountPage(true)
|
||||
await syncCategories(w)
|
||||
const select = w.findComponent(ElSelect)
|
||||
await select.vm.$emit('update:modelValue', ['1024347567', '1024347572'])
|
||||
await flushPromises()
|
||||
expect(block!.text()).toContain('只采选中 1 个分类的商品')
|
||||
expect(block!.find('.shop-cat-clear').exists(), '选中后出「清空」').toBe(true)
|
||||
await block!.find('.shop-cat-clear').trigger('click')
|
||||
await flushPromises()
|
||||
expect(block!.text()).toContain('默认全店采集')
|
||||
|
||||
// 换了一家店:新分类集与旧店 id 无交集 ⇒ 旧已选项必须被清掉并告知
|
||||
api.syncCategories.mockResolvedValue(syncedResult({
|
||||
shopName: '另一家旗舰店',
|
||||
categories: [
|
||||
{ label: '男士上衣', value: '9900000001' },
|
||||
{ label: '其他', value: '9900000002' },
|
||||
],
|
||||
}))
|
||||
await syncCategories(w)
|
||||
|
||||
expect(w.text()).toContain('清除了 2 个不属于当前店铺的已选项')
|
||||
expect(w.findAllComponents(ElOption).length).toBe(2)
|
||||
await startCollect(w)
|
||||
const payload = api.enqueue.mock.calls[0][0]
|
||||
// 跨店残留 id 不得进建单请求体(否则按另一家店的分类过滤,0 行命中)
|
||||
expect(payload.data.shopCategoryIds).toEqual([])
|
||||
expect(payload.data.shopCategoryNames).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user