Files
crawler-plugin/admin-frontend-vue/tests/mount/query-asin-batch-delete.mount.test.ts
T

46 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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()
})