2026-08-29 10:57:01 +08:00
|
|
|
|
import ElementPlus, { ElMessageBox } from 'element-plus'
|
2026-08-11 11:15:44 +08:00
|
|
|
|
import { AxiosError } from 'axios'
|
2026-08-10 15:36:53 +08:00
|
|
|
|
import { createPinia, setActivePinia } from 'pinia'
|
|
|
|
|
|
import { createMemoryHistory, createRouter } from 'vue-router'
|
|
|
|
|
|
import { flushPromises, mount } from '@vue/test-utils'
|
|
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
2026-08-12 18:00:26 +08:00
|
|
|
|
import { readFileSync } from 'node:fs'
|
|
|
|
|
|
import { resolve } from 'node:path'
|
2026-08-10 15:36:53 +08:00
|
|
|
|
import SmartLoadingWorkbenchView from './SmartLoadingWorkbenchView.vue'
|
2026-08-29 10:57:01 +08:00
|
|
|
|
import { assignSmartLoadingGroup, assignSmartLoadingItem, getContainer, getSmartLoadingPlanByBooking, listSmartLoadingCandidates, recommendSmartLoading, removeSmartLoadingGroup } from '../api/platformContainerLoading'
|
2026-08-10 15:36:53 +08:00
|
|
|
|
|
|
|
|
|
|
vi.mock('../api/platformContainerLoading', () => ({
|
|
|
|
|
|
getContainer: vi.fn(), getSmartLoadingPlanByBooking: vi.fn(), listSmartLoadingCandidates: vi.fn(),
|
2026-08-29 10:57:01 +08:00
|
|
|
|
createSmartLoadingPlan: vi.fn(), assignSmartLoadingItem: vi.fn(), assignSmartLoadingGroup: vi.fn(), recommendSmartLoading: vi.fn(),
|
|
|
|
|
|
adjustSmartLoadingItem: vi.fn(), removeSmartLoadingItem: vi.fn(), removeSmartLoadingGroup: vi.fn(), pushSmartLoadingPreload: vi.fn(),
|
2026-08-10 15:36:53 +08:00
|
|
|
|
}))
|
2026-08-31 10:48:23 +08:00
|
|
|
|
vi.mock('../smartLoadingPlanGroups', () => ({ loadSmartLoadingPlanCoLoadGroups: vi.fn().mockResolvedValue(new Map()) }))
|
2026-08-11 11:15:44 +08:00
|
|
|
|
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: () => true }) }))
|
2026-08-10 15:36:53 +08:00
|
|
|
|
|
|
|
|
|
|
const container = {
|
|
|
|
|
|
id: '9007199254740993', planId: '9007199254740994', bookingNo: 'BK-1', cabinetNo: 'CB-1', containerNo: 'MSCU-1',
|
2026-08-17 12:31:27 +08:00
|
|
|
|
warehouseId: '8', warehouseName: '义乌仓', channelCode: 'ZBYHK', channelName: '美森正班海卡包税', containerType: '40HC', planStatus: 'EDITING' as const, version: 1,
|
2026-08-10 15:36:53 +08:00
|
|
|
|
billOfLadingNo: null, vesselName: null, voyageNo: null, shippingCompanyId: null, shippingCompanyName: null,
|
|
|
|
|
|
departurePortCode: null, departurePortName: null, destinationPortCode: null, destinationPortName: null,
|
2026-08-17 12:31:27 +08:00
|
|
|
|
destinationWarehouseCode: 'LAX9', destinationWarehouseName: 'LAX9', capacityCbm: 76, maxWeightKg: 28000,
|
2026-08-25 19:56:37 +08:00
|
|
|
|
terminalTruckingCompanyId: null, terminalTruckingCompany: null, loadingAt: null, estimatedSailingAt: null, actualSailingAt: null,
|
2026-08-10 15:36:53 +08:00
|
|
|
|
estimatedPortArrivalAt: null, actualPortArrivalAt: null, estimatedWarehouseArrivalAt: null, actualWarehouseArrivalAt: null,
|
|
|
|
|
|
}
|
2026-08-17 16:45:46 +08:00
|
|
|
|
const planResponse = {
|
|
|
|
|
|
id: '99', bookingId: container.id, planNo: 'LP-99', status: 'EDITING' as const, containerNo: 'MSCU-1', voyageNo: null, version: 2,
|
|
|
|
|
|
canAssign: true, canEdit: true, blockedReason: null, finalCompletionStatus: 'NOT_STARTED' as const,
|
|
|
|
|
|
pdaTaskId: null, pdaTaskStatus: null, pdaTaskVersion: null, items: [],
|
|
|
|
|
|
}
|
2026-08-29 10:57:01 +08:00
|
|
|
|
const candidate = { accountId: '1', inboundId: '2', orderId: '4', orderNo: 'ORD-1', inboundCode: 'IN-1', warehouseId: '8', channelCode: 'ZBYHK', channelName: '美森正班海卡包税', destinationWarehouseId: '9', destinationWarehouseCode: 'LAX9', destinationWarehouseName: 'LAX9', customerName: '示例企业', goodsSummary: '服装', availablePackageCount: 12, unitGrossWeightKg: 10, unitNetWeightKg: 9, averageUnitVolumeCbm: 0.2, availableVolumeCbm: 2.4, coLoadGroupId: null, groupNo: null, memberCount: null, groupTotalBoxes: null, locked: null, blockReason: null }
|
2026-08-10 15:36:53 +08:00
|
|
|
|
|
|
|
|
|
|
describe('SmartLoadingWorkbenchView', () => {
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
|
setActivePinia(createPinia())
|
2026-08-11 11:15:44 +08:00
|
|
|
|
vi.clearAllMocks()
|
2026-08-10 15:36:53 +08:00
|
|
|
|
vi.mocked(getContainer).mockResolvedValue(container)
|
2026-08-17 16:45:46 +08:00
|
|
|
|
vi.mocked(getSmartLoadingPlanByBooking).mockResolvedValue(planResponse)
|
2026-08-29 10:57:01 +08:00
|
|
|
|
vi.mocked(listSmartLoadingCandidates).mockResolvedValue([candidate])
|
2026-08-10 15:36:53 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('restores the real draft and explains candidate capacity', async () => {
|
|
|
|
|
|
const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/container-loading/:containerId/smart-loading', component: SmartLoadingWorkbenchView }] })
|
|
|
|
|
|
await router.push(`/container-loading/${container.id}/smart-loading`); await router.isReady()
|
|
|
|
|
|
const wrapper = mount(SmartLoadingWorkbenchView, { global: { plugins: [ElementPlus, router] } })
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
expect(getContainer).toHaveBeenCalledWith(container.id)
|
|
|
|
|
|
expect(getSmartLoadingPlanByBooking).toHaveBeenCalledWith(container.id)
|
2026-08-12 18:43:54 +08:00
|
|
|
|
expect(listSmartLoadingCandidates).toHaveBeenCalledWith(container.id, '8')
|
2026-08-14 19:59:32 +08:00
|
|
|
|
expect(wrapper.text()).toContain('MSCU-1 装柜方案')
|
|
|
|
|
|
expect(wrapper.text()).not.toContain('LP-99')
|
|
|
|
|
|
expect(wrapper.text()).toContain('IN-1')
|
|
|
|
|
|
expect(wrapper.text()).not.toContain('ORD-1')
|
|
|
|
|
|
expect(wrapper.text()).toContain('110% 容量上限')
|
2026-08-10 15:36:53 +08:00
|
|
|
|
})
|
2026-08-11 11:15:44 +08:00
|
|
|
|
|
2026-08-17 16:45:46 +08:00
|
|
|
|
it('uses loading plan capabilities to keep PDA increments editable', async () => {
|
2026-08-11 11:15:44 +08:00
|
|
|
|
vi.mocked(getContainer).mockResolvedValue({ ...container, planStatus: 'LOADING' })
|
2026-08-17 16:45:46 +08:00
|
|
|
|
vi.mocked(getSmartLoadingPlanByBooking).mockResolvedValue({ ...planResponse, status: 'LOADING', pdaTaskId: '700', pdaTaskStatus: 'LOADING', pdaTaskVersion: 4 })
|
2026-08-11 11:15:44 +08:00
|
|
|
|
const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/container-loading/:containerId/smart-loading', component: SmartLoadingWorkbenchView }] })
|
|
|
|
|
|
await router.push(`/container-loading/${container.id}/smart-loading`); await router.isReady()
|
|
|
|
|
|
const wrapper = mount(SmartLoadingWorkbenchView, { global: { plugins: [ElementPlus, router] } })
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
2026-08-17 16:45:46 +08:00
|
|
|
|
expect(getSmartLoadingPlanByBooking).toHaveBeenCalledWith(container.id)
|
|
|
|
|
|
expect(listSmartLoadingCandidates).toHaveBeenCalledWith(container.id, container.warehouseId)
|
|
|
|
|
|
expect(wrapper.text()).toContain('已下发 PDA,仍可维护未完成的装柜明细')
|
|
|
|
|
|
expect(wrapper.text()).toContain('刷新 PDA 明细与版本')
|
2026-08-14 19:59:32 +08:00
|
|
|
|
expect(wrapper.text()).not.toContain('智能推荐')
|
2026-08-17 16:45:46 +08:00
|
|
|
|
expect(wrapper.text()).toContain('IN-1')
|
2026-08-11 11:15:44 +08:00
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('refreshes the latest plan after A0409', async () => {
|
|
|
|
|
|
vi.mocked(getSmartLoadingPlanByBooking)
|
2026-08-17 16:45:46 +08:00
|
|
|
|
.mockResolvedValueOnce(planResponse)
|
|
|
|
|
|
.mockResolvedValueOnce({ ...planResponse, version: 3 })
|
2026-08-22 10:02:13 +08:00
|
|
|
|
vi.mocked(recommendSmartLoading).mockRejectedValueOnce(new AxiosError(
|
2026-08-11 11:15:44 +08:00
|
|
|
|
'conflict', 'ERR_BAD_REQUEST', undefined, undefined,
|
|
|
|
|
|
{ data: { code: 'A0409', message: '数据已被修改', requestId: 'request-1', traceId: 'trace-1' }, status: 200, statusText: 'OK', headers: {}, config: {} as never },
|
2026-08-22 10:02:13 +08:00
|
|
|
|
)).mockResolvedValueOnce({ ...planResponse, version: 4 })
|
2026-08-11 11:15:44 +08:00
|
|
|
|
const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/container-loading/:containerId/smart-loading', component: SmartLoadingWorkbenchView }] })
|
|
|
|
|
|
await router.push(`/container-loading/${container.id}/smart-loading`); await router.isReady()
|
|
|
|
|
|
const wrapper = mount(SmartLoadingWorkbenchView, { global: { plugins: [ElementPlus, router] } })
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
|
|
|
|
|
|
await wrapper.findAll('button').find((button) => button.text().includes('智能推荐'))!.trigger('click')
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
expect(getSmartLoadingPlanByBooking).toHaveBeenCalledTimes(2)
|
2026-08-22 10:02:13 +08:00
|
|
|
|
expect(recommendSmartLoading).toHaveBeenCalledWith(planResponse.id, 2)
|
|
|
|
|
|
expect(recommendSmartLoading).toHaveBeenCalledWith(planResponse.id, 3)
|
|
|
|
|
|
expect(wrapper.text()).not.toContain('排柜操作失败')
|
2026-08-11 11:15:44 +08:00
|
|
|
|
})
|
2026-08-12 18:00:26 +08:00
|
|
|
|
|
|
|
|
|
|
it('uses bordered row actions and keeps push independent from containerNo', () => {
|
|
|
|
|
|
const source = readFileSync(resolve(process.cwd(), 'src/modules/container-loading/pages/SmartLoadingWorkbenchView.vue'), 'utf8')
|
|
|
|
|
|
expect(source).toContain('size="small" type="primary" plain')
|
|
|
|
|
|
expect(source).toContain('size="small" type="danger" plain')
|
|
|
|
|
|
expect(source).toContain("canPush && plan?.status === 'EDITING'")
|
|
|
|
|
|
expect(source).not.toContain("canPush && plan?.status === 'EDITING' && container?.containerNo")
|
2026-08-15 17:04:00 +08:00
|
|
|
|
expect(source).toContain('推送后生成预装清单,不会直接开放 PDA')
|
2026-08-27 21:48:15 +08:00
|
|
|
|
expect(source).toContain('后续还需补集装箱号、确认预装。确认继续?')
|
|
|
|
|
|
expect(source).toContain('预装清单已生成,请继续完成集装箱号和预装确认')
|
|
|
|
|
|
expect(source).not.toContain('关联并放舱真实订舱')
|
|
|
|
|
|
expect(source).not.toContain('订舱放舱')
|
2026-08-12 18:00:26 +08:00
|
|
|
|
expect(source).not.toContain('link type="primary" :disabled="!routeMatches(row)')
|
2026-08-14 19:59:32 +08:00
|
|
|
|
expect(source).not.toContain("label: '目的仓'")
|
|
|
|
|
|
expect(source).not.toContain('plan.planNo')
|
2026-08-12 18:16:44 +08:00
|
|
|
|
expect(source.match(/<DataTable[^>]*\bstripe\b/g)).toHaveLength(2)
|
2026-08-15 17:04:00 +08:00
|
|
|
|
expect(source).toContain('<span>柜次号</span>')
|
|
|
|
|
|
expect(source).toContain('<span>集装箱号</span>')
|
|
|
|
|
|
expect(source).not.toContain('当前柜号')
|
2026-08-12 18:00:26 +08:00
|
|
|
|
})
|
2026-08-27 21:48:15 +08:00
|
|
|
|
|
|
|
|
|
|
it('keeps the package count editor inside its table cell without overflow ellipsis', () => {
|
|
|
|
|
|
const source = readFileSync(resolve(process.cwd(), 'src/modules/container-loading/pages/SmartLoadingWorkbenchView.vue'), 'utf8')
|
2026-08-29 10:57:01 +08:00
|
|
|
|
expect(source).toContain('<div v-else class="package-count-editor"><el-input-number')
|
2026-08-27 21:48:15 +08:00
|
|
|
|
expect(source).toContain('.workbench :deep(.package-count-editor .el-input-number) { width: 100%; min-width: 0; }')
|
|
|
|
|
|
})
|
2026-08-29 10:57:01 +08:00
|
|
|
|
|
|
|
|
|
|
it('aggregates a two-order group and calls only the atomic whole-group assignment', async () => {
|
|
|
|
|
|
vi.mocked(listSmartLoadingCandidates).mockResolvedValue([
|
2026-08-30 15:49:01 +08:00
|
|
|
|
{ ...candidate, inboundId: '201', orderId: '301', inboundCode: 'IN-201', availablePackageCount: 4, availableVolumeCbm: 0.8, coLoadGroupId: '9007199254740999', groupNo: 'CLG-9007199254740999', memberCount: 3, groupTotalBoxes: 12, locked: false, blockReason: null },
|
|
|
|
|
|
{ ...candidate, inboundId: '203', orderId: '301', orderNo: 'ORD-1', inboundCode: 'IN-203', availablePackageCount: 2, availableVolumeCbm: 0.4, coLoadGroupId: '9007199254740999', groupNo: 'CLG-9007199254740999', memberCount: 3, groupTotalBoxes: 12, locked: false, blockReason: null },
|
|
|
|
|
|
{ ...candidate, accountId: '2', inboundId: '202', orderId: '302', inboundCode: 'IN-202', availablePackageCount: 6, availableVolumeCbm: 1.2, coLoadGroupId: '9007199254740999', groupNo: 'CLG-9007199254740999', memberCount: 3, groupTotalBoxes: 12, locked: false, blockReason: null },
|
2026-08-29 10:57:01 +08:00
|
|
|
|
])
|
|
|
|
|
|
vi.mocked(assignSmartLoadingGroup).mockResolvedValue(planResponse)
|
|
|
|
|
|
const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/container-loading/:containerId/smart-loading', component: SmartLoadingWorkbenchView }] })
|
|
|
|
|
|
await router.push(`/container-loading/${container.id}/smart-loading`); await router.isReady()
|
|
|
|
|
|
const wrapper = mount(SmartLoadingWorkbenchView, { attachTo: document.body, global: { plugins: [ElementPlus, router] } })
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
expect(wrapper.text()).toContain('CLG-9007199254740999 · 2 票')
|
2026-08-30 15:49:01 +08:00
|
|
|
|
expect(wrapper.text()).toContain('3 个入仓片段')
|
|
|
|
|
|
expect(wrapper.text()).toContain('ORD-1:IN-201、IN-203')
|
|
|
|
|
|
expect(wrapper.text()).toContain('整组 12 箱')
|
2026-08-29 10:57:01 +08:00
|
|
|
|
expect(wrapper.findAll('button').filter((button) => button.text().includes('整组分配'))).toHaveLength(1)
|
|
|
|
|
|
await wrapper.findAll('button').find((button) => button.text().includes('整组分配'))!.trigger('click')
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
;([...document.body.querySelectorAll('button')].find((button) => button.textContent?.includes('确认整组分配')) as HTMLButtonElement).click()
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
expect(assignSmartLoadingGroup).toHaveBeenCalledWith(planResponse.id, '201', planResponse.version)
|
|
|
|
|
|
expect(assignSmartLoadingItem).not.toHaveBeenCalled()
|
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('shows an exact three-member group block and prevents individual assignment', async () => {
|
|
|
|
|
|
vi.mocked(listSmartLoadingCandidates).mockResolvedValue(['401', '402', '403'].map((inboundId, index) => ({
|
|
|
|
|
|
...candidate, inboundId, orderId: `5${index}`, inboundCode: `IN-${inboundId}`, coLoadGroupId: '9900', groupNo: 'CLG-9900',
|
|
|
|
|
|
memberCount: 3, groupTotalBoxes: 18, locked: false, blockReason: '同柜不可拆组成员候选不齐,缺少 1 票',
|
|
|
|
|
|
})))
|
|
|
|
|
|
const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/container-loading/:containerId/smart-loading', component: SmartLoadingWorkbenchView }] })
|
|
|
|
|
|
await router.push(`/container-loading/${container.id}/smart-loading`); await router.isReady()
|
|
|
|
|
|
const wrapper = mount(SmartLoadingWorkbenchView, { global: { plugins: [ElementPlus, router] } })
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
expect(wrapper.text()).toContain('CLG-9900 · 3 票')
|
|
|
|
|
|
expect(wrapper.text()).toContain('同柜不可拆组成员候选不齐,缺少 1 票')
|
|
|
|
|
|
const button = wrapper.findAll('button').find((item) => item.text().includes('整组分配'))!
|
|
|
|
|
|
expect(button.attributes('disabled')).toBeDefined()
|
|
|
|
|
|
expect(wrapper.text()).not.toContain('本次计划装柜箱数')
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
it('keeps an ordinary ungrouped inbound on the existing partial-count assignment', async () => {
|
|
|
|
|
|
vi.mocked(assignSmartLoadingItem).mockResolvedValue(planResponse)
|
|
|
|
|
|
const router = createRouter({ history: createMemoryHistory(), routes: [{ path: '/container-loading/:containerId/smart-loading', component: SmartLoadingWorkbenchView }] })
|
|
|
|
|
|
await router.push(`/container-loading/${container.id}/smart-loading`); await router.isReady()
|
|
|
|
|
|
const wrapper = mount(SmartLoadingWorkbenchView, { attachTo: document.body, global: { plugins: [ElementPlus, router] } })
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
await wrapper.findAll('button').find((button) => button.text() === '分配')!.trigger('click')
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
expect(document.body.textContent).toContain('本次计划装柜箱数')
|
|
|
|
|
|
;([...document.body.querySelectorAll('button')].find((button) => button.textContent?.trim() === '确认分配') as HTMLButtonElement).click()
|
|
|
|
|
|
await flushPromises()
|
|
|
|
|
|
expect(assignSmartLoadingItem).toHaveBeenCalledWith(planResponse.id, { inboundId: '2', packageCount: 1, expectedVersion: planResponse.version })
|
|
|
|
|
|
expect(assignSmartLoadingGroup).not.toHaveBeenCalled()
|
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-08-10 15:36:53 +08:00
|
|
|
|
})
|