优化
This commit is contained in:
@@ -2,14 +2,15 @@ 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 { convertLastMileContainerToInboundPlans, convertLastMileOrderToInboundPlan, listLastMileOrders } from '../api/lastMileOrders'
|
||||
import { ApiResponseError } from '@/shared/api/http'
|
||||
import { convertLastMileContainerToInboundPlans, convertLastMileOrderToInboundPlan, listLastMileOrders, listPendingContainerSummaries } 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(), listPendingContainerSummaries: vi.fn(),
|
||||
convertLastMileContainerToInboundPlans: vi.fn(), convertLastMileOrderToInboundPlan: vi.fn(), transferLastMileOrders: vi.fn(),
|
||||
}))
|
||||
|
||||
class ResizeObserverStub implements ResizeObserver { observe() {} unobserve() {} disconnect() {} }
|
||||
@@ -21,27 +22,96 @@ function memoryStorage(): Storage {
|
||||
}
|
||||
}
|
||||
|
||||
const summary = {
|
||||
sourceContainerBookingId: '2092873463568597001', containerNo: 'CONT-15', orderCount: 15,
|
||||
inboundCodeCount: 15, customerCount: 3, totalPackageCount: 150, totalPalletCount: 30,
|
||||
totalVolumeCbm: 45.5, eligible: true, ineligibleReason: null,
|
||||
}
|
||||
function plans(count = 15) {
|
||||
return Array.from({ length: count }, (_, index) => ({
|
||||
id: String(index + 1), planNo: `LIP-${index + 1}`, customerId: String(index % 3 + 1), sourceOrderId: String(index + 1),
|
||||
containerNo: 'CONT-15', status: 'PENDING_ASSIGNMENT', lineCount: 1, palletCount: 1, totalVolumeCbm: 1,
|
||||
lines: [], pallets: [], allocations: [],
|
||||
}))
|
||||
}
|
||||
|
||||
enableAutoUnmount(afterEach)
|
||||
afterAll(() => vi.unstubAllGlobals())
|
||||
|
||||
describe('LastMileOrdersView container boundary', () => {
|
||||
async function openPending() {
|
||||
const wrapper = mount(LastMileOrdersView, { attachTo: document.body, global: { plugins: [createPinia(), ElementPlus] } })
|
||||
await flushPromises()
|
||||
const pendingTab = wrapper.findAll('.el-radio-button').find((item) => item.text().includes('待分配'))
|
||||
await pendingTab!.trigger('click')
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
describe('LastMileOrdersView server-side container summaries', () => {
|
||||
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(convertLastMileContainerToInboundPlans).mockReset()
|
||||
vi.mocked(listPendingContainerSummaries).mockReset().mockResolvedValue({ records: [summary], page: 1, size: 10, total: 21, pages: 3 })
|
||||
vi.mocked(convertLastMileContainerToInboundPlans).mockReset().mockResolvedValue(plans())
|
||||
vi.mocked(convertLastMileOrderToInboundPlan).mockReset()
|
||||
})
|
||||
|
||||
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()
|
||||
const pendingTab = wrapper.findAll('.el-radio-button').find((item) => item.text().includes('待分配'))
|
||||
await pendingTab!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain('已停止从订单分页本地聚合整柜')
|
||||
it('uses one server summary for a 15-order container that could span order pages', async () => {
|
||||
const wrapper = await openPending()
|
||||
expect(listPendingContainerSummaries).toHaveBeenCalledWith({ page: 1, size: 10, containerNo: undefined, createdFrom: undefined, createdTo: undefined })
|
||||
expect(wrapper.text()).toContain('CONT-15')
|
||||
expect(wrapper.text()).toContain('15')
|
||||
expect(wrapper.text()).toContain('将为 15 个尾程订单生成 15 个独立入库计划')
|
||||
expect(listLastMileOrders).toHaveBeenCalledTimes(1)
|
||||
expect(convertLastMileContainerToInboundPlans).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('requests the next server summary page instead of deriving containers from order rows', async () => {
|
||||
const wrapper = await openPending()
|
||||
const nextPage = wrapper.find('button[aria-label="第 2 页"]')
|
||||
expect(nextPage.exists()).toBe(true)
|
||||
await nextPage.trigger('click')
|
||||
await flushPromises()
|
||||
expect(listPendingContainerSummaries).toHaveBeenLastCalledWith({
|
||||
page: 2, size: 10, containerNo: undefined, createdFrom: undefined, createdTo: undefined,
|
||||
})
|
||||
expect(listLastMileOrders).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it('calls convert-container once, validates N plans and refreshes the server summary', async () => {
|
||||
const wrapper = await openPending()
|
||||
const button = wrapper.findAll('button').find((item) => item.text().includes('生成整柜入库计划'))
|
||||
await button!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(convertLastMileContainerToInboundPlans).toHaveBeenCalledTimes(1)
|
||||
expect(convertLastMileContainerToInboundPlans).toHaveBeenCalledWith({ sourceContainerBookingId: '2092873463568597001' })
|
||||
expect(convertLastMileOrderToInboundPlan).not.toHaveBeenCalled()
|
||||
expect(listPendingContainerSummaries).toHaveBeenCalledTimes(2)
|
||||
expect(document.body.textContent).toContain('已为15个尾程订单生成15个入库计划')
|
||||
})
|
||||
|
||||
it('does not report success or refresh when N returned plans do not match N orders', async () => {
|
||||
vi.mocked(convertLastMileContainerToInboundPlans).mockResolvedValueOnce(plans(14))
|
||||
const wrapper = await openPending()
|
||||
const button = wrapper.findAll('button').find((item) => item.text().includes('生成整柜入库计划'))
|
||||
await button!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(convertLastMileContainerToInboundPlans).toHaveBeenCalledTimes(1)
|
||||
expect(listPendingContainerSummaries).toHaveBeenCalledTimes(1)
|
||||
expect(wrapper.text()).toContain('返回 14 个计划')
|
||||
expect(document.body.textContent).not.toContain('已为15个尾程订单生成14个入库计划')
|
||||
})
|
||||
|
||||
it.each(['A0404', 'A0409'])('keeps %s request evidence visible', async (code) => {
|
||||
vi.mocked(convertLastMileContainerToInboundPlans).mockRejectedValueOnce(new ApiResponseError(
|
||||
'柜级生成失败', code, 200, undefined, `request-${code}`, `trace-${code}`,
|
||||
))
|
||||
const wrapper = await openPending()
|
||||
const button = wrapper.findAll('button').find((item) => item.text().includes('生成整柜入库计划'))
|
||||
await button!.trigger('click')
|
||||
await flushPromises()
|
||||
expect(wrapper.text()).toContain(code)
|
||||
expect(wrapper.text()).toContain(`request-${code}`)
|
||||
expect(wrapper.text()).toContain(`trace-${code}`)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user