2026-08-29 10:19:35 +08:00
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
|
|
|
import ElementPlus from 'element-plus'
|
|
|
|
|
import { ApiResponseError } from '@/shared/api/http'
|
|
|
|
|
import type { ContainerCustomsStatus, ContainerCustomsView } from '../api/platformContainerCustoms'
|
2026-08-28 16:54:02 +08:00
|
|
|
|
2026-08-29 10:19:35 +08:00
|
|
|
const api = vi.hoisted(() => ({
|
|
|
|
|
get: vi.fn(),
|
|
|
|
|
start: vi.fn(),
|
|
|
|
|
completeAllBuy: vi.fn(),
|
|
|
|
|
upload: vi.fn(),
|
|
|
|
|
downloadSource: vi.fn(),
|
|
|
|
|
downloadCompletion: vi.fn(),
|
|
|
|
|
}))
|
2026-08-28 16:54:02 +08:00
|
|
|
|
2026-08-29 10:19:35 +08:00
|
|
|
vi.mock('../api/platformContainerCustoms', () => ({
|
|
|
|
|
getContainerCustoms: api.get,
|
|
|
|
|
startContainerCustoms: api.start,
|
|
|
|
|
completeAllBuyContainerCustoms: api.completeAllBuy,
|
|
|
|
|
uploadContainerCustomsCompletion: api.upload,
|
|
|
|
|
downloadContainerCustomsDocument: api.downloadSource,
|
|
|
|
|
downloadContainerCustomsCompletion: api.downloadCompletion,
|
|
|
|
|
}))
|
|
|
|
|
vi.mock('@/modules/downloads', () => ({ createPlatformExportTask: vi.fn() }))
|
|
|
|
|
|
|
|
|
|
import ContainerCustomsPanel from './ContainerCustomsPanel.vue'
|
|
|
|
|
|
|
|
|
|
function customs(status: ContainerCustomsStatus, hasCompletion = false): ContainerCustomsView {
|
|
|
|
|
return {
|
|
|
|
|
aggregateId: '2092438843630391401', loadingPlanId: '2092438843630391402', containerBookingId: '2092438843630391403',
|
|
|
|
|
planNo: 'LP-1', cabinetNo: 'MCR08290001', containerNo: 'MSCU-1', status, version: 3, taxRefundCount: 1, coveredTaxRefundCount: 1,
|
|
|
|
|
inbounds: [{ inboundId: '2092438843630391404', orderId: '2092438843630391405', orderNo: 'O-1', inboundCode: 'RK-1', tenantId: '2092438843630391406', customerName: '客户一', taxMode: 'TAX_REFUND', covered: true }],
|
|
|
|
|
documents: [{
|
|
|
|
|
documentId: '2092438843630391407', tenantId: '2092438843630391406',
|
|
|
|
|
source: { fileId: '2092438843630391408', fileName: '客户退税资料.pdf', fileHash: 'source-hash', sizeBytes: 12, version: 2, uploadedAt: '2026-08-29T10:00:00' },
|
|
|
|
|
inboundIds: ['2092438843630391404'], inboundCodes: ['RK-1'], frozen: true,
|
|
|
|
|
completion: hasCompletion ? { fileId: '2092438843630391409', fileName: '报关完成文件.pdf', fileHash: 'completion-hash', sizeBytes: 13, version: 1, uploadedAt: '2026-08-29T11:00:00' } : null,
|
|
|
|
|
}],
|
|
|
|
|
startedAt: status === 'DECLARING' || status === 'COMPLETED' ? '2026-08-29T10:30:00' : null,
|
|
|
|
|
completedAt: status === 'COMPLETED' ? '2026-08-29T11:30:00' : null,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function render(status: ContainerCustomsStatus, canManage = true, hasCompletion = false) {
|
|
|
|
|
api.get.mockResolvedValue(customs(status, hasCompletion))
|
|
|
|
|
const wrapper = mount(ContainerCustomsPanel, {
|
|
|
|
|
props: { loadingPlanId: '2092438843630391402', canList: true, canManage, departureState: 'WAITING_OTHER_GATES' },
|
|
|
|
|
global: { plugins: [ElementPlus] },
|
|
|
|
|
})
|
|
|
|
|
await flushPromises()
|
|
|
|
|
return wrapper
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function buttonTexts(wrapper: Awaited<ReturnType<typeof render>>) {
|
|
|
|
|
return wrapper.findAll('button').map((button) => button.text())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('ContainerCustomsPanel', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks()
|
|
|
|
|
api.downloadSource.mockResolvedValue(new Blob(['source']))
|
|
|
|
|
api.downloadCompletion.mockResolvedValue(new Blob(['completion']))
|
|
|
|
|
Object.defineProperty(URL, 'createObjectURL', { configurable: true, value: vi.fn(() => 'blob:customs-file') })
|
|
|
|
|
Object.defineProperty(URL, 'revokeObjectURL', { configurable: true, value: vi.fn() })
|
|
|
|
|
vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => undefined)
|
2026-08-28 16:54:02 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-29 10:19:35 +08:00
|
|
|
it('keeps READY_TO_START read-only while exposing source file name and download', async () => {
|
|
|
|
|
const wrapper = await render('READY_TO_START')
|
|
|
|
|
expect(wrapper.text()).toContain('开始报关')
|
|
|
|
|
expect(wrapper.text()).toContain('客户退税资料.pdf')
|
2026-09-01 20:41:30 +08:00
|
|
|
expect(wrapper.text()).toContain('客户退税资料')
|
|
|
|
|
expect(wrapper.text()).toContain('报关完成文件')
|
|
|
|
|
expect(wrapper.text()).not.toContain('客户报关资料')
|
|
|
|
|
expect(wrapper.find('[aria-label="下载客户退税资料 客户退税资料.pdf"]').exists()).toBe(true)
|
|
|
|
|
expect(buttonTexts(wrapper)).not.toContain('上传报关完成文件')
|
|
|
|
|
expect(buttonTexts(wrapper)).not.toContain('覆盖报关完成文件')
|
2026-08-29 10:19:35 +08:00
|
|
|
expect(buttonTexts(wrapper)).not.toContain('提交')
|
2026-08-28 16:54:02 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-29 10:19:35 +08:00
|
|
|
it('allows completion upload and overwrite only while DECLARING with manage permission', async () => {
|
|
|
|
|
let wrapper = await render('DECLARING', true, false)
|
2026-09-01 20:41:30 +08:00
|
|
|
expect(wrapper.text()).toContain('上传报关完成文件')
|
2026-08-29 10:19:35 +08:00
|
|
|
expect(wrapper.text()).toContain('提交')
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
|
|
|
|
|
wrapper = await render('DECLARING', true, true)
|
2026-09-01 20:41:30 +08:00
|
|
|
expect(wrapper.text()).toContain('覆盖报关完成文件')
|
2026-08-29 10:19:35 +08:00
|
|
|
expect(wrapper.text()).toContain('报关完成文件.pdf')
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
|
|
|
|
|
wrapper = await render('DECLARING', false, true)
|
|
|
|
|
expect(wrapper.text()).toContain('只读')
|
2026-09-01 20:41:30 +08:00
|
|
|
expect(buttonTexts(wrapper)).not.toContain('上传报关完成文件')
|
|
|
|
|
expect(buttonTexts(wrapper)).not.toContain('覆盖报关完成文件')
|
2026-08-29 10:19:35 +08:00
|
|
|
expect(buttonTexts(wrapper)).not.toContain('提交')
|
2026-08-28 16:54:02 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-29 10:19:35 +08:00
|
|
|
it('keeps COMPLETED strictly read-only with both files visible and downloadable', async () => {
|
|
|
|
|
const wrapper = await render('COMPLETED', true, true)
|
|
|
|
|
expect(wrapper.text()).toContain('客户退税资料.pdf')
|
|
|
|
|
expect(wrapper.text()).toContain('报关完成文件.pdf')
|
|
|
|
|
expect(wrapper.text()).toContain('报关已完成,待其他离仓条件')
|
2026-09-01 20:41:30 +08:00
|
|
|
expect(buttonTexts(wrapper)).not.toContain('上传报关完成文件')
|
|
|
|
|
expect(buttonTexts(wrapper)).not.toContain('覆盖报关完成文件')
|
2026-08-29 10:19:35 +08:00
|
|
|
expect(buttonTexts(wrapper)).not.toContain('提交')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('routes source and completion downloads independently by the long document id and original names', async () => {
|
|
|
|
|
const wrapper = await render('COMPLETED', false, true)
|
2026-09-01 20:41:30 +08:00
|
|
|
await wrapper.get('[aria-label="下载客户退税资料 客户退税资料.pdf"]').trigger('click')
|
2026-08-29 10:19:35 +08:00
|
|
|
await flushPromises()
|
|
|
|
|
expect(api.downloadSource).toHaveBeenCalledWith('2092438843630391407')
|
|
|
|
|
expect(api.downloadCompletion).not.toHaveBeenCalled()
|
|
|
|
|
|
2026-09-01 20:41:30 +08:00
|
|
|
await wrapper.get('[aria-label="下载报关完成文件 报关完成文件.pdf"]').trigger('click')
|
2026-08-29 10:19:35 +08:00
|
|
|
await flushPromises()
|
|
|
|
|
expect(api.downloadCompletion).toHaveBeenCalledWith('2092438843630391407')
|
|
|
|
|
expect(HTMLAnchorElement.prototype.click).toHaveBeenCalledTimes(2)
|
|
|
|
|
expect(URL.createObjectURL).toHaveBeenCalledTimes(2)
|
|
|
|
|
expect(URL.revokeObjectURL).toHaveBeenCalledWith('blob:customs-file')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('preserves backend error code, request id and trace id when one download fails', async () => {
|
|
|
|
|
api.downloadSource.mockRejectedValueOnce(new ApiResponseError('文件不可用', 'CUSTOMS_FILE_404', 404, undefined, 'request-customs-download', 'trace-customs-download'))
|
|
|
|
|
const wrapper = await render('COMPLETED', false, true)
|
|
|
|
|
|
2026-09-01 20:41:30 +08:00
|
|
|
await wrapper.get('[aria-label="下载客户退税资料 客户退税资料.pdf"]').trigger('click')
|
2026-08-29 10:19:35 +08:00
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('文件不可用')
|
|
|
|
|
expect(wrapper.text()).toContain('CUSTOMS_FILE_404')
|
|
|
|
|
expect(wrapper.text()).toContain('request-customs-download')
|
|
|
|
|
expect(wrapper.text()).toContain('trace-customs-download')
|
|
|
|
|
expect(api.downloadCompletion).not.toHaveBeenCalled()
|
2026-08-28 16:54:02 +08:00
|
|
|
})
|
|
|
|
|
})
|