test(admin): cover booking-scoped trucking

This commit is contained in:
2026-09-01 16:35:40 +08:00
parent 5706645032
commit 4ad8537113
8 changed files with 98 additions and 13 deletions
@@ -57,6 +57,7 @@ describe('TruckAppointmentForm booking-only behavior', () => {
const labels = wrapper.findAllComponents({ name: 'ElOption' }).map((option) => String(option.props('label') || ''))
expect(labels.some((label) => label.includes('OB-1') && label.includes('BL-1'))).toBe(true)
expect(labels.some((label) => label.includes('CAB-'))).toBe(false)
expect(candidates[0]).not.toHaveProperty('containerBookingId')
const emitted = wrapper.emitted('update:modelValue')?.at(-1)?.[0] as SaveTruckAppointmentRequest
expect(emitted.oceanBookingId).toBe('booking-1')
expect(emitted.billOfLadingNo).toBe('BL-1')
@@ -65,6 +66,30 @@ describe('TruckAppointmentForm booking-only behavior', () => {
wrapper.unmount()
})
it('keeps only the latest candidate response when option reloads overlap', async () => {
let resolveSlow!: (value: Awaited<ReturnType<typeof listTruckAppointmentCandidates>>) => void
let resolveFast!: (value: Awaited<ReturnType<typeof listTruckAppointmentCandidates>>) => void
vi.mocked(listTruckAppointmentCandidates)
.mockResolvedValueOnce({ records: candidates, page: 1, size: 200, total: candidates.length, pages: 1 })
.mockImplementationOnce(() => new Promise((resolve) => { resolveSlow = resolve }))
.mockImplementationOnce(() => new Promise((resolve) => { resolveFast = resolve }))
const wrapper = mount(TruckAppointmentForm, { props: { modelValue: { ...model } }, global: { plugins: [ElementPlus] } })
await flushPromises()
const vm = wrapper.vm as unknown as { loadOptions: () => Promise<void> }
const slow = vm.loadOptions()
const fast = vm.loadOptions()
resolveFast({ records: [candidates[1]!], page: 1, size: 200, total: 1, pages: 1 })
await fast
resolveSlow({ records: [candidates[0]!], page: 1, size: 200, total: 1, pages: 1 })
await slow
await flushPromises()
const labels = wrapper.findAllComponents({ name: 'ElOption' }).map((option) => String(option.props('label') || ''))
expect(labels.some((label) => label.includes('OB-2'))).toBe(true)
expect(labels.some((label) => label.includes('OB-1'))).toBe(false)
wrapper.unmount()
})
it('replaces frozen booking snapshots when switching the selected booking', async () => {
const wrapper = mount(TruckAppointmentForm, { props: { modelValue: { ...model } }, global: { plugins: [ElementPlus] } })
await flushPromises()
@@ -69,9 +69,10 @@ describe('TruckAppointmentForm interaction contract', () => {
})
it('keeps container identity out of the booking-scoped form', () => {
expect(source).not.toContain('柜次号:')
expect(source).not.toContain('集装箱号:')
expect(source).toContain('真实柜次及集装箱号在货柜与预装流程维护')
expect(source).not.toContain('柜次')
expect(source).not.toContain('装柜计划')
expect(source).not.toContain('集装箱号')
expect(source).toContain('货柜资料在货柜与预装流程维护')
})
it('keeps the form usable at 390px', () => {
@@ -94,7 +95,7 @@ describe('TruckAppointmentForm interaction contract', () => {
expect(source).not.toContain('应收拖车费')
})
it('uses four compact desktop columns while retaining two-column relations and wide text fields', () => {
it('keeps the 1920 desktop contract compact without horizontal form overflow', () => {
expect(source).toContain('@media (min-width: 1200px)')
expect(source).toContain('max-width:25%; flex:0 0 25%')
expect(source).toContain('class="relation-column"')
@@ -33,7 +33,7 @@ const phoneRule = (label: string) => ({ validator: (_rule: unknown, value: unkno
}, trigger: 'blur' })
const rules: FormRules = {
oceanBookingId: [{ required: true, message: '请选择已放舱订舱', trigger: 'change' }, { validator: (_rule, value, callback) => {
if (!(bookings.value.some((item) => item.id === String(value)) || (relationLocked.value && selectedBookingFallback.value?.id === String(value)))) return callback(new Error('请选择仍有可预约柜次的已放舱订舱'))
if (!(bookings.value.some((item) => item.id === String(value)) || (relationLocked.value && selectedBookingFallback.value?.id === String(value)))) return callback(new Error('请选择可创建拖车单的已放舱订舱'))
if (bookingContainersError.value) return callback(new Error('订舱资料状态加载失败,请重试'))
if (!draft.billOfLadingNo?.trim()) return callback(new Error('所选订舱缺少有效提单号'))
return callback(bookingDocumentReady.value ? undefined : new Error('所选订舱缺少有效的订舱确认文件或提单文件'))
@@ -124,7 +124,7 @@ async function loadOptions() {
if (sequence !== optionsLoadSequence) return
if (results[0].status === 'fulfilled') carriers.value = results[0].value.records.filter((item) => item.category === 'TRUCKING' && item.status === 'ACTIVE')
if (results[1].status === 'fulfilled') candidates.value = results[1].value.records
const failed = ['承运商', '可预约订舱柜次'].filter((_, index) => results[index]?.status === 'rejected')
const failed = ['承运商', '可用订舱'].filter((_, index) => results[index]?.status === 'rejected')
if (failed.length) optionsError.value = `${failed.join('、')}选项加载失败`
optionsLoading.value = false
if (relationLocked.value && draft.oceanBookingId) await loadCurrentBookingContext(String(draft.oceanBookingId))
@@ -140,7 +140,7 @@ async function loadOptions() {
}
async function validate() { return formRef.value?.validate() }
async function submitForm() { if (props.submitting) return; if (await formRef.value?.validate()) emit('submit') }
defineExpose({ validate })
defineExpose({ validate, loadOptions })
onMounted(() => { void loadOptions() })
watch(() => props.readonly, (readonly) => { if (!readonly && !carriers.value.length) void loadOptions() })
watch(() => props.resource?.id, (id, previous) => { if (id && id !== previous) void loadOptions() })
@@ -148,7 +148,7 @@ watch(() => props.resource?.id, (id, previous) => { if (id && id !== previous) v
<template>
<el-form ref="formRef" :model="draft" :rules="rules" label-position="top" :disabled="readonly || submitting" class="truck-form">
<div class="relation-note"><span>一张已放舱订舱对应一张有效拖车单;仓库和提单号由订舱冻结资料带入,真实柜次及集装箱号在货柜与预装流程维护,最终资格仍由服务端校验。</span><div v-if="$slots['relation-note-actions']" class="relation-note__actions"><slot name="relation-note-actions" /></div></div>
<div class="relation-note"><span>一张已放舱订舱对应一张有效拖车单;仓库和提单号由订舱冻结资料带入,货柜资料在货柜与预装流程维护,最终资格仍由服务端校验。</span><div v-if="$slots['relation-note-actions']" class="relation-note__actions"><slot name="relation-note-actions" /></div></div>
<el-alert v-if="relationWarning" type="warning" :closable="false" show-icon :title="relationWarning" class="relation-alert" />
<el-alert v-if="optionsError" type="warning" :closable="false" show-icon :title="optionsError" class="relation-alert"><el-button link type="warning" :loading="optionsLoading" @click="loadOptions">重新加载选项</el-button></el-alert>
<el-row :gutter="16">