This commit is contained in:
2026-08-27 16:42:32 +08:00
parent a90d5fbe39
commit 0181656b4f
4 changed files with 25 additions and 158 deletions
@@ -2,102 +2,46 @@ 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 { convertLastMileContainerToInboundPlans, 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(),
convertLastMileContainerToInboundPlans: vi.fn(),
convertLastMileOrderToInboundPlan: vi.fn(),
transferLastMileOrders: vi.fn(),
listLastMileOrders: vi.fn(), convertLastMileContainerToInboundPlans: 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),
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())
async function mountView() {
const wrapper = mount(LastMileOrdersView, { attachTo: document.body, global: { plugins: [createPinia(), ElementPlus] } })
await flushPromises()
return wrapper
}
const containerRecords = [
{ id: '1', customerId: '100', sourceContainerBookingId: '2092873463568597001', orderNo: 'LMO-1', inboundCode: 'IN-1', containerNo: 'CONT-1', packageCount: 10, palletCount: 1, volumeCbm: 2, currentStatus: 'PENDING_ASSIGNMENT' },
{ id: '2', customerId: '200', sourceContainerBookingId: '2092873463568597001', orderNo: 'LMO-2', inboundCode: 'IN-2', containerNo: 'CONT-1', packageCount: 5, palletCount: 2, volumeCbm: 1, currentStatus: 'PENDING_ASSIGNMENT' },
]
function plan(id: string, customerId: string) {
return { id, planNo: `LIP-${id}`, customerId, sourceOrderId: id, containerNo: 'CONT-1', status: 'PENDING_ASSIGNMENT', lineCount: 1, palletCount: 1, totalVolumeCbm: 1, lines: [], pallets: [], allocations: [] }
}
async function openPendingContainers(wrapper: Awaited<ReturnType<typeof mountView>>) {
const pendingTab = wrapper.findAll('.el-radio-button').find((item) => item.text().includes('待分配'))
expect(pendingTab).toBeDefined()
await pendingTab!.trigger('click')
await flushPromises()
}
describe('LastMileOrdersView inbound-plan conversion', () => {
describe('LastMileOrdersView container boundary', () => {
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({})
vi.mocked(convertLastMileContainerToInboundPlans).mockReset().mockResolvedValue([plan('1', '100'), plan('2', '200')])
vi.mocked(convertLastMileContainerToInboundPlans).mockReset()
vi.mocked(convertLastMileOrderToInboundPlan).mockReset()
})
it('calls the atomic container endpoint once and refreshes all affected orders', async () => {
vi.mocked(listLastMileOrders)
.mockResolvedValueOnce({ records: [], page: 1, size: 10, total: 0, pages: 0 })
.mockResolvedValueOnce({ records: containerRecords, page: 1, size: 10, total: 2, pages: 1 })
.mockResolvedValueOnce({ records: [], page: 1, size: 10, total: 0, pages: 0 })
const wrapper = await mountView()
await openPendingContainers(wrapper)
expect(wrapper.text()).toContain('CONT-1')
expect(wrapper.text()).toContain('将为 2 个尾程订单生成 2 个独立入库计划,PDA仍按同柜作业')
const button = wrapper.findAll('button').find((item) => item.text().includes('生成整柜入库计划'))
expect(button).toBeDefined()
expect(button!.attributes('disabled')).toBeUndefined()
await button!.trigger('click')
it('fails closed instead of grouping the current order page as a whole container', async () => {
const wrapper = mount(LastMileOrdersView, { attachTo: document.body, global: { plugins: [createPinia(), ElementPlus] } })
await flushPromises()
expect(convertLastMileContainerToInboundPlans).toHaveBeenCalledTimes(1)
expect(convertLastMileContainerToInboundPlans).toHaveBeenCalledWith({ sourceContainerBookingId: '2092873463568597001' })
expect(convertLastMileOrderToInboundPlan).not.toHaveBeenCalled()
expect(listLastMileOrders).toHaveBeenCalledTimes(3)
expect(document.body.textContent).toContain('已为2个尾程订单生成2个入库计划')
})
it.each([
['A0404', 'Container orders not found'],
['A0409', 'Container conversion conflict'],
])('keeps %s request evidence after the atomic operation fails', async (code, message) => {
vi.mocked(listLastMileOrders)
.mockResolvedValueOnce({ records: [], page: 1, size: 10, total: 0, pages: 0 })
.mockResolvedValueOnce({ records: containerRecords, page: 1, size: 10, total: 2, pages: 1 })
vi.mocked(convertLastMileContainerToInboundPlans).mockRejectedValueOnce(new ApiResponseError(
message, code, 200, undefined, `request-${code}`, `trace-${code}`,
))
const wrapper = await mountView()
await openPendingContainers(wrapper)
const button = wrapper.findAll('button').find((item) => item.text().includes('生成整柜入库计划'))
await button!.trigger('click')
const pendingTab = wrapper.findAll('.el-radio-button').find((item) => item.text().includes('待分配'))
await pendingTab!.trigger('click')
await flushPromises()
expect(wrapper.text()).toContain(code)
expect(wrapper.text()).toContain(`request-${code}`)
expect(wrapper.text()).toContain(`trace-${code}`)
expect(wrapper.text()).toContain('已停止从订单分页本地聚合整柜')
expect(listLastMileOrders).toHaveBeenCalledTimes(1)
expect(convertLastMileContainerToInboundPlans).not.toHaveBeenCalled()
expect(convertLastMileOrderToInboundPlan).not.toHaveBeenCalled()
})
})
@@ -17,7 +17,7 @@ import OrderReferenceText from '../components/OrderReferenceText.vue'
import { useAccessPreviewStore } from '@/core/access/accessPreview'
import { overseasWarehousePermissions as permission } from '../permissions'
import { toLastMileOrderListItem } from '../lastMilePresentation'
import { groupPendingOrdersByContainer, type LastMileContainerPlanRow } from '../lastMileContainerPlanning'
import type { LastMileContainerPlanRow } from '../lastMileContainerPlanning'
import type { LastMileOrderListItem } from '../types'
const rows = ref<LastMileOrderListItem[]>([])
@@ -29,6 +29,7 @@ const page = ref(1)
const pageSize = ref(10)
const total = ref(0)
const selectedRows = ref<LastMileOrderListItem[]>([])
const containerRows = ref<LastMileContainerPlanRow[]>([])
const actionLoading = ref(false)
const actionError = ref<ApiErrorDetails | null>(null)
const transferOpen = ref(false)
@@ -106,12 +107,19 @@ const containerColumns: DataTableColumn[] = [
{ key: 'eligibility', prop: 'eligibility', label: '资格', minWidth: 160, slotName: 'eligibility' },
{ key: 'planNotice', prop: 'planNotice', label: '生成说明', minWidth: 320 },
]
const containerRows = computed(() => groupPendingOrdersByContainer(rows.value))
async function load(model: QueryModel = filters.value) {
Object.assign(filters.value, model)
loading.value = true
loadError.value = null
if (statusTab.value === '待分配') {
rows.value = []
containerRows.value = []
total.value = 0
loadError.value = { message: '柜级待分配摘要分页接口尚未在当前 test 后端提供,已停止从订单分页本地聚合整柜' }
loading.value = false
return
}
try {
const dateRange = Array.isArray(filters.value.createdAt) ? filters.value.createdAt.map(String) : []
const booleanValue = (value: unknown) => value === 'true' ? true : value === 'false' ? false : undefined
@@ -124,7 +132,7 @@ async function load(model: QueryModel = filters.value) {
inboundCode: String(filters.value.inboundCode || '').trim() || undefined,
sourceOrderNo: String(filters.value.sourceOrderNo || '').trim() || undefined,
containerNo: String(filters.value.containerNo || '').trim() || undefined,
currentStatus: statusTab.value === '待分配' ? 'PENDING_ASSIGNMENT' : String(filters.value.status || '').trim() || undefined,
currentStatus: String(filters.value.status || '').trim() || undefined,
transferWarehouseCode: String(filters.value.transferWarehouseCode || '').trim() || undefined,
abnormal: booleanValue(filters.value.abnormal),
detained: booleanValue(filters.value.detained),