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 { getDeliveryOrder } from '../api/deliveryOrders'
|
|
|
|
|
import DeliveryOrderDetailView from './DeliveryOrderDetailView.vue'
|
|
|
|
|
|
|
|
|
|
const routeState = vi.hoisted(() => ({ params: { deliveryNo: 'DEL/1' }, query: { customerId: '100' } as Record<string, string> }))
|
|
|
|
|
vi.mock('vue-router', () => ({ useRoute: () => routeState, useRouter: () => ({ push: vi.fn() }) }))
|
|
|
|
|
vi.mock('../api/deliveryOrders', () => ({ getDeliveryOrder: vi.fn() }))
|
|
|
|
|
|
|
|
|
|
describe('DeliveryOrderDetailView', () => {
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
routeState.query = { customerId: '100' }
|
|
|
|
|
vi.mocked(getDeliveryOrder).mockReset().mockResolvedValue({
|
|
|
|
|
order: {
|
2026-09-09 11:17:12 +08:00
|
|
|
version: 3, allowedActions: ['COMPLETE_DELIVERY'],
|
2026-09-01 19:57:36 +08:00
|
|
|
id: '1', customerId: '100', deliveryNo: 'DEL/1', outboundNo: 'OUT-1', dispatchNo: 'PC-1',
|
|
|
|
|
status: 'DELIVERING', overseasWarehouseName: '洛杉矶仓', palletCount: 1, packageCount: 2,
|
|
|
|
|
createdAt: '2026-09-01T10:00:00',
|
|
|
|
|
},
|
2026-09-08 18:02:56 +08:00
|
|
|
skus: [], fees: [
|
|
|
|
|
{ id: 'fee-private', feeDirection: 'RECEIVABLE', feeType: 'PRIVATE_LAST_MILE_DELIVERY', currency: 'USD', amount: 88 },
|
|
|
|
|
{ id: 'fee-delivery', feeDirection: 'RECEIVABLE', feeType: 'DELIVERY_FEE', currency: 'USD', amount: 66 },
|
|
|
|
|
], operations: [],
|
2026-09-01 19:57:36 +08:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('loads and renders detail in the explicit customer scope', async () => {
|
|
|
|
|
const wrapper = mount(DeliveryOrderDetailView, { global: { plugins: [ElementPlus] } })
|
|
|
|
|
await flushPromises()
|
|
|
|
|
expect(getDeliveryOrder).toHaveBeenCalledWith('DEL/1', '100')
|
|
|
|
|
expect(wrapper.text()).toContain('DEL/1')
|
|
|
|
|
expect(wrapper.text()).toContain('派送中')
|
|
|
|
|
expect(wrapper.text()).toContain('洛杉矶仓')
|
2026-09-08 18:02:56 +08:00
|
|
|
await wrapper.find('.el-tabs__item:nth-child(3)').trigger('click')
|
|
|
|
|
expect(wrapper.text()).toContain('私人仓尾程派送费')
|
|
|
|
|
expect(wrapper.text()).toContain('派送费用')
|
2026-09-01 19:57:36 +08:00
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('blocks an unsafe detail request without customer scope', async () => {
|
|
|
|
|
routeState.query = {}
|
|
|
|
|
const wrapper = mount(DeliveryOrderDetailView, { global: { plugins: [ElementPlus] } })
|
|
|
|
|
await flushPromises()
|
|
|
|
|
expect(getDeliveryOrder).not.toHaveBeenCalled()
|
|
|
|
|
expect(wrapper.text()).toContain('缺少派送单客户范围')
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
})
|