import { describe, expect, it } from 'vitest' import { readFileSync } from 'node:fs' import { resolve } from 'node:path' const source = readFileSync(resolve(process.cwd(), 'src/modules/trucking/pages/TruckAppointmentCreateView.vue'), 'utf8') describe('TruckAppointmentCreateView booking-bound creation contract', () => { it('starts with required booking and container choices empty until the user selects them', () => { expect(source).toContain('carrierId: null') expect(source).not.toContain('customerId') expect(source).toContain('oceanBookingId: initialOceanBookingId || null, containerBookingId: initialContainerBookingId || null, loadingPlanId: null') expect(source).toContain('plannedLoadingAt: null') expect(source).toContain("payableAmount: '0.00', currency: 'RMB'") expect(source).not.toContain('receivableAmount') expect(source).toContain('createTruckAppointment({ ...form })') }) it('keeps the form visible and exposes the real backend error details', () => { expect(source).toContain("getApiErrorDetails(err, '创建失败,请稍后重试')") expect(source).toContain('') expect(source).toContain(' { expect(source).toContain('if (saving.value || existingLookupLoading.value) return') }) it('reuses non-terminal appointments by container and separates lookup failures from booking-file errors', () => { expect(source).toContain("listTruckAppointments({ containerBookingId: normalizedId, page: 1, size: 20 })") expect(source).toContain("new Set(['COMPLETED', 'CANCELLED', 'EXCEPTION'])") expect(source).toContain('该柜已有拖车预约') expect(source).toContain("getApiErrorDetails(cause, '已有拖车预约查询失败,请稍后重试')") expect(source).toContain('') expect(source).toContain("router.replace({ name: 'trucking-detail'") expect(source).toContain('serial !== lookupSerial') }) it('places the return action beside the relation note instead of in a separate header row', () => { expect(source).toContain('