feat(jd): 「登录京麦」按钮退役改懒触发自动登录链+进度分母未知走不确定态+FAILED 归历史区(2026-11-23 客户三条口径)
1. **京麦登录自动化**(客户口径「登录能不能自动化的识别,登录按钮不要了」): 新 shared/stores/jd-login-autoflow.ts——京麦登录态探测要起有头浏览器,常态化探测 每次进页闪窗口 ⇒ 懒触发:会话内任一路(同步分类 jd_login/任务致命公告 CredentialFatalAlert kind=jd_login)发现未登录即置旗;此后建单/重试前 passJdLoginGate 预检,旗置位时自动开登录窗、登录成功才放行(重试闸排在复位**之前** ——复位成功即 PENDING,预检拦下却没人领=任务挂死);busy 档 8 秒自动重试一次; 同步分类登录成功后自动重拉(fromAutoLogin 防递归)。open_jd_login 桥与客户端 login_window.py 原样复用,app_client 零改动。 2. **进度条不确定态**:在跑但 totalCount 读不出(分类筛选未生效走行级兜底翻页)时 TaskItemCard 进度条走流动条纹,计数文案点名「总量未知,按页累计」——0% 空轨道 看着像坏了。 3. **FAILED 归历史任务区**(11-23 拍板,推翻 11-22「失败是当前区待办」): CURRENT_AREA_STATUSES 摘掉 FAILED——重试/删除按钮在历史行同形槽不丢,失败单堆当前区 反而看不清在跑的。 判据:jd-login-autoflow.test.ts(store 分档+重试语义)+jd-collect-tab.test.ts 改反钉 (按钮/状态机复活即红、预检位置绊线)+mount 51 支(旗隔离 resetJdLoginAutoflowForTest 防串用例、jd_login 自动开窗、indeterminate 断言)。
This commit is contained in:
@@ -17,6 +17,7 @@ import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
||||
import ElementPlus, { ElOption, ElSelect } from 'element-plus'
|
||||
|
||||
import JdCollectTab from '@/pages/jd/JdCollectTab.vue'
|
||||
import { resetJdLoginAutoflowForTest } from '@/shared/stores/jd-login-autoflow'
|
||||
|
||||
const api = vi.hoisted(() => ({
|
||||
createJdCollectTask: vi.fn(),
|
||||
@@ -34,6 +35,8 @@ const api = vi.hoisted(() => ({
|
||||
enqueue: vi.fn(),
|
||||
// 2026-11-19「同步分类」:选项集正本从冻结快照改为桥实时拉取(每家店的店内分类不同)。
|
||||
syncCategories: vi.fn(),
|
||||
// 2026-11-23「登录京麦」按钮退役:jd_login 自动开登录窗走桥 open_jd_login(autoflow 闸)。
|
||||
openJdLogin: vi.fn(),
|
||||
}))
|
||||
|
||||
vi.mock('@/shared/api/types/modules/jd-collect', () => ({
|
||||
@@ -52,7 +55,11 @@ vi.mock('@/shared/api/task-retry', () => ({
|
||||
retryClientTask: api.retryClientTask,
|
||||
}))
|
||||
vi.mock('@/shared/bridges/pywebview', () => ({
|
||||
getPywebviewApi: () => ({ enqueue_json: api.enqueue, get_jd_shop_categories: api.syncCategories }),
|
||||
getPywebviewApi: () => ({
|
||||
enqueue_json: api.enqueue,
|
||||
get_jd_shop_categories: api.syncCategories,
|
||||
open_jd_login: api.openJdLogin,
|
||||
}),
|
||||
}))
|
||||
|
||||
const EMPTY_DASHBOARD = {
|
||||
@@ -157,8 +164,8 @@ function syncedResult(over: Record<string, unknown> = {}) {
|
||||
}
|
||||
|
||||
async function syncCategories(w: VueWrapper) {
|
||||
// 2026-11-20 起同一样式类下有两个按钮:「登录京麦」在前、「同步分类」在后;
|
||||
// 按文案取,别再拿 find('.shop-cat-sync') 点第一个(点到登录按钮=同步根本没跑)。
|
||||
// 2026-11-23 起「登录京麦」按钮退役,.shop-cat-sync 只剩「同步分类」一个;
|
||||
// 按文案取仍是最稳的定位(将来再加按钮也不会点错)。
|
||||
const syncBtn = w.findAll('.shop-cat-sync').find((btn) => btn.text().includes('同步分类'))
|
||||
if (!syncBtn) throw new Error('页面缺「同步分类」按钮')
|
||||
await syncBtn.trigger('click')
|
||||
@@ -168,6 +175,8 @@ async function syncCategories(w: VueWrapper) {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers()
|
||||
localStorage.setItem('username', 'admin')
|
||||
// 会话旗是模块级单例:jd_login 用例置过旗会泄漏进后续用例的建单预检(误开登录窗)。
|
||||
resetJdLoginAutoflowForTest()
|
||||
for (const mock of Object.values(api)) {
|
||||
// 无桥用例会把 syncCategories 覆写成 undefined,这里按可重置性防御(保持全量 reset 语义)。
|
||||
if (typeof (mock as { mockReset?: unknown })?.mockReset === 'function') mock.mockReset()
|
||||
@@ -280,8 +289,12 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
const meta = w.find('.file-progress-meta')
|
||||
expect(meta.exists()).toBe(true)
|
||||
expect(meta.text()).toContain('已采集 30 个商品')
|
||||
expect(meta.text()).toContain('总量未知')
|
||||
expect(meta.text()).not.toContain('%')
|
||||
expect(w.find('.file-progress-bar').attributes('style')).toContain('width: 0%')
|
||||
// 分母未知 + 在跑:进度条走不确定态流动条纹(宽度不再按 percent 摆成 0% 空轨道)。
|
||||
const bar = w.find('.file-progress-bar')
|
||||
expect(bar.classes()).toContain('indeterminate')
|
||||
expect(bar.attributes('style') ?? '').not.toContain('width')
|
||||
})
|
||||
|
||||
it('0 行且无分母时报进行时文案,不把「已采集 0 个商品」挂出来像卡死(35089 误删实录)', async () => {
|
||||
@@ -527,16 +540,36 @@ describe('获取店铺数据:一键采集 + 任务面板', () => {
|
||||
expect(w.findAllComponents(ElOption).length).toBe(0)
|
||||
})
|
||||
|
||||
it('同步失败 jd_login:京麦未登录要用户去登录,走红色 error', async () => {
|
||||
api.syncCategories.mockResolvedValue(
|
||||
syncedResult({ success: false, code: 'jd_login', error: '京麦未登录(登录态失效),请先在客户端登录京麦' }))
|
||||
it('同步失败 jd_login:自动开京麦登录窗,登录成功后自动重拉分类(登录按钮已退役)', async () => {
|
||||
// 第一次同步回 jd_login ⇒ 自动开登录窗(already_logged_in 秒回)⇒ 自动重拉第二次成功。
|
||||
api.syncCategories
|
||||
.mockResolvedValueOnce(syncedResult({ success: false, code: 'jd_login',
|
||||
error: '京麦未登录(登录态失效),请先在客户端登录京麦' }))
|
||||
.mockResolvedValueOnce(syncedResult())
|
||||
api.openJdLogin.mockResolvedValue({ success: true, code: 'already_logged_in', message: '京麦已是登录状态' })
|
||||
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(api.openJdLogin).toHaveBeenCalledTimes(1)
|
||||
expect(api.syncCategories).toHaveBeenCalledTimes(2, '登录成功后必须自动重拉一次分类(闭环,不劳用户再点)')
|
||||
expect(w.findAllComponents(ElOption).length).toBe(SYNCED_CATEGORIES.length)
|
||||
expect(w.find('.feedback.error').exists()).toBe(false)
|
||||
})
|
||||
|
||||
it('同步失败 jd_login 且登录未完成:amber 提示等登录,不递归开窗不假同步', async () => {
|
||||
// 超时档(窗口仍开着等人工登录):只提示、不重拉——用户登完再点同步/获取。
|
||||
api.syncCategories.mockResolvedValue(
|
||||
syncedResult({ success: false, code: 'jd_login', error: '京麦未登录(登录态失效),请先在客户端登录京麦' }))
|
||||
api.openJdLogin.mockResolvedValue({ success: false, code: 'timeout', 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)
|
||||
expect(api.openJdLogin).toHaveBeenCalledTimes(1)
|
||||
expect(api.syncCategories).toHaveBeenCalledTimes(1, '登录未完成不得自动重拉(再拉还是 jd_login)')
|
||||
expect(w.findAllComponents(ElOption).length).toBe(0)
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user