2026-08-31 19:59:17 +08:00
|
|
|
import ElementPlus from 'element-plus'
|
|
|
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
2026-08-31 19:54:37 +08:00
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
import { resolve } from 'node:path'
|
2026-08-31 19:59:17 +08:00
|
|
|
import OceanBookingDocumentsPanel from './OceanBookingDocumentsPanel.vue'
|
|
|
|
|
import { uploadOceanBookingDocument } from '../api/platformOceanBookings'
|
|
|
|
|
|
|
|
|
|
vi.mock('../api/platformOceanBookings', () => ({
|
|
|
|
|
downloadOceanBookingDocument: vi.fn(),
|
|
|
|
|
invalidateOceanBookingDocument: vi.fn(),
|
|
|
|
|
uploadOceanBookingDocument: vi.fn(),
|
|
|
|
|
}))
|
2026-08-31 19:54:37 +08:00
|
|
|
|
|
|
|
|
const source = readFileSync(resolve(process.cwd(), 'src/modules/ocean-bookings/components/OceanBookingDocumentsPanel.vue'), 'utf8')
|
|
|
|
|
|
|
|
|
|
describe('OceanBookingDocumentsPanel contract', () => {
|
2026-08-31 19:59:17 +08:00
|
|
|
beforeEach(() => { vi.clearAllMocks() })
|
2026-08-31 19:54:37 +08:00
|
|
|
it('owns the two confirmed document types under the booking', () => {
|
|
|
|
|
expect(source).toContain("value: 'BOOKING_CONFIRMATION', label: '订舱确认文件'")
|
|
|
|
|
expect(source).toContain("value: 'BILL_OF_LADING', label: '提单文件'")
|
|
|
|
|
expect(source).toContain('文件统一归属当前订舱')
|
|
|
|
|
expect(source).not.toContain('TRUCK_APPOINTMENT_ATTACHMENT')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('supports upload, replacement, logical invalidation and download with version chaining', () => {
|
|
|
|
|
expect(source).toContain('uploadOceanBookingDocument(props.bookingId, props.bookingVersion, type, file)')
|
|
|
|
|
expect(source).toContain('invalidateOceanBookingDocument(props.bookingId, item.id, version)')
|
|
|
|
|
expect(source).toContain('version = invalidated.bookingVersion')
|
|
|
|
|
expect(source).toContain('确认替换')
|
|
|
|
|
expect(source).toContain('确认作废')
|
|
|
|
|
expect(source).toContain('downloadOceanBookingDocument')
|
|
|
|
|
expect(source).toContain('URL.createObjectURL(blob)')
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-31 19:59:17 +08:00
|
|
|
it('accepts every file format while rejecting a single file above 50 MiB before upload', () => {
|
|
|
|
|
expect(source).toContain('const maxFileBytes = 50 * 1024 * 1024')
|
|
|
|
|
expect(source).toContain('file.size > maxFileBytes')
|
|
|
|
|
expect(source).toContain('单个订舱资料文件不能超过 50MB,请重新选择')
|
|
|
|
|
expect(source).toContain('任意格式,单文件不超过 50MB')
|
|
|
|
|
expect(source).not.toContain('accept="')
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('rejects an oversized arbitrary-format file before calling the backend', async () => {
|
|
|
|
|
const wrapper = mount(OceanBookingDocumentsPanel, {
|
|
|
|
|
props: { bookingId: '123', bookingVersion: 2, bookingStatus: 'DRAFT', documents: [], canManage: true },
|
|
|
|
|
global: { plugins: [ElementPlus] },
|
|
|
|
|
})
|
|
|
|
|
const file = new File(['data'], 'archive.custom', { type: 'application/x-custom' })
|
|
|
|
|
Object.defineProperty(file, 'size', { value: 50 * 1024 * 1024 + 1 })
|
|
|
|
|
const input = wrapper.get('input[type="file"]')
|
|
|
|
|
Object.defineProperty(input.element, 'files', { configurable: true, value: [file] })
|
|
|
|
|
await input.trigger('change')
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
expect(wrapper.text()).toContain('单个订舱资料文件不能超过 50MB')
|
|
|
|
|
expect(uploadOceanBookingDocument).not.toHaveBeenCalled()
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
2026-08-31 19:54:37 +08:00
|
|
|
it('makes released booking files permanently read-only and preserves traced errors', () => {
|
|
|
|
|
expect(source).toContain("props.bookingStatus === 'DRAFT' && props.canManage")
|
|
|
|
|
expect(source).toContain('已放舱 · 永久只读')
|
|
|
|
|
expect(source).toContain('manageReason')
|
|
|
|
|
expect(source).toContain('<ApiErrorMeta :details="error" />')
|
|
|
|
|
expect(source).toContain('订舱资料上传失败,请稍后重试')
|
|
|
|
|
expect(source).toContain('订舱资料下载失败,请稍后重试')
|
|
|
|
|
})
|
|
|
|
|
})
|