fix(admin): align booking files with upload contract
This commit is contained in:
@@ -1,10 +1,21 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import ElementPlus from 'element-plus'
|
||||
import { flushPromises, mount } from '@vue/test-utils'
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
||||
import { readFileSync } from 'node:fs'
|
||||
import { resolve } from 'node:path'
|
||||
import OceanBookingDocumentsPanel from './OceanBookingDocumentsPanel.vue'
|
||||
import { uploadOceanBookingDocument } from '../api/platformOceanBookings'
|
||||
|
||||
vi.mock('../api/platformOceanBookings', () => ({
|
||||
downloadOceanBookingDocument: vi.fn(),
|
||||
invalidateOceanBookingDocument: vi.fn(),
|
||||
uploadOceanBookingDocument: vi.fn(),
|
||||
}))
|
||||
|
||||
const source = readFileSync(resolve(process.cwd(), 'src/modules/ocean-bookings/components/OceanBookingDocumentsPanel.vue'), 'utf8')
|
||||
|
||||
describe('OceanBookingDocumentsPanel contract', () => {
|
||||
beforeEach(() => { vi.clearAllMocks() })
|
||||
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: '提单文件'")
|
||||
@@ -22,6 +33,31 @@ describe('OceanBookingDocumentsPanel contract', () => {
|
||||
expect(source).toContain('URL.createObjectURL(blob)')
|
||||
})
|
||||
|
||||
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()
|
||||
})
|
||||
|
||||
it('makes released booking files permanently read-only and preserves traced errors', () => {
|
||||
expect(source).toContain("props.bookingStatus === 'DRAFT' && props.canManage")
|
||||
expect(source).toContain('已放舱 · 永久只读')
|
||||
|
||||
Reference in New Issue
Block a user