43 lines
1.8 KiB
TypeScript
43 lines
1.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: {
|
|
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',
|
|
},
|
|
skus: [], fees: [], 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('洛杉矶仓')
|
|
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()
|
|
})
|
|
})
|