import ElementPlus from 'element-plus' import { createPinia, setActivePinia } from 'pinia' import { flushPromises, mount } from '@vue/test-utils' import { beforeEach, describe, expect, it, vi } from 'vitest' import TruckAppointmentsView from './TruckAppointmentsView.vue' import { listTruckAppointments } from '../api/platformTrucking' import type { TruckAppointmentResource } from '../types' vi.mock('../api/platformTrucking', () => ({ listTruckAppointments: vi.fn(), })) const row: TruckAppointmentResource = { id: '9001', appointmentNo: 'TA-9001', status: 'DISPATCHED', customerName: '示例企业', orderNo: 'ORD-1', containerBookingId: '77', containerNo: 'CONT-1', carrierName: '宁波运输', driverName: '王强', vehicleNo: '浙B12345', plannedLoadingAt: '2026-08-10T10:00:00', payableAmount: '3200.00', receivableAmount: '3800.00', attachments: [], } describe('TruckAppointmentsView', () => { beforeEach(() => { vi.mocked(listTruckAppointments).mockReset().mockResolvedValue({ records: [row], page: 1, size: 20, total: 1, pages: 1 }) setActivePinia(createPinia()) }) it('loads the real list and renders relationship snapshots', async () => { const wrapper = mount(TruckAppointmentsView, { global: { plugins: [ElementPlus] } }) await flushPromises() expect(listTruckAppointments).toHaveBeenCalledWith({ page: 1, size: 20, keyword: '', status: '', containerBookingId: '', containerType: '' }) expect(wrapper.text()).toContain('TA-9001') expect(wrapper.text()).toContain('77') expect(wrapper.text()).toContain('宁波运输') expect(wrapper.find('button[aria-label="查看 TA-9001"]').exists()).toBe(true) }) })