优化
This commit is contained in:
@@ -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()
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user