49 lines
3.8 KiB
TypeScript
49 lines
3.8 KiB
TypeScript
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|||
|
|
import { readFileSync } from 'node:fs'
|
||
|
|
import { createPlatformExportTask } from './api/platformExportTasks'
|
||
|
|
import { showExportTaskCreatedDialog } from '@/shared/components/exportTaskCreatedDialog'
|
||
|
|
import { useExportTask } from './useExportTask'
|
||
|
|
|
||
|
|
const { push } = vi.hoisted(() => ({ push: vi.fn() }))
|
||
|
|
vi.mock('vue-router', () => ({ useRouter: () => ({ push }) }))
|
||
|
|
vi.mock('./api/platformExportTasks', () => ({ createPlatformExportTask: vi.fn() }))
|
||
|
|
vi.mock('@/shared/components/exportTaskCreatedDialog', () => ({ showExportTaskCreatedDialog: vi.fn() }))
|
||
|
|
beforeEach(() => {
|
||
|
|
vi.clearAllMocks()
|
||
|
|
vi.mocked(createPlatformExportTask).mockResolvedValue({ taskNo: 'EXP-1' } as Awaited<ReturnType<typeof createPlatformExportTask>>)
|
||
|
|
vi.mocked(showExportTaskCreatedDialog).mockResolvedValue(false)
|
||
|
|
})
|
||
|
|
|
||
|
|
describe('download center export submission', () => {
|
||
|
|
it('exports all matching rows and preserves false, zero, stage and business filters', async () => {
|
||
|
|
const filters = { page: 3, size: 20, detained: false, count: 0, orderNo: '', warehouse: undefined, sailingStage: 'BEFORE_DEPARTURE', relabelNo: 'RL-1' }
|
||
|
|
await useExportTask()('LAST_MILE_ORDER_LIST', '尾程订单', filters)
|
||
|
|
expect(createPlatformExportTask).toHaveBeenCalledWith({ exportType: 'LAST_MILE_ORDER_LIST', taskName: '尾程订单', format: 'XLSX',
|
||
|
|
parameters: { detained: false, count: 0, sailingStage: 'BEFORE_DEPARTURE', relabelNo: 'RL-1' } })
|
||
|
|
expect(filters.page).toBe(3)
|
||
|
|
expect(showExportTaskCreatedDialog).toHaveBeenCalledWith({ taskName: '尾程订单', taskNo: 'EXP-1', dense: true })
|
||
|
|
expect(push).not.toHaveBeenCalled()
|
||
|
|
})
|
||
|
|
it('opens the download center only after the user chooses it', async () => {
|
||
|
|
vi.mocked(showExportTaskCreatedDialog).mockResolvedValue(true)
|
||
|
|
await useExportTask()('VEHICLE_LIST', '车辆', {})
|
||
|
|
expect(push).toHaveBeenCalledWith({ name: 'download-center' })
|
||
|
|
})
|
||
|
|
it('preserves submission failure diagnostics without a success prompt or navigation', async () => {
|
||
|
|
const error = { message: '无导出权限', requestId: 'export-request' }
|
||
|
|
vi.mocked(createPlatformExportTask).mockRejectedValue(error)
|
||
|
|
await expect(useExportTask()('VEHICLE_LIST', '车辆', {})).rejects.toBe(error)
|
||
|
|
expect(showExportTaskCreatedDialog).not.toHaveBeenCalled()
|
||
|
|
expect(push).not.toHaveBeenCalled()
|
||
|
|
})
|
||
|
|
it.each([["overseas-warehouse/pages/LastMileOrdersView.vue","LAST_MILE_ORDER_LIST","platform:overseas-warehouse:last-mile-order:export"],["overseas-warehouse/pages/InventoryView.vue","OVERSEAS_INVENTORY_BALANCE","platform:overseas-warehouse:inventory:export"],["overseas-warehouse/pages/InventoryTransactionsView.vue","OVERSEAS_INVENTORY_LEDGER","platform:overseas-warehouse:inventory:export"],["overseas-master-data/pages/OverseasQuotesView.vue","OVERSEAS_QUOTE_LIST","platform:overseas-master-data:quote:export"],["overseas-master-data/pages/ExchangeRatesView.vue","MONTHLY_EXCHANGE_RATE_LIST","platform:overseas-master-data:exchange-rate:export"],["overseas-master-data/pages/VehiclesView.vue","VEHICLE_LIST","platform:overseas-master-data:vehicle:export"],["overseas-master-data/pages/FleetQuotesView.vue","FLEET_QUOTE_LIST","platform:fleet:quote:export"],["overseas-master-data/pages/TripOperationsView.vue","TRIP_OPERATIONS_LIST","platform:fleet:operations:export"]])('connects %s with the correct type and download-center retry permission', (path, type, permission) => {
|
||
|
|
const page = readFileSync(new URL('../' + path, import.meta.url), 'utf8')
|
||
|
|
expect(page).toContain("await submitExport('" + type + "'")
|
||
|
|
expect(page).not.toMatch(/saveCsv\(|saveFleetCsv\(/)
|
||
|
|
const center = readFileSync('src/modules/downloads/pages/DownloadCenterView.vue', 'utf8')
|
||
|
|
expect(center).toContain(type + ": { label:")
|
||
|
|
expect(center).toContain("retryPermission: '" + permission + "'")
|
||
|
|
})
|
||
|
|
})
|
||
|
|
|