2026-08-26 12:04:50 +08:00
|
|
|
import ElementPlus, { ElMessageBox } from 'element-plus'
|
2026-08-26 11:10:48 +08:00
|
|
|
import { flushPromises, mount, type VueWrapper } from '@vue/test-utils'
|
|
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
|
|
import ContainerDetailView from './ContainerDetailView.vue'
|
|
|
|
|
import { getContainer, getContainerClearance, getContainerOverview, uploadContainerClearance, uploadContainerDocument } from '../api/platformContainerLoading'
|
|
|
|
|
import { uploadLoadingDeclaration } from '@/modules/loading-lists'
|
2026-08-26 12:04:50 +08:00
|
|
|
import { confirmContainerOutboundDispatch, getContainerOutboundDispatch } from '@/modules/outbound-dispatch/api/platformOutboundDispatch'
|
|
|
|
|
import type { ContainerOutboundDispatchDetail } from '@/modules/outbound-dispatch/types'
|
2026-08-18 17:40:40 +08:00
|
|
|
|
2026-08-26 12:04:50 +08:00
|
|
|
const { accessCan, routerPush, carrierMounts } = vi.hoisted(() => ({ accessCan: vi.fn(), routerPush: vi.fn(), carrierMounts: { value: 0 } }))
|
2026-08-26 11:10:48 +08:00
|
|
|
vi.mock('vue-router', () => ({ useRoute: () => ({ params: { containerId: '2092438843630391297' }, query: {} }), useRouter: () => ({ push: routerPush }) }))
|
|
|
|
|
vi.mock('@/core/access/accessPreview', () => ({ useAccessPreviewStore: () => ({ can: accessCan }) }))
|
2026-08-26 12:04:50 +08:00
|
|
|
vi.mock('@/modules/port-schedules', () => ({ CarrierScheduleQueryPanel: { template: '<div data-test="carrier-panel" />', mounted: () => { carrierMounts.value += 1 } } }))
|
2026-08-26 11:10:48 +08:00
|
|
|
vi.mock('@/modules/loading-lists', () => ({ uploadLoadingDeclaration: vi.fn() }))
|
2026-08-26 12:04:50 +08:00
|
|
|
vi.mock('@/modules/outbound-dispatch/api/platformOutboundDispatch', () => ({ getContainerOutboundDispatch: vi.fn(), confirmContainerOutboundDispatch: vi.fn() }))
|
2026-08-26 11:10:48 +08:00
|
|
|
vi.mock('../api/platformContainerLoading', () => ({
|
|
|
|
|
getContainer: vi.fn(), getContainerOverview: vi.fn(), getContainerClearance: vi.fn(),
|
|
|
|
|
uploadContainerClearance: vi.fn(), completeContainerClearance: vi.fn(), uploadContainerDocument: vi.fn(),
|
|
|
|
|
downloadContainerDocument: vi.fn(), downloadContainerPdaPhoto: vi.fn(), markContainerException: vi.fn(), cancelContainerException: vi.fn(),
|
|
|
|
|
}))
|
|
|
|
|
|
|
|
|
|
const detail = { id: '2092438843630391297', planId: '2092438843630391401', planNo: 'LP-260825-0181', bookingNo: 'CB-1', cabinetNo: 'CAB-1', containerNo: 'C11111111', warehouseId: '193000000000200002', warehouseName: '东莞仓', containerType: '45HC', planStatus: 'COMPLETED', version: 8 } as never
|
|
|
|
|
const overview = {
|
|
|
|
|
container: { id: '2092438843630391297', bookingNo: 'CB-1', cabinetNo: 'CAB-1', containerNo: 'C11111111', status: 'COMPLETED', warehouseId: '193000000000200002', warehouseName: '东莞仓', voyageNo: null, vesselName: null, version: 8 },
|
|
|
|
|
loadingPlanId: '2092438843630391401', pda: null,
|
|
|
|
|
documents: [{ id: '2092438843630391501', documentType: 'CUSTOMS_DECLARATION', fileId: '2092438843630391502', fileName: 'old.pdf', fileHash: null, uploadedBy: '1', uploadedByName: '操作员', uploadedAt: '2026-08-26T10:00:00', version: 5, completed: false }],
|
|
|
|
|
exception: { active: false, reason: null, markedBy: null, markedByName: null, markedAt: null }, exceptionHistory: [], timeline: [],
|
|
|
|
|
}
|
2026-08-26 12:04:50 +08:00
|
|
|
const outboundDetail = {
|
|
|
|
|
aggregate: {
|
|
|
|
|
containerBookingId: '2092438843630391297', cabinetNo: 'CAB-1', containerNo: 'C11111111',
|
2026-08-26 12:36:01 +08:00
|
|
|
loadingPlanId: '2092438843630391401', loadingPlanStatus: 'COMPLETED', truckAppointmentStatus: 'ARRIVED', dispatchStatus: 'READY_FOR_DISPATCH', version: 4,
|
2026-08-26 12:04:50 +08:00
|
|
|
inbounds: [{ orderId: '11', orderNo: 'O-1', inboundId: '2092438843630391501', inboundCode: 'IN-1', tenantId: '22', inboundStatus: 'LOADED' }],
|
|
|
|
|
gate: { passed: true, checkedAt: '2026-08-26T12:00:00', inbounds: [{ inboundId: '2092438843630391501', inboundCode: 'IN-1', gate: { passed: true, checkedAt: '2026-08-26T12:00:00', items: [{ code: 'CUSTOMS_CLEARANCE', name: '报关协同完成', passed: true, actual: 'COMPLETED', requirement: 'COMPLETED' }] } }] },
|
|
|
|
|
},
|
|
|
|
|
timeline: [],
|
|
|
|
|
} as ContainerOutboundDispatchDetail
|
2026-08-26 11:10:48 +08:00
|
|
|
|
2026-08-26 12:04:50 +08:00
|
|
|
function mountView(customs = true, outbound = true) {
|
|
|
|
|
accessCan.mockImplementation((permission: string) => permission === 'platform:firstleg:container:edit'
|
|
|
|
|
|| (customs && permission === 'platform:firstleg:customs:manage')
|
|
|
|
|
|| (outbound && ['platform:firstleg:outbound-dispatch:view', 'platform:firstleg:outbound-dispatch:confirm'].includes(permission)))
|
2026-08-26 11:10:48 +08:00
|
|
|
return mount(ContainerDetailView, { global: { plugins: [ElementPlus] } })
|
|
|
|
|
}
|
|
|
|
|
function documentArticle(wrapper: VueWrapper, label: string) { return wrapper.findAll('.document-item').find((item) => item.text().includes(label))! }
|
2026-08-18 17:40:40 +08:00
|
|
|
|
|
|
|
|
describe('ContainerDetailView', () => {
|
2026-08-26 11:10:48 +08:00
|
|
|
beforeEach(() => {
|
|
|
|
|
vi.clearAllMocks()
|
2026-08-26 12:04:50 +08:00
|
|
|
carrierMounts.value = 0
|
2026-08-26 11:10:48 +08:00
|
|
|
vi.mocked(getContainer).mockResolvedValue(detail)
|
|
|
|
|
vi.mocked(getContainerOverview).mockResolvedValue(overview as never)
|
|
|
|
|
vi.mocked(getContainerClearance).mockResolvedValue(null)
|
|
|
|
|
vi.mocked(uploadLoadingDeclaration).mockResolvedValue({} as never)
|
|
|
|
|
vi.mocked(uploadContainerDocument).mockResolvedValue({} as never)
|
|
|
|
|
vi.mocked(uploadContainerClearance).mockResolvedValue({} as never)
|
2026-08-26 12:04:50 +08:00
|
|
|
vi.mocked(getContainerOutboundDispatch).mockResolvedValue(outboundDetail)
|
|
|
|
|
vi.mocked(confirmContainerOutboundDispatch).mockResolvedValue({ ...outboundDetail, aggregate: { ...outboundDetail.aggregate, dispatchStatus: 'WAITING_FOR_LOADING', version: 5 } } as never)
|
2026-08-18 17:40:40 +08:00
|
|
|
})
|
|
|
|
|
|
2026-08-26 11:10:48 +08:00
|
|
|
it('opens domestic export customs upload and sends stable plan, warehouse, version and reason', async () => {
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
|
|
|
|
await documentArticle(wrapper, '国内出口报关附件').find('button').trigger('click'); await flushPromises()
|
|
|
|
|
expect(wrapper.text()).toContain('国内出口报关附件')
|
|
|
|
|
const file = new File(['customs'], 'customs.pdf', { type: 'application/pdf' })
|
|
|
|
|
;(wrapper.vm as unknown as { selectDocumentFile: (file: { raw: File }) => void }).selectDocumentFile({ raw: file })
|
|
|
|
|
await (wrapper.vm as unknown as { saveDocument: () => Promise<void> }).saveDocument()
|
|
|
|
|
expect(uploadLoadingDeclaration).toHaveBeenCalledWith('2092438843630391401', '193000000000200002', file, 5, '上传国内出口报关附件')
|
|
|
|
|
expect(uploadContainerDocument).not.toHaveBeenCalled(); expect(uploadContainerClearance).not.toHaveBeenCalled()
|
|
|
|
|
wrapper.unmount()
|
2026-08-18 17:40:40 +08:00
|
|
|
})
|
2026-08-19 16:45:51 +08:00
|
|
|
|
2026-08-26 11:10:48 +08:00
|
|
|
it('shows a readable error when the container has no loading plan', async () => {
|
|
|
|
|
vi.mocked(getContainerOverview).mockResolvedValueOnce({ ...overview, loadingPlanId: null } as never)
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
|
|
|
|
await documentArticle(wrapper, '国内出口报关附件').find('button').trigger('click'); await flushPromises()
|
|
|
|
|
expect(wrapper.text()).toContain('当前货柜没有装柜清单,无法上传国内出口报关附件')
|
|
|
|
|
expect(uploadLoadingDeclaration).not.toHaveBeenCalled(); wrapper.unmount()
|
2026-08-19 16:45:51 +08:00
|
|
|
})
|
2026-08-20 18:02:52 +08:00
|
|
|
|
2026-08-26 11:10:48 +08:00
|
|
|
it('hides customs and clearance upload without customs manage permission while keeping DO and PU', async () => {
|
|
|
|
|
const wrapper = mountView(false); await flushPromises()
|
|
|
|
|
expect(documentArticle(wrapper, '国内出口报关附件').find('button').exists()).toBe(false)
|
|
|
|
|
expect(documentArticle(wrapper, '目的港清关资料').find('button').exists()).toBe(false)
|
|
|
|
|
expect(documentArticle(wrapper, 'DO 资料').find('button').exists()).toBe(true)
|
|
|
|
|
expect(documentArticle(wrapper, 'PU 资料').find('button').exists()).toBe(true)
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('keeps destination clearance on its independent container clearance API', async () => {
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
|
|
|
|
await documentArticle(wrapper, '目的港清关资料').find('button').trigger('click'); await flushPromises()
|
|
|
|
|
expect(getContainerClearance).toHaveBeenCalledWith('2092438843630391297')
|
|
|
|
|
expect(wrapper.text()).toContain('目的港清关资料'); expect(uploadLoadingDeclaration).not.toHaveBeenCalled()
|
|
|
|
|
wrapper.unmount()
|
2026-08-20 18:02:52 +08:00
|
|
|
})
|
2026-08-26 12:04:50 +08:00
|
|
|
|
|
|
|
|
it('loads and displays the whole-container gate without querying an inbound id', async () => {
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
|
|
|
|
expect(getContainerOutboundDispatch).toHaveBeenCalledOnce()
|
|
|
|
|
expect(getContainerOutboundDispatch).toHaveBeenCalledWith('2092438843630391297')
|
|
|
|
|
expect(wrapper.text()).toContain('国内出仓门禁')
|
2026-08-26 12:36:01 +08:00
|
|
|
expect(wrapper.find('.gate-summary').text()).toContain('总门禁 1')
|
|
|
|
|
expect(wrapper.find('.gate-summary').text()).toContain('已通过 1')
|
|
|
|
|
expect(wrapper.find('.gate-summary').text()).toContain('阻断 0')
|
|
|
|
|
expect(wrapper.find('.gate-list').text()).not.toContain('报关协同完成')
|
|
|
|
|
await wrapper.find('.gate-summary button').trigger('click')
|
|
|
|
|
expect(wrapper.find('.gate-list').text()).toContain('报关协同完成')
|
|
|
|
|
expect(wrapper.find('.gate-list').text()).toContain('覆盖 1 个入库码')
|
|
|
|
|
expect(wrapper.find('.gate-list').text()).toContain('IN-1')
|
2026-08-26 12:04:50 +08:00
|
|
|
expect(wrapper.text()).toContain('确认离仓')
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('confirms the physical container once with version and no inboundId then refreshes the carrier panel', async () => {
|
|
|
|
|
vi.spyOn(ElMessageBox, 'confirm').mockResolvedValueOnce({ action: 'confirm' } as never)
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
|
|
|
|
await wrapper.find('.outbound-panel__actions button').trigger('click'); await flushPromises()
|
|
|
|
|
expect(confirmContainerOutboundDispatch).toHaveBeenCalledOnce()
|
|
|
|
|
expect(confirmContainerOutboundDispatch).toHaveBeenCalledWith('2092438843630391297', { expectedVersion: 4, remark: '货柜详情确认国内出仓' })
|
|
|
|
|
expect(vi.mocked(confirmContainerOutboundDispatch).mock.calls[0]?.[1]).not.toHaveProperty('inboundId')
|
|
|
|
|
expect(getContainerOverview).toHaveBeenCalledTimes(2)
|
|
|
|
|
expect(carrierMounts.value).toBe(2)
|
|
|
|
|
expect(wrapper.text()).toContain('已确认离仓')
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('prevents a repeated confirmation wave while the first prompt is open', async () => {
|
|
|
|
|
vi.spyOn(ElMessageBox, 'confirm').mockReturnValueOnce(new Promise(() => {}) as never)
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
|
|
|
|
const button = wrapper.find('.outbound-panel__actions button')
|
|
|
|
|
await button.trigger('click')
|
|
|
|
|
await button.trigger('click')
|
|
|
|
|
expect(ElMessageBox.confirm).toHaveBeenCalledOnce()
|
|
|
|
|
expect(confirmContainerOutboundDispatch).not.toHaveBeenCalled()
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('hides the outbound gate and never calls its API without view permission', async () => {
|
|
|
|
|
const wrapper = mountView(true, false); await flushPromises()
|
|
|
|
|
expect(wrapper.text()).not.toContain('国内出仓门禁')
|
|
|
|
|
expect(getContainerOutboundDispatch).not.toHaveBeenCalled()
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('shows gate failure reasons and does not expose confirm when any gate is blocked', async () => {
|
|
|
|
|
vi.mocked(getContainerOutboundDispatch).mockResolvedValueOnce({
|
|
|
|
|
...outboundDetail,
|
|
|
|
|
aggregate: {
|
|
|
|
|
...outboundDetail.aggregate,
|
2026-08-26 12:36:01 +08:00
|
|
|
gate: { passed: false, checkedAt: '2026-08-26T12:00:00', inbounds: [{ inboundId: '2092438843630391501', inboundCode: 'IN-1', gate: { passed: false, checkedAt: '2026-08-26T12:00:00', items: [{ code: 'SAILING_SCHEDULE', name: '船期有效且未过期', passed: false, actual: 'EXPIRED', requirement: 'VALID' }] } }] },
|
2026-08-26 12:04:50 +08:00
|
|
|
},
|
|
|
|
|
} as never)
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
2026-08-26 12:36:01 +08:00
|
|
|
expect(wrapper.text()).toContain('船期有效且未过期')
|
|
|
|
|
expect(wrapper.text()).toContain('EXPIRED')
|
|
|
|
|
expect(wrapper.text()).toContain('VALID')
|
2026-08-26 12:04:50 +08:00
|
|
|
expect(wrapper.find('.outbound-panel__actions button').exists()).toBe(false)
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
2026-08-26 12:36:01 +08:00
|
|
|
|
|
|
|
|
it('deduplicates identical gates across inbounds and shows compact coverage counts', async () => {
|
|
|
|
|
const blocked = { code: 'CUSTOMS_CLEARANCE', name: '报关协同完成', passed: false, actual: 'MISSING', requirement: 'COMPLETED' }
|
|
|
|
|
const passed = { code: 'SAILING_SCHEDULE', name: '船期有效且未过期', passed: true, actual: 'VALID', requirement: 'VALID' }
|
|
|
|
|
vi.mocked(getContainerOutboundDispatch).mockResolvedValueOnce({
|
|
|
|
|
...outboundDetail,
|
|
|
|
|
aggregate: {
|
|
|
|
|
...outboundDetail.aggregate,
|
|
|
|
|
gate: {
|
|
|
|
|
passed: false,
|
|
|
|
|
checkedAt: '2026-08-26T12:00:00',
|
|
|
|
|
inbounds: [
|
|
|
|
|
{ inboundId: '101', inboundCode: 'IN-101', gate: { passed: false, checkedAt: '2026-08-26T12:00:00', items: [blocked, passed] } },
|
|
|
|
|
{ inboundId: '102', inboundCode: 'IN-102', gate: { passed: false, checkedAt: '2026-08-26T12:00:00', items: [blocked, passed] } },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
} as never)
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
|
|
|
|
expect(wrapper.find('.gate-summary').text()).toContain('总门禁 2')
|
|
|
|
|
expect(wrapper.find('.gate-summary').text()).toContain('已通过 1')
|
|
|
|
|
expect(wrapper.find('.gate-summary').text()).toContain('阻断 1')
|
|
|
|
|
expect(wrapper.findAll('.gate-row')).toHaveLength(1)
|
|
|
|
|
expect(wrapper.find('.gate-row').text()).toContain('影响 2 个入库码')
|
|
|
|
|
expect(wrapper.find('.gate-row').text()).toContain('IN-101')
|
|
|
|
|
expect(wrapper.find('.gate-row').text()).toContain('IN-102')
|
|
|
|
|
await wrapper.find('.gate-summary button').trigger('click')
|
|
|
|
|
expect(wrapper.findAll('.gate-row')).toHaveLength(2)
|
|
|
|
|
expect(wrapper.findAll('.gate-row')[1]?.text()).toContain('覆盖 2 个入库码')
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('keeps different facts for the same gate code separate and labels the affected inbound', async () => {
|
|
|
|
|
vi.mocked(getContainerOutboundDispatch).mockResolvedValueOnce({
|
|
|
|
|
...outboundDetail,
|
|
|
|
|
aggregate: {
|
|
|
|
|
...outboundDetail.aggregate,
|
|
|
|
|
gate: {
|
|
|
|
|
passed: false,
|
|
|
|
|
checkedAt: '2026-08-26T12:00:00',
|
|
|
|
|
inbounds: [
|
|
|
|
|
{ inboundId: '201', inboundCode: 'IN-MISSING', gate: { passed: false, checkedAt: '2026-08-26T12:00:00', items: [{ code: 'CUSTOMS_CLEARANCE', name: '报关协同完成', passed: false, actual: 'MISSING', requirement: 'COMPLETED' }] } },
|
|
|
|
|
{ inboundId: '202', inboundCode: 'IN-PENDING', gate: { passed: false, checkedAt: '2026-08-26T12:00:00', items: [{ code: 'CUSTOMS_CLEARANCE', name: '报关协同完成', passed: false, actual: 'PENDING', requirement: 'COMPLETED' }] } },
|
|
|
|
|
{ inboundId: '203', inboundCode: 'IN-DONE', gate: { passed: true, checkedAt: '2026-08-26T12:00:00', items: [{ code: 'CUSTOMS_CLEARANCE', name: '报关协同完成', passed: true, actual: 'COMPLETED', requirement: 'COMPLETED' }] } },
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
} as never)
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
|
|
|
|
expect(wrapper.findAll('.gate-row')).toHaveLength(2)
|
|
|
|
|
expect(wrapper.find('.gate-list').text()).toContain('MISSING')
|
|
|
|
|
expect(wrapper.find('.gate-list').text()).toContain('IN-MISSING')
|
|
|
|
|
expect(wrapper.find('.gate-list').text()).toContain('PENDING')
|
|
|
|
|
expect(wrapper.find('.gate-list').text()).toContain('IN-PENDING')
|
|
|
|
|
await wrapper.find('.gate-summary button').trigger('click')
|
|
|
|
|
expect(wrapper.findAll('.gate-row')).toHaveLength(3)
|
|
|
|
|
expect(wrapper.find('.gate-list').text()).toContain('IN-DONE')
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('keeps truck status as reference only and never counts the legacy truck gate as blocking', async () => {
|
|
|
|
|
vi.mocked(getContainerOutboundDispatch).mockResolvedValueOnce({
|
|
|
|
|
...outboundDetail,
|
|
|
|
|
aggregate: {
|
|
|
|
|
...outboundDetail.aggregate,
|
|
|
|
|
truckAppointmentStatus: 'ARRIVED',
|
|
|
|
|
gate: {
|
|
|
|
|
passed: false,
|
|
|
|
|
checkedAt: '2026-08-26T12:00:00',
|
|
|
|
|
inbounds: [{ inboundId: '301', inboundCode: 'IN-301', gate: { passed: false, checkedAt: '2026-08-26T12:00:00', items: [
|
|
|
|
|
{ code: 'TRUCK_DEPARTED', name: '关联拖车已离仓', passed: false, actual: 'ARRIVED', requirement: 'DEPARTED或COMPLETED' },
|
|
|
|
|
{ code: 'CUSTOMS_CLEARANCE', name: '报关协同完成', passed: true, actual: 'COMPLETED', requirement: 'COMPLETED' },
|
|
|
|
|
] } }],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
} as never)
|
|
|
|
|
const wrapper = mountView(); await flushPromises()
|
|
|
|
|
expect(wrapper.find('.gate-summary').text()).toContain('总门禁 1')
|
|
|
|
|
expect(wrapper.find('.gate-summary').text()).toContain('阻断 0')
|
|
|
|
|
expect(wrapper.find('.gate-summary').text()).toContain('拖车状态(参考):已到仓')
|
|
|
|
|
expect(wrapper.text()).not.toContain('关联拖车已离仓')
|
|
|
|
|
expect(wrapper.find('.outbound-panel__actions button').text()).toContain('确认离仓')
|
|
|
|
|
wrapper.unmount()
|
|
|
|
|
})
|
2026-08-18 17:40:40 +08:00
|
|
|
})
|