fix(admin): unblock tailleg inbound planning

This commit is contained in:
2026-08-27 15:56:13 +08:00
parent 00045a9764
commit 690f386bff
16 changed files with 241 additions and 34 deletions
@@ -0,0 +1,102 @@
import ElementPlus from 'element-plus'
import { createPinia } from 'pinia'
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { ApiResponseError } from '@/shared/api/http'
import DataTable from '@/shared/components/DataTable.vue'
import { convertLastMileOrderToInboundPlan, listLastMileOrders } from '../api/lastMileOrders'
import LastMileOrdersView from './LastMileOrdersView.vue'
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: () => true }) }))
vi.mock('vue-router', () => ({ useRouter: () => ({ push: vi.fn() }) }))
vi.mock('../api/lastMileOrders', () => ({
listLastMileOrders: vi.fn(),
convertLastMileOrderToInboundPlan: vi.fn(),
transferLastMileOrders: vi.fn(),
}))
class ResizeObserverStub implements ResizeObserver { observe() {} unobserve() {} disconnect() {} }
function memoryStorage(): Storage {
const values = new Map<string, string>()
return {
get length() { return values.size }, clear: () => values.clear(),
getItem: (key) => values.get(key) ?? null, key: (index) => [...values.keys()][index] ?? null,
removeItem: (key) => values.delete(key), setItem: (key, value) => values.set(key, value),
}
}
enableAutoUnmount(afterEach)
afterAll(() => vi.unstubAllGlobals())
function selectedRow(customerId = '2092618717861048321') {
return { id: '2092873463568596994', customerId, orderNo: 'LMO-260827-0001' }
}
async function mountView() {
const wrapper = mount(LastMileOrdersView, { attachTo: document.body, global: { plugins: [createPinia(), ElementPlus] } })
await flushPromises()
return wrapper
}
async function selectAndConvert(wrapper: Awaited<ReturnType<typeof mountView>>, row = selectedRow()) {
wrapper.findComponent(DataTable).vm.$emit('selection-change', [row])
await wrapper.vm.$nextTick()
const button = wrapper.findAll('button').find((item) => item.text().includes('生成入库计划'))
expect(button).toBeDefined()
await button!.trigger('click')
await flushPromises()
}
describe('LastMileOrdersView inbound-plan conversion', () => {
beforeEach(() => {
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
vi.stubGlobal('localStorage', memoryStorage())
vi.mocked(listLastMileOrders).mockReset().mockResolvedValue({ records: [], page: 1, size: 10, total: 0, pages: 0 })
vi.mocked(convertLastMileOrderToInboundPlan).mockReset().mockResolvedValue({})
})
it('submits the selected long customer id without coercing it to a number', async () => {
const wrapper = await mountView()
await selectAndConvert(wrapper)
expect(convertLastMileOrderToInboundPlan).toHaveBeenCalledWith({
orderId: '2092873463568596994', customerId: '2092618717861048321',
})
})
it('refreshes the list and displays INBOUND_PLANNED after a successful conversion', async () => {
const base = {
id: '2092873463568596994', customerId: '2092618717861048321', customerName: '华远贸易',
orderNo: 'LMO-260827-0001', orderType: 'FIRST_LEG',
}
vi.mocked(listLastMileOrders)
.mockResolvedValueOnce({ records: [{ ...base, currentStatus: 'PENDING_ASSIGNMENT' }], page: 1, size: 10, total: 1, pages: 1 })
.mockResolvedValueOnce({ records: [{ ...base, currentStatus: 'INBOUND_PLANNED', inboundOrderNo: 'IP-260827-0001' }], page: 1, size: 10, total: 1, pages: 1 })
const wrapper = await mountView()
expect(wrapper.text()).toContain('待分配')
await selectAndConvert(wrapper)
expect(listLastMileOrders).toHaveBeenCalledTimes(2)
expect(wrapper.text()).toContain('已生成入库计划')
expect(wrapper.text()).toContain('IP-260827-0001')
})
it('fails closed when the selected row has no customer scope', async () => {
const wrapper = await mountView()
await selectAndConvert(wrapper, selectedRow(''))
expect(convertLastMileOrderToInboundPlan).not.toHaveBeenCalled()
expect(wrapper.text()).toContain('所选尾程订单缺少客户标识')
})
it.each([
['A0404', 'Inbound order not found'],
['A0409', 'Inbound order version conflict'],
])('keeps %s request metadata visible after conversion failure', async (code, message) => {
vi.mocked(convertLastMileOrderToInboundPlan).mockRejectedValueOnce(new ApiResponseError(
message, code, 200, undefined, `request-${code}`, `trace-${code}`,
))
const wrapper = await mountView()
await selectAndConvert(wrapper)
expect(wrapper.text()).toContain(code)
expect(wrapper.text()).toContain(`request-${code}`)
expect(wrapper.text()).toContain(`trace-${code}`)
})
})