feat(admin): bind booking documents and truck containers

This commit is contained in:
2026-08-31 19:54:37 +08:00
parent 0f4f635686
commit a759eb1b6b
24 changed files with 691 additions and 179 deletions
@@ -0,0 +1,57 @@
import ElementPlus from 'element-plus'
import { flushPromises, mount } from '@vue/test-utils'
import { beforeEach, describe, expect, it, vi } from 'vitest'
import OceanBookingPrintDialog from './OceanBookingPrintDialog.vue'
import { downloadOceanBookingPrint } from '../api/platformOceanBookings'
import { ApiResponseError } from '@/shared/api/http'
vi.mock('../api/platformOceanBookings', () => ({ downloadOceanBookingPrint: vi.fn() }))
describe('OceanBookingPrintDialog', () => {
beforeEach(() => {
vi.clearAllMocks()
document.body.innerHTML = ''
vi.stubGlobal('URL', { createObjectURL: vi.fn(() => 'blob:booking-print'), revokeObjectURL: vi.fn() })
})
it('offers the two confirmed documents and previews the selected PDF', async () => {
vi.mocked(downloadOceanBookingPrint).mockResolvedValue(new Blob(['pdf'], { type: 'application/pdf' }))
const wrapper = mount(OceanBookingPrintDialog, {
props: { modelValue: true, bookingId: '123', bookingNo: 'OB-123', allowed: true },
global: { plugins: [ElementPlus] },
attachTo: document.body,
})
await flushPromises()
expect(document.body.textContent).toContain('出口货物托运单')
expect(document.body.textContent).toContain('提单确认件')
await wrapper.findAll('.booking-print-option')[0]!.trigger('click')
await flushPromises()
await Array.from(document.body.querySelectorAll('button')).find((button) => button.textContent?.includes('预览 PDF'))?.click()
await flushPromises()
expect(downloadOceanBookingPrint).toHaveBeenCalledWith('123', 'SHIPPING_INSTRUCTION')
expect(document.body.querySelector('iframe')?.getAttribute('src')).toBe('blob:booking-print')
wrapper.unmount()
})
it('shows permission and API errors without attempting a download', async () => {
const denied = mount(OceanBookingPrintDialog, { props: { modelValue: true, bookingId: '123', allowed: false }, global: { plugins: [ElementPlus] }, attachTo: document.body })
await flushPromises()
expect(document.body.textContent).toContain('暂无订舱单据打印权限')
expect(downloadOceanBookingPrint).not.toHaveBeenCalled()
denied.unmount()
vi.mocked(downloadOceanBookingPrint).mockRejectedValue(new ApiResponseError('缺少提单号', 'B0409', 200, undefined, 'req-print', 'trace-print'))
const failed = mount(OceanBookingPrintDialog, { props: { modelValue: true, bookingId: '123', allowed: true }, global: { plugins: [ElementPlus] }, attachTo: document.body })
await flushPromises()
await failed.findAll('.booking-print-option')[1]!.trigger('click')
await flushPromises()
await Array.from(document.body.querySelectorAll('button')).find((button) => button.textContent?.includes('预览 PDF'))?.click()
await flushPromises()
expect(document.body.textContent).toContain('缺少提单号')
expect(document.body.textContent).toContain('req-print')
expect(document.body.textContent).toContain('trace-print')
failed.unmount()
})
})