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
@@ -0,0 +1,45 @@
import { beforeEach, expect, it, vi } from 'vitest'
import { flushPromises, mount } from '@vue/test-utils'
import { createPinia, setActivePinia } from 'pinia'
import QueryAsinPage from '@/pages/asin/QueryAsinPage.vue'
import { useAdminSessionStore } from '@/stores/admin-session'
const api = vi.hoisted(() => ({
fetchQueryAsinList: vi.fn(),
deleteQueryAsinCountryAsin: vi.fn(),
openAdminConfirm: vi.fn(),
}))
vi.mock('@/pages/asin/query-asin-api.ts', () => ({ ...api, createQueryAsin: vi.fn(), fetchShopNamesByGroup: vi.fn() }))
vi.mock('@/pages/asin/query-asin-detail-api.ts', () => ({ ...api, updateQueryAsinCountryAsin: vi.fn() }))
vi.mock('@/pages/shop/shop-manage-api.ts', () => ({ fetchShopManageGroups: vi.fn().mockResolvedValue([]) }))
vi.mock('@/components/admin-confirm', () => ({ openAdminConfirm: api.openAdminConfirm }))
beforeEach(() => {
vi.resetAllMocks()
setActivePinia(createPinia())
useAdminSessionStore().user = { id: 1, username: 'root', role: 'super_admin' }
})
it('多站点店铺只占一个勾选;部分站点失败时,重试不重删成功站点', async () => {
const shop = { id: 7, shopName: '甲店', groupName: '甲组', asinDe: 'B000000001', asinUk: 'B000000002' }
api.fetchQueryAsinList.mockResolvedValue({ page: 1, total: 1, items: [shop] })
api.deleteQueryAsinCountryAsin.mockResolvedValueOnce(undefined).mockRejectedValueOnce(new Error('暂时无法删除英国站'))
api.openAdminConfirm.mockResolvedValue(true)
const wrapper = mount(QueryAsinPage, { global: { stubs: ['el-select', 'el-option', 'el-dialog', 'el-drawer', 'el-progress'] } })
await flushPromises()
expect(wrapper.findAll('tbody .batch-delete-checkbox')).toHaveLength(1)
expect(wrapper.get('tbody .batch-delete-cell').attributes('rowspan')).toBe('2')
await wrapper.get('thead .batch-delete-checkbox').setValue(true)
const button = wrapper.get('.batch-delete-actions .btn-danger')
expect(button.text()).toBe('批量删除(1)')
await button.trigger('click')
await flushPromises()
expect(api.openAdminConfirm).toHaveBeenCalledWith(expect.objectContaining({ message: expect.stringContaining('全部站点') }))
expect(api.deleteQueryAsinCountryAsin.mock.calls).toEqual([[7, 'DE'], [7, 'UK']])
expect(wrapper.get('details').text()).toContain('暂时无法删除英国站')
await button.trigger('click')
await flushPromises()
expect(api.deleteQueryAsinCountryAsin.mock.calls).toEqual([[7, 'DE'], [7, 'UK'], [7, 'UK']])
expect(button.text()).toBe('批量删除(0)')
wrapper.unmount()
})