import ElementPlus from 'element-plus' import { flushPromises, mount } from '@vue/test-utils' import { beforeEach, describe, expect, it, vi } from 'vitest' import { getDispatch } from '../api/dispatches' import DispatchDetailView from './DispatchDetailView.vue' import { detail, destination } from '../dispatchTestFixtures' import { DataTableStub } from './phase5TestStubs' const query = vi.hoisted(() => ({} as Record)) const push = vi.hoisted(() => vi.fn()) const can = vi.hoisted(() => vi.fn(() => false)) vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can }) })) vi.mock('vue-router', () => ({ useRoute: () => ({ params: { dispatchNo: 'PC/1' }, query }), useRouter: () => ({ push }) })) vi.mock('../api/dispatches', () => ({ getDispatch: vi.fn() })) vi.mock('@/modules/overseas-master-data', () => ({ inquiryReturnTarget: (value: Record) => value.fleetOfferNo ? { name: 'overseas-master-data-capacity-offer-detail', params: { offerNo: value.fleetOfferNo }, query: { inquiry: value.fleetBookingNo } } : null })) const options = { global: { plugins: [ElementPlus], stubs: { DataTable: DataTableStub, DispatchWorkflowDialog: true } } } beforeEach(() => { vi.mocked(getDispatch).mockResolvedValue(detail()); can.mockReturnValue(false); push.mockReset(); Object.keys(query).forEach(key => delete query[key]) }) describe('whole-dispatch four-tab detail', () => { it('uses only four accessible colored tabs and switches without another network read', async () => { const wrapper = mount(DispatchDetailView, options); await flushPromises() expect(getDispatch).toHaveBeenCalledWith('PC/1') const tabs = wrapper.findAll('[role="tab"]') expect(tabs.map(tab => tab.text())).toEqual(['🚚车辆信息', '📋排车信息', '📝单据信息', '📦关联订单明细']) expect(wrapper.findAll('.density-tab-icon')).toHaveLength(4) await tabs[1]!.trigger('click'); await flushPromises() expect(tabs[1]!.attributes('aria-selected')).toBe('true') expect(wrapper.get(`#${tabs[1]!.attributes('aria-controls')}`).text()).toContain('LAX → ONT8') expect(getDispatch).toHaveBeenCalledTimes(1); expect(wrapper.text()).toContain('装车前'); wrapper.unmount() }) it('uses exact server order attribution including unknown measurements and real container numbers', async () => { const value = detail(); value.orderDetails.push({ ...value.orderDetails[0]!, customerId: 'C2', customerName: '客户乙', sourceKey: 'source-2', orderNo: 'LM-2', grossWeightKg: 12.25 }) vi.mocked(getDispatch).mockResolvedValueOnce(value) const wrapper = mount(DispatchDetailView, options); await flushPromises() expect(wrapper.getComponent(DataTableStub).props('data')).toEqual(value.orderDetails) expect(value.orderDetails[0]!.grossWeightKg).toBeNull(); wrapper.unmount() }) it('renders all customer delivery references and real update time/remark without leaking internal IDs', async () => { const value = detail(); value.documents.deliveries = ['DEL-A', 'DEL-B'].map((deliveryNo, index) => ({ deliveryNo, customerId: `C${index}`, customerName: `客户${index}`, outboundNo: `OUT-${index}`, groupKey: `group-${index}`, destination: destination(), status: 'WAIT_DELIVERY', packageCount: 1, palletCount: 1 })) vi.mocked(getDispatch).mockResolvedValueOnce(value) const wrapper = mount(DispatchDetailView, options); await flushPromises(); await wrapper.findAll('[role="tab"]')[2]!.trigger('click') expect(wrapper.text()).toContain('DEL-A'); expect(wrapper.text()).toContain('DEL-B'); expect(wrapper.text()).toContain('真实备注') expect(wrapper.findAll('button').some(button => button.text() === 'DEL-A')).toBe(false); wrapper.unmount() }) it('requires a literal service allowance and permission for a write action', async () => { can.mockReturnValue(true); vi.mocked(getDispatch).mockResolvedValueOnce(detail({ actions: { DEPART: { allowed: false, blockCode: 'NOT_ARRANGED', blockReason: '尚未安排派送' } } })) const wrapper = mount(DispatchDetailView, options); await flushPromises() expect(wrapper.text()).toContain('尚未安排派送'); expect(wrapper.findAll('button').some(button => button.text() === '确认发车')).toBe(false); wrapper.unmount() }) it('retains a real API failure and exposes retry rather than rendering a successful empty detail', async () => { vi.mocked(getDispatch).mockRejectedValueOnce(new Error('permission denied')) const wrapper = mount(DispatchDetailView, options); await flushPromises(); expect(wrapper.text()).toContain('排车详情加载失败,请重试'); expect(wrapper.findAll('[role="tab"]')).toHaveLength(0); wrapper.unmount() }) it('keeps the original inquiry return target', async () => { Object.assign(query, { fleetOfferNo: 'FO-1', fleetBookingNo: 'FB-2' }); const wrapper = mount(DispatchDetailView, options); await flushPromises(); await wrapper.get('button.density-back').trigger('click') expect(push).toHaveBeenCalledWith({ name: 'overseas-master-data-capacity-offer-detail', params: { offerNo: 'FO-1' }, query: { inquiry: 'FB-2' } }); wrapper.unmount() }) })