2026-08-27 15:56:13 +08:00
|
|
|
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'
|
2026-08-27 17:16:38 +08:00
|
|
|
import { ApiResponseError } from '@/shared/api/http'
|
2026-08-27 17:49:05 +08:00
|
|
|
import DataTable from '@/shared/components/DataTable.vue'
|
|
|
|
|
import {
|
|
|
|
|
convertLastMileContainerToInboundPlans,
|
|
|
|
|
convertLastMileOrderToInboundPlan,
|
|
|
|
|
listLastMileOrders,
|
|
|
|
|
listPendingContainerSummaries,
|
|
|
|
|
} from '../api/lastMileOrders'
|
2026-08-27 15:56:13 +08:00
|
|
|
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', () => ({
|
2026-08-27 17:16:38 +08:00
|
|
|
listLastMileOrders: vi.fn(), listPendingContainerSummaries: vi.fn(),
|
2026-08-27 17:49:05 +08:00
|
|
|
convertLastMileOrderToInboundPlan: vi.fn(), convertLastMileContainerToInboundPlans: vi.fn(), transferLastMileOrders: vi.fn(),
|
2026-08-27 15:56:13 +08:00
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
class ResizeObserverStub implements ResizeObserver { observe() {} unobserve() {} disconnect() {} }
|
|
|
|
|
function memoryStorage(): Storage {
|
|
|
|
|
const values = new Map<string, string>()
|
|
|
|
|
return {
|
2026-08-27 16:42:32 +08:00
|
|
|
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),
|
2026-08-27 15:56:13 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-27 17:49:05 +08:00
|
|
|
const bookingId = '2092873463568597001'
|
|
|
|
|
const customerId = '2092618717861048321'
|
2026-08-27 17:16:38 +08:00
|
|
|
const summary = {
|
2026-08-27 17:49:05 +08:00
|
|
|
sourceContainerBookingId: bookingId, containerNo: 'CONT-15', orderCount: 15,
|
2026-08-27 17:16:38 +08:00
|
|
|
inboundCodeCount: 15, customerCount: 3, totalPackageCount: 150, totalPalletCount: 30,
|
|
|
|
|
totalVolumeCbm: 45.5, eligible: true, ineligibleReason: null,
|
|
|
|
|
}
|
2026-08-27 17:49:05 +08:00
|
|
|
function selectedRow(overrides: Record<string, unknown> = {}) {
|
|
|
|
|
return { id: '2092873463568596994', customerId, sourceContainerBookingId: bookingId, orderNo: 'LMO-260827-0001', ...overrides }
|
2026-08-27 17:16:38 +08:00
|
|
|
}
|
|
|
|
|
|
2026-08-27 15:56:13 +08:00
|
|
|
enableAutoUnmount(afterEach)
|
|
|
|
|
afterAll(() => vi.unstubAllGlobals())
|
|
|
|
|
|
2026-08-27 17:49:05 +08:00
|
|
|
async function mountView() {
|
2026-08-27 17:16:38 +08:00
|
|
|
const wrapper = mount(LastMileOrdersView, { attachTo: document.body, global: { plugins: [createPinia(), ElementPlus] } })
|
|
|
|
|
await flushPromises()
|
2026-08-27 17:49:05 +08:00
|
|
|
return wrapper
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function openPending() {
|
|
|
|
|
const wrapper = await mountView()
|
|
|
|
|
const pendingTab = wrapper.findAll('.el-radio-button').find((item) => item.text() === '待分配')
|
2026-08-27 17:16:38 +08:00
|
|
|
await pendingTab!.trigger('click')
|
|
|
|
|
await flushPromises()
|
|
|
|
|
return wrapper
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-27 17:49:05 +08:00
|
|
|
async function selectRows(wrapper: Awaited<ReturnType<typeof mountView>>, rows: object[]) {
|
|
|
|
|
wrapper.findComponent(DataTable).vm.$emit('selection-change', rows)
|
|
|
|
|
await wrapper.vm.$nextTick()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function button(wrapper: Awaited<ReturnType<typeof mountView>>, text: string) {
|
|
|
|
|
return wrapper.findAll('button').find((item) => item.text().includes(text))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function openContainerDialog(wrapper: Awaited<ReturnType<typeof mountView>>) {
|
|
|
|
|
await button(wrapper, '按柜批量生成')!.trigger('click')
|
|
|
|
|
await flushPromises()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function chooseContainer(wrapper: Awaited<ReturnType<typeof mountView>>) {
|
|
|
|
|
const selects = wrapper.findAllComponents({ name: 'ElSelect' })
|
|
|
|
|
const containerSelect = selects[selects.length - 1]
|
|
|
|
|
expect(containerSelect).toBeDefined()
|
|
|
|
|
containerSelect.vm.$emit('update:modelValue', bookingId)
|
|
|
|
|
await wrapper.vm.$nextTick()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
describe('LastMileOrdersView pending order and container conversion', () => {
|
2026-08-27 15:56:13 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.stubGlobal('ResizeObserver', ResizeObserverStub)
|
|
|
|
|
vi.stubGlobal('localStorage', memoryStorage())
|
|
|
|
|
vi.mocked(listLastMileOrders).mockReset().mockResolvedValue({ records: [], page: 1, size: 10, total: 0, pages: 0 })
|
2026-08-27 17:49:05 +08:00
|
|
|
vi.mocked(listPendingContainerSummaries).mockReset().mockResolvedValue({ records: [summary], page: 1, size: 50, total: 1, pages: 1 })
|
|
|
|
|
vi.mocked(convertLastMileOrderToInboundPlan).mockReset().mockResolvedValue({})
|
|
|
|
|
vi.mocked(convertLastMileContainerToInboundPlans).mockReset().mockResolvedValue([{ planNo: 'LIP-1' }, { planNo: 'LIP-2' }] as never)
|
2026-08-27 15:56:13 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-27 17:49:05 +08:00
|
|
|
it('keeps the original pending order table and does not render a view switch or container table', async () => {
|
2026-08-27 17:16:38 +08:00
|
|
|
const wrapper = await openPending()
|
2026-08-27 17:49:05 +08:00
|
|
|
expect(wrapper.text()).toContain('尾程单号')
|
|
|
|
|
expect(wrapper.text()).toContain('海外仓')
|
|
|
|
|
expect(wrapper.text()).toContain('转仓')
|
|
|
|
|
expect(wrapper.text()).toContain('生成入库计划')
|
|
|
|
|
expect(wrapper.text()).toContain('按柜批量生成')
|
|
|
|
|
expect(wrapper.text()).not.toContain('按订单')
|
|
|
|
|
expect(wrapper.text()).not.toContain('待分配整柜')
|
|
|
|
|
expect(listLastMileOrders).toHaveBeenLastCalledWith(expect.objectContaining({ page: 1, size: 10, currentStatus: 'PENDING_ASSIGNMENT' }))
|
|
|
|
|
expect(listPendingContainerSummaries).not.toHaveBeenCalled()
|
2026-08-27 17:16:38 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-27 17:49:05 +08:00
|
|
|
it('keeps single-order conversion isolated with long order and customer ids', async () => {
|
2026-08-27 17:16:38 +08:00
|
|
|
const wrapper = await openPending()
|
2026-08-27 17:49:05 +08:00
|
|
|
await selectRows(wrapper, [selectedRow()])
|
|
|
|
|
await button(wrapper, '生成入库计划')!.trigger('click')
|
2026-08-27 17:16:38 +08:00
|
|
|
await flushPromises()
|
2026-08-27 17:49:05 +08:00
|
|
|
expect(convertLastMileOrderToInboundPlan).toHaveBeenCalledTimes(1)
|
|
|
|
|
expect(convertLastMileOrderToInboundPlan).toHaveBeenCalledWith({ orderId: '2092873463568596994', customerId })
|
|
|
|
|
expect(convertLastMileContainerToInboundPlans).not.toHaveBeenCalled()
|
|
|
|
|
expect(listPendingContainerSummaries).not.toHaveBeenCalled()
|
2026-08-27 17:16:38 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-27 17:49:05 +08:00
|
|
|
it('opens a cabinet selector without requiring order selection and loads server summaries only then', async () => {
|
2026-08-27 17:16:38 +08:00
|
|
|
const wrapper = await openPending()
|
2026-08-27 17:49:05 +08:00
|
|
|
await openContainerDialog(wrapper)
|
2026-08-27 17:16:38 +08:00
|
|
|
expect(listPendingContainerSummaries).toHaveBeenCalledTimes(1)
|
2026-08-27 17:49:05 +08:00
|
|
|
expect(listPendingContainerSummaries).toHaveBeenCalledWith({ page: 1, size: 50, containerNo: undefined })
|
|
|
|
|
expect(document.body.textContent).toContain('选择待分配柜')
|
|
|
|
|
expect(document.body.textContent).toContain('将为所选柜内所有待分配尾程订单分别生成独立入库计划')
|
|
|
|
|
expect(convertLastMileContainerToInboundPlans).not.toHaveBeenCalled()
|
2026-08-27 17:16:38 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-27 17:49:05 +08:00
|
|
|
it('selects one cabinet and sends one long-id convert-container request without using current-page row counts', async () => {
|
|
|
|
|
const wrapper = await openPending()
|
|
|
|
|
await openContainerDialog(wrapper)
|
|
|
|
|
await chooseContainer(wrapper)
|
|
|
|
|
const confirm = [...document.body.querySelectorAll('button')].find((item) => item.textContent?.includes('确认按柜生成')) as HTMLButtonElement
|
|
|
|
|
expect(confirm.disabled).toBe(false)
|
|
|
|
|
confirm.click()
|
|
|
|
|
await flushPromises()
|
|
|
|
|
expect(convertLastMileContainerToInboundPlans).toHaveBeenCalledTimes(1)
|
|
|
|
|
expect(convertLastMileContainerToInboundPlans).toHaveBeenCalledWith({ sourceContainerBookingId: bookingId })
|
|
|
|
|
expect(convertLastMileOrderToInboundPlan).not.toHaveBeenCalled()
|
|
|
|
|
expect(document.body.textContent).toContain('已按柜生成 2 个独立入库计划')
|
|
|
|
|
expect(listLastMileOrders).toHaveBeenCalledTimes(3)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it.each(['A0404', 'A0409'])('keeps %s request evidence visible after cabinet conversion failure', async (code) => {
|
2026-08-27 17:16:38 +08:00
|
|
|
vi.mocked(convertLastMileContainerToInboundPlans).mockRejectedValueOnce(new ApiResponseError(
|
|
|
|
|
'柜级生成失败', code, 200, undefined, `request-${code}`, `trace-${code}`,
|
|
|
|
|
))
|
|
|
|
|
const wrapper = await openPending()
|
2026-08-27 17:49:05 +08:00
|
|
|
await openContainerDialog(wrapper)
|
|
|
|
|
await chooseContainer(wrapper)
|
|
|
|
|
const confirm = [...document.body.querySelectorAll('button')].find((item) => item.textContent?.includes('确认按柜生成')) as HTMLButtonElement
|
|
|
|
|
confirm.click()
|
2026-08-27 17:16:38 +08:00
|
|
|
await flushPromises()
|
2026-08-27 17:49:05 +08:00
|
|
|
expect(convertLastMileContainerToInboundPlans).toHaveBeenCalledTimes(1)
|
2026-08-27 17:16:38 +08:00
|
|
|
expect(wrapper.text()).toContain(code)
|
|
|
|
|
expect(wrapper.text()).toContain(`request-${code}`)
|
|
|
|
|
expect(wrapper.text()).toContain(`trace-${code}`)
|
2026-08-27 15:56:13 +08:00
|
|
|
})
|
|
|
|
|
})
|