Files
admin-web/src/modules/overseas-warehouse/pages/DeliveryOrderDetailView.test.ts
T

67 lines
3.8 KiB
TypeScript

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: {
version: 3, allowedActions: ['COMPLETE_DELIVERY'],
id: '1', customerId: '100', deliveryNo: 'DEL/1', outboundNo: 'OUT-1', dispatchNo: 'PC-1',
status: 'DELIVERING', overseasWarehouseName: '洛杉矶仓', destinationWarehouseCode: 'ACY2', palletCount: 1, packageCount: 2, signedPackages: null,
createdAt: '2026-09-01T10:00:00',
},
skus: [], fees: [
{ id: 'fee-private', feeDirection: 'RECEIVABLE', feeType: 'PRIVATE_LAST_MILE_DELIVERY', currency: 'USD', amount: 88, sourceStatus: 'ACTIVE', reviewStatus: 'APPROVED', voidStatus: 'PENDING_FINANCE' },
{ id: 'fee-delivery', feeDirection: 'RECEIVABLE', feeType: 'DELIVERY_FEE', currency: 'USD', amount: 66, sourceStatus: 'ACTIVE', reviewStatus: 'APPROVED', voidStatus: 'FINANCE_ATTENTION' },
], operations: [],
})
})
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('洛杉矶仓')
expect(wrapper.text()).toContain('ACY2')
await wrapper.find('.el-tabs__item:nth-child(3)').trigger('click')
expect(wrapper.text()).toContain('私人仓尾程派送费')
expect(wrapper.text()).toContain('派送费用')
expect(wrapper.text()).toContain('作废待财务确认')
expect(wrapper.text()).toContain('作废待财务处理')
expect(wrapper.text()).not.toContain('已作废')
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()
})
it('shows frozen original coverage separately from new fees', async () => {
const value = await vi.mocked(getDeliveryOrder)('DEL/1', '100')
value.feeCoverage = { cargoHash: 'hash', cargo: [], confirmedAt: '2026-10-03T00:00:00Z', references: [{
source: { financeFeeId: '711', sourceFeeId: '811', sourceType: 'INBOUND_FEE', sourceVersion: 3, customerId: '100', sourceInboundId: '11', inboundCode: 'IN-11', feeItemCode: 'FREIGHT', feeItemName: '原运费', currency: 'CNY', amount: 100, sourceHash: 'original', status: 'AVAILABLE' }, services: ['DELIVERY_FEE', 'LOADING_FEE'],
}] }
vi.mocked(getDeliveryOrder).mockResolvedValue(value)
const wrapper = mount(DeliveryOrderDetailView, { global: { plugins: [ElementPlus] } })
await flushPromises()
await wrapper.find('.el-tabs__item:nth-child(3)').trigger('click')
expect(wrapper.text()).toContain('原费用金额供核对,不计作本次新增')
expect(wrapper.text()).toContain('IN-11 · 原运费 · CNY 100 · 版本 3 · 已含派送、装车')
wrapper.unmount()
})
})