2026-09-01 19:57:36 +08:00
|
|
|
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 { DataTableStub } from './phase5TestStubs'
|
|
|
|
|
|
2026-10-11 15:33:09 +08:00
|
|
|
const sourceQuery = vi.hoisted(() => ({} as Record<string, string>))
|
2026-09-01 19:57:36 +08:00
|
|
|
const routerPush = vi.hoisted(() => vi.fn())
|
2026-10-11 15:33:09 +08:00
|
|
|
vi.mock('vue-router', () => ({ useRoute: () => ({ params: { dispatchNo: 'PC/1' }, query: sourceQuery }), useRouter: () => ({ push: routerPush }) }))
|
2026-09-01 19:57:36 +08:00
|
|
|
vi.mock('../api/dispatches', () => ({ getDispatch: vi.fn() }))
|
|
|
|
|
|
|
|
|
|
describe('DispatchDetailView', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
routerPush.mockReset()
|
2026-10-11 15:33:09 +08:00
|
|
|
Object.keys(sourceQuery).forEach(key => delete sourceQuery[key])
|
2026-09-01 19:57:36 +08:00
|
|
|
vi.mocked(getDispatch).mockReset().mockResolvedValue({
|
|
|
|
|
id: '1', dispatchNo: 'PC/1', vehiclePlate: 'CA-100', driverName: '张师傅', status: 'PENDING_DEPARTURE',
|
2026-09-18 14:58:40 +08:00
|
|
|
route: 'LAX → ONT8', items: [{ id: '11', planPalletId: '20', orderNo: 'LM-1', warehousePalletId: '21', fbaWarehouseCode: 'ONT8', grossWeightKg: 88.5, volumeCbm: 1.25 }],
|
2026-09-01 19:57:36 +08:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('loads the business dispatch number and renders summary and related orders', async () => {
|
|
|
|
|
const wrapper = mount(DispatchDetailView, { global: { plugins: [ElementPlus], stubs: { DataTable: DataTableStub } } })
|
|
|
|
|
await flushPromises()
|
|
|
|
|
expect(getDispatch).toHaveBeenCalledWith('PC/1')
|
|
|
|
|
expect(wrapper.text()).toContain('PC/1')
|
|
|
|
|
expect(wrapper.text()).toContain('CA-100')
|
|
|
|
|
expect(wrapper.text()).toContain('待发车')
|
|
|
|
|
const table = wrapper.findComponent(DataTableStub)
|
2026-09-18 14:58:40 +08:00
|
|
|
expect(table.props('data')).toEqual([{ orderNo: 'LM-1', weight: 88.5, palletCount: 1, fbaWarehouse: 'ONT8', volume: 1.25, containerNo: '—' }])
|
2026-09-01 19:57:36 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
2026-10-03 04:35:55 +08:00
|
|
|
|
|
|
|
|
it('keeps related order weight unknown when one pallet lacks physical weight', async () => {
|
|
|
|
|
vi.mocked(getDispatch).mockResolvedValueOnce({ id: '1', dispatchNo: 'PC/1', status: 'PENDING_DEPARTURE', items: [
|
|
|
|
|
{ id: '11', planPalletId: '31', orderNo: 'LM-1', warehousePalletId: '21', grossWeightKg: 88.5, volumeCbm: 1 },
|
|
|
|
|
{ id: '12', planPalletId: '32', orderNo: 'LM-1', warehousePalletId: '22', grossWeightKg: null, volumeWeightKg: 999, volumeCbm: 1 },
|
|
|
|
|
] })
|
|
|
|
|
const wrapper = mount(DispatchDetailView, { global: { plugins: [ElementPlus], stubs: { DataTable: DataTableStub } } })
|
|
|
|
|
await flushPromises()
|
|
|
|
|
expect(wrapper.findComponent(DataTableStub).props('data')).toEqual([expect.objectContaining({ weight: null })])
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
2026-10-11 15:33:09 +08:00
|
|
|
it.each([false, true])('returns to the original inquiry only for a valid source: %s', async fromInquiry => {
|
|
|
|
|
if (fromInquiry) Object.assign(sourceQuery, { fleetSource: 'inquiry', fleetOfferNo: 'FO-1', fleetBookingNo: 'FB-2' })
|
|
|
|
|
const wrapper = mount(DispatchDetailView, { global: { plugins: [ElementPlus], stubs: { DataTable: DataTableStub } } })
|
|
|
|
|
await flushPromises()
|
|
|
|
|
wrapper.findComponent({ name: 'OverseasDetailShell' }).vm.$emit('back')
|
|
|
|
|
expect(routerPush).toHaveBeenCalledWith(fromInquiry ? { name: 'overseas-master-data-capacity-offer-detail', params: { offerNo: 'FO-1' }, query: { inquiry: 'FB-2' } } : { name: 'overseas-dispatches' })
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
2026-09-01 19:57:36 +08:00
|
|
|
})
|