Files
admin-web/src/shared/components/exportTaskCreatedDialog.test.ts
T
2026-09-15 09:58:15 +08:00

31 lines
1.5 KiB
TypeScript

import { ElMessageBox } from 'element-plus'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import { showExportTaskCreatedDialog } from './exportTaskCreatedDialog'
describe('showExportTaskCreatedDialog', () => {
beforeEach(() => vi.restoreAllMocks())
it('offers a direct path to the download center with the task reference', async () => {
const confirm = vi.spyOn(ElMessageBox, 'confirm').mockResolvedValue({} as never)
await expect(showExportTaskCreatedDialog({ taskName: '客户列表', taskNo: 'EXP2084' })).resolves.toBe(true)
expect(confirm).toHaveBeenCalledWith(
expect.stringContaining('任务编号:EXP2084'),
'导出任务已创建',
expect.objectContaining({ confirmButtonText: '前往下载中心', cancelButtonText: '留在当前页' }),
)
})
it.each([false, true])('opts into the shared dialog style explicitly: %s', async (dense) => {
const confirm = vi.spyOn(ElMessageBox, 'confirm').mockResolvedValue({} as never)
await showExportTaskCreatedDialog({ taskName: '财务导出', dense })
expect(confirm).toHaveBeenCalledWith(expect.any(String), '导出任务已创建', expect.objectContaining({ customClass: dense ? 'admin-density-confirm' : undefined }))
})
it('keeps the user on the current page when the dialog is dismissed', async () => {
vi.spyOn(ElMessageBox, 'confirm').mockRejectedValue('cancel')
await expect(showExportTaskCreatedDialog({ taskName: '客户列表' })).resolves.toBe(false)
})
})