feat(admin): 为支持单删的管理列表补齐批量删除

This commit is contained in:
2026-11-20 12:08:28 +08:00
parent 132c19d51f
commit 51c41b238a
43 changed files with 2806 additions and 1948 deletions
@@ -21,6 +21,8 @@ const usersApi = vi.hoisted(() => ({
}))
vi.mock('@/api/users', () => usersApi)
const confirmBatch = vi.hoisted(() => vi.fn())
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: confirmBatch }))
vi.mock('@/api/companies', () => ({ fetchCompanies: vi.fn().mockResolvedValue([]) }))
vi.mock('@/pages/account/user-menu-auth-api', () => ({ loadUserMenuAuth: vi.fn() }))
@@ -48,6 +50,45 @@ beforeEach(() => {
const session = useAdminSessionStore()
session.user = { id: 1, username: 'root', role: 'super_admin' }
usersApi.fetchUserList.mockResolvedValue(pageOf())
usersApi.deleteUser.mockReset().mockResolvedValue(undefined)
confirmBatch.mockReset().mockResolvedValue(false)
})
it('批量删除取消不发请求;部分失败只保留失败用户', async () => {
usersApi.deleteUser.mockRejectedValueOnce(new Error('无权删除此用户'))
const wrapper = mount(UsersPage)
await flushPromises()
const button = wrapper.get('.batch-delete-actions .btn-danger')
expect(button.attributes('disabled')).toBeDefined()
await wrapper.get('input[aria-label="选择 京东号"]').setValue(true)
await wrapper.get('input[aria-label="选择 存量号"]').setValue(true)
await button.trigger('click')
await flushPromises()
expect(confirmBatch).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('京东号、存量号') }))
expect(usersApi.deleteUser).not.toHaveBeenCalled()
confirmBatch.mockResolvedValue(true)
await button.trigger('click')
await flushPromises()
expect(usersApi.deleteUser.mock.calls).toEqual([[7], [8]])
expect(button.text()).toBe('批量删除(1)')
expect(wrapper.get('details').text()).toContain('京东号:无权删除此用户')
expect(usersApi.fetchUserList).toHaveBeenCalledTimes(2)
wrapper.unmount()
})
it('确认弹窗期间切平台,旧勾选不发删除请求', async () => {
let resolveConfirm!: (ok: boolean) => void
confirmBatch.mockReturnValue(new Promise<boolean>((resolve) => { resolveConfirm = resolve }))
const wrapper = mount(UsersPage)
await flushPromises()
await wrapper.get('input[aria-label="选择 京东号"]').setValue(true)
await wrapper.get('.batch-delete-actions .btn-danger').trigger('click')
usePlatformTabStore().setActive('jd')
resolveConfirm(true)
await flushPromises()
expect(usersApi.deleteUser).not.toHaveBeenCalled()
expect(wrapper.get('.batch-delete-actions .btn-danger').text()).toBe('批量删除(0)')
wrapper.unmount()
})
describe('UsersPage × 平台 tab(V206)', () => {
@@ -60,8 +101,8 @@ describe('UsersPage × 平台 tab(V206)', () => {
expect(params).toHaveProperty('companyId')
const headers = wrapper.findAll('thead th').map((th) => th.text())
expect(headers).not.toContain('上架上限')
// 亚马逊侧表头 9 列(存量表头,quota 列不渲染)
expect(headers.length).toBe(9)
// 亚马逊侧保留原有 9 列,另加 1 列批量选择。
expect(headers.length).toBe(10)
wrapper.unmount()
})
@@ -78,12 +119,11 @@ describe('UsersPage × 平台 tab(V206)', () => {
const headers = wrapper.findAll('thead th').map((th) => th.text())
expect(headers).toContain('上架上限')
expect(headers.length).toBe(10)
expect(headers.length).toBe(11)
// quota 单元格:0=不限(存量号 8),null/缺省=-(京东号 7、没配号 10),800 原样
const quotaCells = wrapper.findAll('tbody tr').map((tr) => {
const tds = tr.findAll('td')
// 上架上限列在第 5 列(ID/用户名/角色/所属管理员/到期时间 之后)
return tds[5]?.text()
return tds[6]?.text()
})
expect(quotaCells).toEqual(['-', '不限', '800', '-'])
wrapper.unmount()